mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 14:53:50 +01:00
Kill the "_homeserver_" injected messages for room membership changes
This commit is contained in:
parent
ba88c9105c
commit
9c0e570496
2 changed files with 6 additions and 58 deletions
|
@ -383,7 +383,6 @@ class RoomCreationHandler(BaseHandler):
|
||||||
|
|
||||||
yield self.hs.get_handlers().room_member_handler.change_membership(
|
yield self.hs.get_handlers().room_member_handler.change_membership(
|
||||||
join_event,
|
join_event,
|
||||||
broadcast_msg=True,
|
|
||||||
do_auth=False
|
do_auth=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -495,19 +494,15 @@ class RoomMemberHandler(BaseHandler):
|
||||||
defer.returnValue(member)
|
defer.returnValue(member)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def change_membership(self, event=None, broadcast_msg=False, do_auth=True):
|
def change_membership(self, event=None, do_auth=True):
|
||||||
""" Change the membership status of a user in a room.
|
""" Change the membership status of a user in a room.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
event (SynapseEvent): The membership event
|
event (SynapseEvent): The membership event
|
||||||
broadcast_msg (bool): True to inject a membership message into this
|
|
||||||
room on success.
|
|
||||||
Raises:
|
Raises:
|
||||||
SynapseError if there was a problem changing the membership.
|
SynapseError if there was a problem changing the membership.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
broadcast_msg = False
|
|
||||||
|
|
||||||
prev_state = yield self.store.get_room_member(
|
prev_state = yield self.store.get_room_member(
|
||||||
event.target_user_id, event.room_id
|
event.target_user_id, event.room_id
|
||||||
)
|
)
|
||||||
|
@ -528,9 +523,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
# if this HS is not currently in the room, i.e. we have to do the
|
# if this HS is not currently in the room, i.e. we have to do the
|
||||||
# invite/join dance.
|
# invite/join dance.
|
||||||
if event.membership == Membership.JOIN:
|
if event.membership == Membership.JOIN:
|
||||||
yield self._do_join(
|
yield self._do_join(event, do_auth=do_auth)
|
||||||
event, do_auth=do_auth, broadcast_msg=broadcast_msg
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# This is not a JOIN, so we can handle it normally.
|
# This is not a JOIN, so we can handle it normally.
|
||||||
if do_auth:
|
if do_auth:
|
||||||
|
@ -548,7 +541,6 @@ class RoomMemberHandler(BaseHandler):
|
||||||
yield self._do_local_membership_update(
|
yield self._do_local_membership_update(
|
||||||
event,
|
event,
|
||||||
membership=event.content["membership"],
|
membership=event.content["membership"],
|
||||||
broadcast_msg=broadcast_msg,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue({"room_id": room_id})
|
defer.returnValue({"room_id": room_id})
|
||||||
|
@ -583,8 +575,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
defer.returnValue({"room_id": room_id})
|
defer.returnValue({"room_id": room_id})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _do_join(self, event, room_host=None, do_auth=True,
|
def _do_join(self, event, room_host=None, do_auth=True):
|
||||||
broadcast_msg=True):
|
|
||||||
joinee = self.hs.parse_userid(event.target_user_id)
|
joinee = self.hs.parse_userid(event.target_user_id)
|
||||||
# room_id = RoomID.from_string(event.room_id, self.hs)
|
# room_id = RoomID.from_string(event.room_id, self.hs)
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
|
@ -639,7 +630,6 @@ class RoomMemberHandler(BaseHandler):
|
||||||
yield self._do_local_membership_update(
|
yield self._do_local_membership_update(
|
||||||
event,
|
event,
|
||||||
membership=event.content["membership"],
|
membership=event.content["membership"],
|
||||||
broadcast_msg=broadcast_msg,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
user = self.hs.parse_userid(event.user_id)
|
user = self.hs.parse_userid(event.user_id)
|
||||||
|
@ -710,7 +700,7 @@ class RoomMemberHandler(BaseHandler):
|
||||||
defer.returnValue([r.room_id for r in rooms])
|
defer.returnValue([r.room_id for r in rooms])
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _do_local_membership_update(self, event, membership, broadcast_msg):
|
def _do_local_membership_update(self, event, membership):
|
||||||
# store membership
|
# store membership
|
||||||
store_id = yield self.store.persist_event(event)
|
store_id = yield self.store.persist_event(event)
|
||||||
|
|
||||||
|
@ -739,48 +729,6 @@ class RoomMemberHandler(BaseHandler):
|
||||||
yield self.hs.get_federation().handle_new_event(event)
|
yield self.hs.get_federation().handle_new_event(event)
|
||||||
self.notifier.on_new_room_event(event, store_id)
|
self.notifier.on_new_room_event(event, store_id)
|
||||||
|
|
||||||
if broadcast_msg:
|
|
||||||
yield self._inject_membership_msg(
|
|
||||||
source=event.user_id,
|
|
||||||
target=event.target_user_id,
|
|
||||||
room_id=event.room_id,
|
|
||||||
membership=event.content["membership"]
|
|
||||||
)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def _inject_membership_msg(self, room_id=None, source=None, target=None,
|
|
||||||
membership=None):
|
|
||||||
# TODO this should be a different type of message, not m.text
|
|
||||||
if membership == Membership.INVITE:
|
|
||||||
body = "%s invited %s to the room." % (source, target)
|
|
||||||
elif membership == Membership.JOIN:
|
|
||||||
body = "%s joined the room." % (target)
|
|
||||||
elif membership == Membership.LEAVE:
|
|
||||||
body = "%s left the room." % (target)
|
|
||||||
else:
|
|
||||||
raise RoomError(500, "Unknown membership value %s" % membership)
|
|
||||||
|
|
||||||
membership_json = {
|
|
||||||
"msgtype": u"m.text",
|
|
||||||
"body": body,
|
|
||||||
"membership_source": source,
|
|
||||||
"membership_target": target,
|
|
||||||
"membership": membership,
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_id = "m%s" % int(self.clock.time_msec())
|
|
||||||
|
|
||||||
event = self.event_factory.create_event(
|
|
||||||
etype=MessageEvent.TYPE,
|
|
||||||
room_id=room_id,
|
|
||||||
user_id="_homeserver_",
|
|
||||||
msg_id=msg_id,
|
|
||||||
content=membership_json
|
|
||||||
)
|
|
||||||
|
|
||||||
handler = self.hs.get_handlers().message_handler
|
|
||||||
yield handler.send_message(event, suppress_auth=True)
|
|
||||||
|
|
||||||
|
|
||||||
class RoomListHandler(BaseHandler):
|
class RoomListHandler(BaseHandler):
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ class RoomMemberRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
|
|
||||||
handler = self.handlers.room_member_handler
|
handler = self.handlers.room_member_handler
|
||||||
yield handler.change_membership(event, broadcast_msg=True)
|
yield handler.change_membership(event)
|
||||||
defer.returnValue((200, ""))
|
defer.returnValue((200, ""))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -220,7 +220,7 @@ class RoomMemberRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
|
|
||||||
handler = self.handlers.room_member_handler
|
handler = self.handlers.room_member_handler
|
||||||
yield handler.change_membership(event, broadcast_msg=True)
|
yield handler.change_membership(event)
|
||||||
defer.returnValue((200, ""))
|
defer.returnValue((200, ""))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue