Merge pull request #615 from matrix-org/rav/SYN-642
Handle rejections of invites from local users locallypull/622/merge
commit
fa6d6bbceb
|
@ -199,8 +199,7 @@ class BaseHandler(object):
|
||||||
# events in the room, because we don't know enough about the graph
|
# events in the room, because we don't know enough about the graph
|
||||||
# fragment we received to treat it like a graph, so the above returned
|
# fragment we received to treat it like a graph, so the above returned
|
||||||
# no relevant events. It may have returned some events (if we have
|
# no relevant events. It may have returned some events (if we have
|
||||||
# joined and left the room), but not useful ones, like the invite. So we
|
# joined and left the room), but not useful ones, like the invite.
|
||||||
# forcibly set our context to the invite we received over federation.
|
|
||||||
if (
|
if (
|
||||||
not self.is_host_in_room(context.current_state) and
|
not self.is_host_in_room(context.current_state) and
|
||||||
builder.type == EventTypes.Member
|
builder.type == EventTypes.Member
|
||||||
|
@ -208,7 +207,27 @@ class BaseHandler(object):
|
||||||
prev_member_event = yield self.store.get_room_member(
|
prev_member_event = yield self.store.get_room_member(
|
||||||
builder.sender, builder.room_id
|
builder.sender, builder.room_id
|
||||||
)
|
)
|
||||||
if prev_member_event:
|
|
||||||
|
# The prev_member_event may already be in context.current_state,
|
||||||
|
# despite us not being present in the room; in particular, if
|
||||||
|
# inviting user, and all other local users, have already left.
|
||||||
|
#
|
||||||
|
# In that case, we have all the information we need, and we don't
|
||||||
|
# want to drop "context" - not least because we may need to handle
|
||||||
|
# the invite locally, which will require us to have the whole
|
||||||
|
# context (not just prev_member_event) to auth it.
|
||||||
|
#
|
||||||
|
context_event_ids = (
|
||||||
|
e.event_id for e in context.current_state.values()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
prev_member_event and
|
||||||
|
prev_member_event.event_id not in context_event_ids
|
||||||
|
):
|
||||||
|
# The prev_member_event is missing from context, so it must
|
||||||
|
# have arrived over federation and is an outlier. We forcibly
|
||||||
|
# set our context to the invite we received over federation
|
||||||
builder.prev_events = (
|
builder.prev_events = (
|
||||||
prev_member_event.event_id,
|
prev_member_event.event_id,
|
||||||
prev_member_event.prev_events
|
prev_member_event.prev_events
|
||||||
|
|
|
@ -500,6 +500,8 @@ class RoomMemberHandler(BaseHandler):
|
||||||
Raises:
|
Raises:
|
||||||
SynapseError if there was a problem changing the membership.
|
SynapseError if there was a problem changing the membership.
|
||||||
"""
|
"""
|
||||||
|
remote_room_hosts = remote_room_hosts or []
|
||||||
|
|
||||||
target_user = UserID.from_string(event.state_key)
|
target_user = UserID.from_string(event.state_key)
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
|
|
||||||
|
@ -534,7 +536,23 @@ class RoomMemberHandler(BaseHandler):
|
||||||
action = "remote_join"
|
action = "remote_join"
|
||||||
elif event.membership == Membership.LEAVE:
|
elif event.membership == Membership.LEAVE:
|
||||||
is_host_in_room = self.is_host_in_room(context.current_state)
|
is_host_in_room = self.is_host_in_room(context.current_state)
|
||||||
|
|
||||||
if not is_host_in_room:
|
if not is_host_in_room:
|
||||||
|
# perhaps we've been invited
|
||||||
|
inviter = self.get_inviter(target_user.to_string(), context.current_state)
|
||||||
|
if not inviter:
|
||||||
|
raise SynapseError(404, "Not a known room")
|
||||||
|
|
||||||
|
if self.hs.is_mine(inviter):
|
||||||
|
# the inviter was on our server, but has now left. Carry on
|
||||||
|
# with the normal rejection codepath.
|
||||||
|
#
|
||||||
|
# This is a bit of a hack, because the room might still be
|
||||||
|
# active on other servers.
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# send the rejection to the inviter's HS.
|
||||||
|
remote_room_hosts = remote_room_hosts + [inviter.domain]
|
||||||
action = "remote_reject"
|
action = "remote_reject"
|
||||||
|
|
||||||
federation_handler = self.hs.get_handlers().federation_handler
|
federation_handler = self.hs.get_handlers().federation_handler
|
||||||
|
@ -554,11 +572,8 @@ class RoomMemberHandler(BaseHandler):
|
||||||
event.content,
|
event.content,
|
||||||
)
|
)
|
||||||
elif action == "remote_reject":
|
elif action == "remote_reject":
|
||||||
inviter = self.get_inviter(target_user.to_string(), context.current_state)
|
|
||||||
if not inviter:
|
|
||||||
raise SynapseError(404, "No known servers")
|
|
||||||
yield federation_handler.do_remotely_reject_invite(
|
yield federation_handler.do_remotely_reject_invite(
|
||||||
[inviter.domain],
|
remote_room_hosts,
|
||||||
room_id,
|
room_id,
|
||||||
event.user_id
|
event.user_id
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue