This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Use RoomVersion
objects
#10934
Merged
Merged
Use RoomVersion
objects
#10934
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b7a65d
Use `RoomVersion` objects in more places
richvdh 1059c76
`add_display_name_to_third_party_invite`: take a RoomVersion object
richvdh 1eb47bf
`MessageHandler`: use `RoomVersion` objects
richvdh 0ba748a
Remove `EventBuilderFactory.new`
richvdh 1dfaf36
changelog
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor various parts of the codebase to use `RoomVersion` objects instead of room version identifier strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -718,8 +718,8 @@ async def on_make_join_request( | |
state_ids, | ||
) | ||
|
||
builder = self.event_builder_factory.new( | ||
room_version.identifier, | ||
builder = self.event_builder_factory.for_room_version( | ||
room_version, | ||
{ | ||
"type": EventTypes.Member, | ||
"content": event_content, | ||
|
@@ -897,9 +897,9 @@ async def on_make_leave_request( | |
) | ||
raise SynapseError(403, "User not from origin", Codes.FORBIDDEN) | ||
|
||
room_version = await self.store.get_room_version_id(room_id) | ||
builder = self.event_builder_factory.new( | ||
room_version, | ||
room_version_obj = await self.store.get_room_version(room_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we likely could have kept the variable names as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we could; however renaming them made it easier for me to make sure I was updating all the places they were referenced, and I think it does no harm to have renamed them. |
||
builder = self.event_builder_factory.for_room_version( | ||
room_version_obj, | ||
{ | ||
"type": EventTypes.Member, | ||
"content": {"membership": Membership.LEAVE}, | ||
|
@@ -917,7 +917,7 @@ async def on_make_leave_request( | |
# The remote hasn't signed it yet, obviously. We'll do the full checks | ||
# when we get the event back in `on_send_leave_request` | ||
await self._event_auth_handler.check_from_context( | ||
room_version, event, context, do_sig_check=False | ||
room_version_obj.identifier, event, context, do_sig_check=False | ||
) | ||
except AuthError as e: | ||
logger.warning("Failed to create new leave %r because %s", event, e) | ||
|
@@ -949,10 +949,10 @@ async def on_make_knock_request( | |
) | ||
raise SynapseError(403, "User not from origin", Codes.FORBIDDEN) | ||
|
||
room_version = await self.store.get_room_version_id(room_id) | ||
room_version_obj = await self.store.get_room_version(room_id) | ||
|
||
builder = self.event_builder_factory.new( | ||
room_version, | ||
builder = self.event_builder_factory.for_room_version( | ||
room_version_obj, | ||
{ | ||
"type": EventTypes.Member, | ||
"content": {"membership": Membership.KNOCK}, | ||
|
@@ -979,7 +979,7 @@ async def on_make_knock_request( | |
# The remote hasn't signed it yet, obviously. We'll do the full checks | ||
# when we get the event back in `on_send_knock_request` | ||
await self._event_auth_handler.check_from_context( | ||
room_version, event, context, do_sig_check=False | ||
room_version_obj.identifier, event, context, do_sig_check=False | ||
) | ||
except AuthError as e: | ||
logger.warning("Failed to create new knock %r because %s", event, e) | ||
|
@@ -1245,16 +1245,18 @@ async def exchange_third_party_invite( | |
} | ||
|
||
if await self._event_auth_handler.check_host_in_room(room_id, self.hs.hostname): | ||
room_version = await self.store.get_room_version_id(room_id) | ||
builder = self.event_builder_factory.new(room_version, event_dict) | ||
room_version_obj = await self.store.get_room_version(room_id) | ||
builder = self.event_builder_factory.for_room_version( | ||
room_version_obj, event_dict | ||
) | ||
|
||
EventValidator().validate_builder(builder) | ||
event, context = await self.event_creation_handler.create_new_client_event( | ||
builder=builder | ||
) | ||
|
||
event, context = await self.add_display_name_to_third_party_invite( | ||
room_version, event_dict, event, context | ||
room_version_obj, event_dict, event, context | ||
) | ||
|
||
EventValidator().validate_new(event, self.config) | ||
|
@@ -1265,7 +1267,7 @@ async def exchange_third_party_invite( | |
|
||
try: | ||
await self._event_auth_handler.check_from_context( | ||
room_version, event, context | ||
room_version_obj.identifier, event, context | ||
) | ||
except AuthError as e: | ||
logger.warning("Denying new third party invite %r because %s", event, e) | ||
|
@@ -1299,22 +1301,24 @@ async def on_exchange_third_party_invite_request( | |
|
||
""" | ||
assert_params_in_dict(event_dict, ["room_id"]) | ||
room_version = await self.store.get_room_version_id(event_dict["room_id"]) | ||
room_version_obj = await self.store.get_room_version(event_dict["room_id"]) | ||
|
||
# NB: event_dict has a particular specced format we might need to fudge | ||
# if we change event formats too much. | ||
builder = self.event_builder_factory.new(room_version, event_dict) | ||
builder = self.event_builder_factory.for_room_version( | ||
room_version_obj, event_dict | ||
) | ||
|
||
event, context = await self.event_creation_handler.create_new_client_event( | ||
builder=builder | ||
) | ||
event, context = await self.add_display_name_to_third_party_invite( | ||
room_version, event_dict, event, context | ||
room_version_obj, event_dict, event, context | ||
) | ||
|
||
try: | ||
await self._event_auth_handler.check_from_context( | ||
room_version, event, context | ||
room_version_obj.identifier, event, context | ||
) | ||
except AuthError as e: | ||
logger.warning("Denying third party invite %r because %s", event, e) | ||
|
@@ -1331,7 +1335,7 @@ async def on_exchange_third_party_invite_request( | |
|
||
async def add_display_name_to_third_party_invite( | ||
self, | ||
room_version: str, | ||
room_version_obj: RoomVersion, | ||
event_dict: JsonDict, | ||
event: EventBase, | ||
context: EventContext, | ||
|
@@ -1363,7 +1367,9 @@ async def add_display_name_to_third_party_invite( | |
# auth checks. If we need the invite and don't have it then the | ||
# auth check code will explode appropriately. | ||
|
||
builder = self.event_builder_factory.new(room_version, event_dict) | ||
builder = self.event_builder_factory.for_room_version( | ||
room_version_obj, event_dict | ||
) | ||
EventValidator().validate_builder(builder) | ||
event, context = await self.event_creation_handler.create_new_client_event( | ||
builder=builder | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should rename this to
new(...)
now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda like having the verbose name. It makes grepping more effective, for a start.