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

Commit

Permalink
Make a fake requester with just what we need
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Jul 8, 2021
1 parent bb92d87 commit d7eb538
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
from synapse.streams.config import PaginationConfig
from synapse.types import (
JsonDict,
Requester,
RoomAlias,
RoomID,
StreamToken,
ThirdPartyInstanceID,
UserID,
create_requester,
)
from synapse.util import json_decoder
from synapse.util.stringutils import parse_and_validate_server_name, random_string
Expand Down Expand Up @@ -310,13 +310,6 @@ def __init__(self, hs):
self.room_member_handler = hs.get_room_member_handler()
self.auth = hs.get_auth()

def _copy_requester_and_override_user_id(self, requester, new_user_id):
serialized_requester = requester.serialize()
serialized_requester["user_id"] = new_user_id
new_requester = Requester.deserialize(self.store, serialized_requester)

return new_requester

async def _inherit_depth_from_prev_ids(self, prev_event_ids) -> int:
(
most_recent_prev_event_id,
Expand Down Expand Up @@ -447,8 +440,8 @@ async def on_POST(self, request, room_id):
if event_dict["type"] == EventTypes.Member:
membership = event_dict["content"].get("membership", None)
event_id, _ = await self.room_member_handler.update_membership(
self._copy_requester_and_override_user_id(
requester, state_event["sender"]
create_requester(
state_event["sender"], app_service=requester.app_service
),
target=UserID.from_string(event_dict["state_key"]),
room_id=room_id,
Expand All @@ -469,8 +462,8 @@ async def on_POST(self, request, room_id):
event,
_,
) = await self.event_creation_handler.create_and_send_nonmember_event(
self._copy_requester_and_override_user_id(
requester, state_event["sender"]
create_requester(
state_event["sender"], app_service=requester.app_service
),
event_dict,
outlier=True,
Expand Down Expand Up @@ -552,7 +545,7 @@ async def on_POST(self, request, room_id):
}

event, context = await self.event_creation_handler.create_event(
self._copy_requester_and_override_user_id(requester, ev["sender"]),
create_requester(ev["sender"], app_service=requester.app_service),
event_dict,
prev_event_ids=event_dict.get("prev_events"),
auth_event_ids=auth_event_ids,
Expand Down Expand Up @@ -582,7 +575,7 @@ async def on_POST(self, request, room_id):
# where topological_ordering is just depth.
for (event, context) in reversed(events_to_persist):
ev = await self.event_creation_handler.handle_new_client_event(
self._copy_requester_and_override_user_id(requester, event["sender"]),
create_requester(event["sender"], app_service=requester.app_service),
event=event,
context=context,
)
Expand Down

0 comments on commit d7eb538

Please sign in to comment.