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

Add a ModuleApi method to update a user's membership in a room #11147

Merged
merged 16 commits into from
Oct 28, 2021
Merged
Prev Previous commit
Next Next commit
Lint
  • Loading branch information
babolivier committed Oct 22, 2021
commit 025b11ff77905fb69a07743205b744239e64396a
13 changes: 9 additions & 4 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,21 +601,26 @@ async def update_room_membership(
"Tried to send an event as a user that isn't local to this homeserver",
)

requester = create_requester(sender)
target_user_id = UserID.from_string(target)

if content is None:
content = {}

# Set the profile if not already done by the module.
if "avatar_url" not in content:
content["avatar_url"] = self._hs.get_profile_handler().get_avatar_url(target)
content["avatar_url"] = self._hs.get_profile_handler().get_avatar_url(
requester.user,
)

if "displayname" not in content:
content["displayname"] = self._hs.get_profile_handler().get_displayname(
target,
target_user_id,
)

event_id, _ = await self._hs.get_room_member_handler().update_membership(
requester=create_requester(sender),
target=UserID.from_string(target),
requester=requester,
target=target_user_id,
room_id=room_id,
action=new_membership,
content=content,
Expand Down