summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-09-18 15:38:22 +0100
committerErik Johnston <erik@matrix.org>2017-09-18 15:38:22 +0100
commitd6dadd95acdc5e4899b2b781bb0b0c42724bd10d (patch)
tree88f244c5649245a83c572f970b858a31b4e54732
parentFix typo (diff)
downloadsynapse-d6dadd95acdc5e4899b2b781bb0b0c42724bd10d.tar.xz
Correctly handle leaving room in /key/changes
Diffstat (limited to '')
-rw-r--r--synapse/handlers/device.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index 0d6750f0e4..dac4b3f4e0 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -292,12 +292,18 @@ class DeviceHandler(BaseHandler):
         ).stream
 
         possibly_changed = set(changed)
-        possibly_left_rooms = set()
+        possibly_left = set()
         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
             # TODO: Check if they actually did or if we were just invited.
             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
 
             # Fetch the current state at the time.
@@ -310,8 +316,6 @@ class DeviceHandler(BaseHandler):
                 # ordering: treat it the same as a new room
                 event_ids = []
 
-            current_state_ids = yield self.store.get_current_state_ids(room_id)
-
             # special-case for an empty prev state: include all members
             # in the changed list
             if not event_ids:
@@ -354,16 +358,11 @@ class DeviceHandler(BaseHandler):
                 for state_dict in prev_state_ids.itervalues():
                     prev_event_id = state_dict.get(key, None)
                     if not prev_event_id or prev_event_id != event_id:
-                        possibly_changed.add(state_key)
-                        if state_key == user_id:
-                            for key, event_id in current_state_ids.iteritems():
-                                etype, state_key = key
-                                if etype != EventTypes.Member:
-                                    continue
-                                possibly_changed.add(room_id)
+                        if state_key != user_id:
+                            possibly_changed.add(state_key)
                         break
 
-        if possibly_changed:
+        if possibly_changed or possibly_left:
             users_who_share_room = yield self.store.get_users_who_share_room_with_user(
                 user_id
             )
@@ -371,7 +370,7 @@ class DeviceHandler(BaseHandler):
             # Take the intersection of the users whose devices may have changed
             # and those that actually still share a room with the user
             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:
             possibly_joined = []
             possibly_left = []