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

Update module API "update room membership" method to allow for remote joins #13441

1 change: 1 addition & 0 deletions changelog.d/13441.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add remote join capability to the module API "update_room_membership" method (in a backwards compatible manner).
babolivier marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
JsonMapping,
Requester,
RoomAlias,
RoomID,
StateMap,
UserID,
UserInfo,
Expand Down Expand Up @@ -929,6 +930,7 @@ async def update_room_membership(
room_id: str,
new_membership: str,
content: Optional[JsonDict] = None,
is_remote_join: bool = False,
) -> EventBase:
"""Updates the membership of a user to the given value.

Expand All @@ -946,6 +948,9 @@ async def update_room_membership(
https://spec.matrix.org/unstable/client-server-api/#mroommember for the
list of allowed values.
content: Additional values to include in the resulting event's content.
is_remote_join: Must be True if room_id refers to a remote room and
new_membership is "join" (i.e. a remote join is needed), otherwise must
be False.

Returns:
The newly created membership event.
Expand Down Expand Up @@ -999,11 +1004,16 @@ async def update_room_membership(
if "displayname" not in content:
content["displayname"] = profile["displayname"]

remote_room_hosts = None
if is_remote_join:
remote_room_hosts = [RoomID.from_string(room_id).domain]
babolivier marked this conversation as resolved.
Show resolved Hide resolved

event_id, _ = await self._hs.get_room_member_handler().update_membership(
requester=requester,
target=target_user_id,
room_id=room_id,
action=new_membership,
remote_room_hosts=remote_room_hosts,
content=content,
)

Expand Down