0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-09 11:32:01 +01:00

Reuse update_membership from /join

This commit is contained in:
Daniel Wagner-Hall 2016-02-15 16:16:03 +00:00
parent 73e616df2a
commit 150fcde0dc
2 changed files with 14 additions and 19 deletions

View file

@ -403,7 +403,9 @@ class RoomMemberHandler(BaseHandler):
remotedomains.add(member.domain) remotedomains.add(member.domain)
@defer.inlineCallbacks @defer.inlineCallbacks
def update_membership(self, requester, target, room_id, action, txn_id=None): def update_membership(
self, requester, target, room_id, action, txn_id=None, room_hosts=None
):
effective_membership_state = action effective_membership_state = action
if action in ["kick", "unban"]: if action in ["kick", "unban"]:
effective_membership_state = "leave" effective_membership_state = "leave"
@ -412,7 +414,7 @@ class RoomMemberHandler(BaseHandler):
msg_handler = self.hs.get_handlers().message_handler msg_handler = self.hs.get_handlers().message_handler
content = {"membership": unicode(effective_membership_state)} content = {"membership": effective_membership_state}
if requester.is_guest: if requester.is_guest:
content["kind"] = "guest" content["kind"] = "guest"
@ -423,6 +425,9 @@ class RoomMemberHandler(BaseHandler):
"room_id": room_id, "room_id": room_id,
"sender": requester.user.to_string(), "sender": requester.user.to_string(),
"state_key": target.to_string(), "state_key": target.to_string(),
# For backwards compatibility:
"membership": effective_membership_state,
}, },
token_id=requester.access_token_id, token_id=requester.access_token_id,
txn_id=txn_id, txn_id=txn_id,
@ -447,7 +452,8 @@ class RoomMemberHandler(BaseHandler):
event, event,
context, context,
ratelimit=True, ratelimit=True,
is_guest=requester.is_guest is_guest=requester.is_guest,
room_hosts=room_hosts,
) )
if action == "forget": if action == "forget":

View file

@ -242,23 +242,12 @@ class JoinRoomAliasServlet(ClientV1RestServlet):
room_identifier, room_identifier,
)) ))
msg_handler = self.handlers.message_handler yield self.handlers.room_member_handler.update_membership(
content = {"membership": Membership.JOIN} requester=requester,
if requester.is_guest: target=requester.user,
content["kind"] = "guest" room_id=room_id,
yield msg_handler.create_and_send_event( action="join",
{
"type": EventTypes.Member,
"content": content,
"room_id": room_id,
"sender": requester.user.to_string(),
"state_key": requester.user.to_string(),
"membership": Membership.JOIN, # For backwards compatibility
},
token_id=requester.access_token_id,
txn_id=txn_id, txn_id=txn_id,
is_guest=requester.is_guest,
room_hosts=room_hosts, room_hosts=room_hosts,
) )