Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use RoomVersion objects #10934

Merged
merged 5 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we likely could have kept the variable names as room_version?

Copy link
Member Author

Choose a reason for hiding this comment

The 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},
Expand All @@ -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)
Expand Down Expand Up @@ -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},
Expand All @@ -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)
Expand Down Expand Up @@ -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.identifier, event_dict, event, context
)

EventValidator().validate_new(event, self.config)
Expand All @@ -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)
Expand Down Expand Up @@ -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.identifier, 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)
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ async def _upgrade_room(
},
},
)
old_room_version = await self.store.get_room_version_id(old_room_id)
old_room_version = await self.store.get_room_version(old_room_id)
await self._event_auth_handler.check_from_context(
old_room_version, tombstone_event, tombstone_context
old_room_version.identifier, tombstone_event, tombstone_context
)

await self.clone_existing_room(
Expand Down