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

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Mar 3, 2023
1 parent d96e3eb commit 44e9370
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
8 changes: 3 additions & 5 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,12 @@ def serialize_event(
# they sent.
txn_id = getattr(e.internal_metadata, "txn_id", None)
if txn_id is not None and config.requester is not None:
requester: Requester = config.requester
event_token_id = getattr(e.internal_metadata, "token_id", None)
event_user_id = getattr(e, "user_id", None)
if requester.user.to_string() == event_user_id and (
if config.requester.user.to_string() == e.sender and (
(
event_token_id is not None
and requester.access_token_id is not None
and event_token_id == requester.access_token_id
and config.requester.access_token_id is not None
and event_token_id == config.requester.access_token_id
)
or config.requester.is_guest
):
Expand Down
6 changes: 3 additions & 3 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ async def get_state_events(
)
room_state = room_state_events[membership_event_id]

now = self.clock.time_msec()
serialize_options = SerializeEventConfig(requester=requester)
events = self._event_serializer.serialize_events(
room_state.values(), now, config=serialize_options
room_state.values(),
self.clock.time_msec(),
config=SerializeEventConfig(requester=requester),
)
return events

Expand Down
6 changes: 3 additions & 3 deletions synapse/rest/client/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ async def on_GET(
requester = await self.auth.get_user_by_req(request)
event = await self.event_handler.get_event(requester.user, None, event_id)

time_now = self.clock.time_msec()
if event:
serialize_options = SerializeEventConfig(requester=requester)
result = self._event_serializer.serialize_event(
event, time_now, config=serialize_options
event,
self.clock.time_msec(),
config=SerializeEventConfig(requester=requester),
)
return 200, result
else:
Expand Down
7 changes: 2 additions & 5 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,14 @@ async def on_GET(
[event], requester.user.to_string()
)

serializer_options = SerializeEventConfig(requester=requester)

time_now = self.clock.time_msec()
# per MSC2676, /rooms/{roomId}/event/{eventId}, should return the
# *original* event, rather than the edited version
event_dict = self._event_serializer.serialize_event(
event,
time_now,
self.clock.time_msec(),
bundle_aggregations=aggregations,
apply_edits=False,
config=serializer_options,
config=SerializeEventConfig(requester=requester),
)
return 200, event_dict

Expand Down

0 comments on commit 44e9370

Please sign in to comment.