mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-29 06:46:13 -05:00
Generalise _locally_reject_invite (#8751)
`_locally_reject_invite` generates an out-of-band membership event which can be passed to clients, but not other homeservers. This is used when we fail to reject an invite over federation. If this happens, we instead just generate a leave event locally and send it down /sync, allowing clients to reject invites even if we can't reach the remote homeserver. A similar flow needs to be put in place for rescinding knocks. If we're unable to contact any remote server from the room we've tried to knock on, we'd still like to generate and store the leave event locally. Hence the need to reuse, and thus generalise, this method. Separated from #6739.
This commit is contained in:
parent
791d7cd6f0
commit
4f76eef0e8
1
changelog.d/8751.misc
Normal file
1
changelog.d/8751.misc
Normal file
@ -0,0 +1 @@
|
||||
Generalise `RoomMemberHandler._locally_reject_invite` to apply to more flows than just invite.
|
@ -1104,32 +1104,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_leave(
|
||||
invite_event, txn_id, requester, content
|
||||
)
|
||||
|
||||
async def _locally_reject_invite(
|
||||
async def _generate_local_out_of_band_leave(
|
||||
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
|
||||
|
||||
@ -1141,12 +1143,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,
|
||||
|
Loading…
Reference in New Issue
Block a user