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

Commit 4f76eef

Browse files
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.
1 parent 791d7cd commit 4f76eef

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

changelog.d/8751.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generalise `RoomMemberHandler._locally_reject_invite` to apply to more flows than just invite.

synapse/handlers/room_member.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,32 +1104,34 @@ async def remote_reject_invite(
11041104
#
11051105
logger.warning("Failed to reject invite: %s", e)
11061106

1107-
return await self._locally_reject_invite(
1107+
return await self._generate_local_out_of_band_leave(
11081108
invite_event, txn_id, requester, content
11091109
)
11101110

1111-
async def _locally_reject_invite(
1111+
async def _generate_local_out_of_band_leave(
11121112
self,
1113-
invite_event: EventBase,
1113+
previous_membership_event: EventBase,
11141114
txn_id: Optional[str],
11151115
requester: Requester,
11161116
content: JsonDict,
11171117
) -> Tuple[str, int]:
1118-
"""Generate a local invite rejection
1118+
"""Generate a local leave event for a room
11191119
1120-
This is called after we fail to reject an invite via a remote server. It
1121-
generates an out-of-band membership event locally.
1120+
This can be called after we e.g fail to reject an invite via a remote server.
1121+
It generates an out-of-band membership event locally.
11221122
11231123
Args:
1124-
invite_event: the invite to be rejected
1124+
previous_membership_event: the previous membership event for this user
11251125
txn_id: optional transaction ID supplied by the client
1126-
requester: user making the rejection request, according to the access token
1127-
content: additional content to include in the rejection event.
1126+
requester: user making the request, according to the access token
1127+
content: additional content to include in the leave event.
11281128
Normally an empty dict.
1129-
"""
11301129
1131-
room_id = invite_event.room_id
1132-
target_user = invite_event.state_key
1130+
Returns:
1131+
A tuple containing (event_id, stream_id of the leave event)
1132+
"""
1133+
room_id = previous_membership_event.room_id
1134+
target_user = previous_membership_event.state_key
11331135

11341136
content["membership"] = Membership.LEAVE
11351137

@@ -1141,12 +1143,12 @@ async def _locally_reject_invite(
11411143
"state_key": target_user,
11421144
}
11431145

1144-
# the auth events for the new event are the same as that of the invite, plus
1145-
# the invite itself.
1146+
# the auth events for the new event are the same as that of the previous event, plus
1147+
# the event itself.
11461148
#
1147-
# the prev_events are just the invite.
1148-
prev_event_ids = [invite_event.event_id]
1149-
auth_event_ids = invite_event.auth_event_ids() + prev_event_ids
1149+
# the prev_events consist solely of the previous membership event.
1150+
prev_event_ids = [previous_membership_event.event_id]
1151+
auth_event_ids = previous_membership_event.auth_event_ids() + prev_event_ids
11501152

11511153
event, context = await self.event_creation_handler.create_event(
11521154
requester,

0 commit comments

Comments
 (0)