diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2020-11-12 17:33:19 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2020-11-13 16:23:00 +0000 |
commit | 9bdd420f9b7abd3a5b1270bab1bd121cc9c6db9b (patch) | |
tree | fe68b81568d05382ed35af6dc7f8b6552a6137f6 | |
parent | Add some handy db methods for knocking (diff) | |
download | synapse-9bdd420f9b7abd3a5b1270bab1bd121cc9c6db9b.tar.xz |
Generalise _locally_reject_invite
We'll be using this to rescind knocks locally too, so generalise the method.
-rw-r--r-- | synapse/handlers/room_member.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index 2cce4b136e..ead214c813 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -1135,32 +1135,34 @@ class RoomMemberMasterHandler(RoomMemberHandler): # logger.warning("Failed to reject invite: %s", e) - return await self._locally_reject_invite( + return await self._generate_local_out_of_band_membership( invite_event, txn_id, requester, content ) - async def _locally_reject_invite( + async def _generate_local_out_of_band_membership( self, - invite_event: EventBase, + previous_membership_event: EventBase, txn_id: Optional[str], requester: Requester, content: JsonDict, - ) -> Tuple[str, int]: - """Generate a local invite rejection + ): + """Generate a local leave event for a room - This is called after we fail to reject an invite via a remote server. It - generates an out-of-band membership event locally. + This can be called after we e.g fail to reject an invite via a remote server. + It generates an out-of-band membership event locally. Args: - invite_event: the invite to be rejected + previous_membership_event: the previous membership event for this user txn_id: optional transaction ID supplied by the client - requester: user making the rejection request, according to the access token - content: additional content to include in the rejection event. + requester: user making the request, according to the access token + content: additional content to include in the leave event. Normally an empty dict. - """ - room_id = invite_event.room_id - target_user = invite_event.state_key + Returns: + A tuple containing (event_id, stream_id of the leave event) + """ + room_id = previous_membership_event.room_id + target_user = previous_membership_event.state_key content["membership"] = Membership.LEAVE @@ -1172,12 +1174,12 @@ class RoomMemberMasterHandler(RoomMemberHandler): "state_key": target_user, } - # the auth events for the new event are the same as that of the invite, plus - # the invite itself. + # the auth events for the new event are the same as that of the previous event, plus + # the event itself. # - # the prev_events are just the invite. - prev_event_ids = [invite_event.event_id] - auth_event_ids = invite_event.auth_event_ids() + prev_event_ids + # the prev_events consist solely of the previous membership event. + prev_event_ids = [previous_membership_event.event_id] + auth_event_ids = previous_membership_event.auth_event_ids() + prev_event_ids event, context = await self.event_creation_handler.create_event( requester, |