0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 17:23:53 +01:00

Correctly handle leaving room in /key/changes

This commit is contained in:
Erik Johnston 2017-09-18 15:38:22 +01:00
parent 4a94eb3ea4
commit d6dadd95ac

View file

@ -292,12 +292,18 @@ class DeviceHandler(BaseHandler):
).stream ).stream
possibly_changed = set(changed) possibly_changed = set(changed)
possibly_left_rooms = set() possibly_left = set()
for room_id in rooms_changed: for room_id in rooms_changed:
current_state_ids = yield self.store.get_current_state_ids(room_id)
# The user may have left the room # The user may have left the room
# TODO: Check if they actually did or if we were just invited. # TODO: Check if they actually did or if we were just invited.
if room_id not in room_ids: if room_id not in room_ids:
possibly_left_rooms.add(room_id) for key, event_id in current_state_ids.iteritems():
etype, state_key = key
if etype != EventTypes.Member:
continue
possibly_left.add(state_key)
continue continue
# Fetch the current state at the time. # Fetch the current state at the time.
@ -310,8 +316,6 @@ class DeviceHandler(BaseHandler):
# ordering: treat it the same as a new room # ordering: treat it the same as a new room
event_ids = [] event_ids = []
current_state_ids = yield self.store.get_current_state_ids(room_id)
# special-case for an empty prev state: include all members # special-case for an empty prev state: include all members
# in the changed list # in the changed list
if not event_ids: if not event_ids:
@ -354,16 +358,11 @@ class DeviceHandler(BaseHandler):
for state_dict in prev_state_ids.itervalues(): for state_dict in prev_state_ids.itervalues():
prev_event_id = state_dict.get(key, None) prev_event_id = state_dict.get(key, None)
if not prev_event_id or prev_event_id != event_id: if not prev_event_id or prev_event_id != event_id:
possibly_changed.add(state_key) if state_key != user_id:
if state_key == user_id: possibly_changed.add(state_key)
for key, event_id in current_state_ids.iteritems():
etype, state_key = key
if etype != EventTypes.Member:
continue
possibly_changed.add(room_id)
break break
if possibly_changed: if possibly_changed or possibly_left:
users_who_share_room = yield self.store.get_users_who_share_room_with_user( users_who_share_room = yield self.store.get_users_who_share_room_with_user(
user_id user_id
) )
@ -371,7 +370,7 @@ class DeviceHandler(BaseHandler):
# Take the intersection of the users whose devices may have changed # Take the intersection of the users whose devices may have changed
# and those that actually still share a room with the user # and those that actually still share a room with the user
possibly_joined = possibly_changed & users_who_share_room possibly_joined = possibly_changed & users_who_share_room
possibly_left = possibly_changed - users_who_share_room possibly_left = (possibly_changed | possibly_left) - users_who_share_room
else: else:
possibly_joined = [] possibly_joined = []
possibly_left = [] possibly_left = []