summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-01-27 13:36:39 +0000
committerErik Johnston <erik@matrix.org>2017-01-27 14:31:35 +0000
commit252b503fc8626078141dc6b82eeff63607874347 (patch)
tree72667c5deb13c6f3cbcbc802ecf9c898a8c6d004 /synapse/handlers
parentComment (diff)
downloadsynapse-252b503fc8626078141dc6b82eeff63607874347.tar.xz
Hook device list updates to replication
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/device.py16
-rw-r--r--synapse/handlers/sync.py35
2 files changed, 25 insertions, 26 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index ed077c9a76..6fefb85890 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -221,22 +221,6 @@ class DeviceHandler(BaseHandler):
                 self.federation_sender.send_device_messages(host)
 
     @defer.inlineCallbacks
-    def get_device_list_changes(self, user_id, room_ids, from_key):
-        """For a user and their joined rooms, calculate which device updates
-        we need to return.
-        """
-        room_ids = frozenset(room_ids)
-
-        user_ids_changed = set()
-        changed = yield self.store.get_user_whose_devices_changed(from_key)
-        for other_user_id in changed:
-            other_rooms = yield self.store.get_rooms_for_user(other_user_id)
-            if room_ids.intersection(e.room_id for e in other_rooms):
-                user_ids_changed.add(other_user_id)
-
-        defer.returnValue(user_ids_changed)
-
-    @defer.inlineCallbacks
     def _incoming_device_list_update(self, origin, edu_content):
         user_id = edu_content["user_id"]
         device_id = edu_content["device_id"]
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 06bf626367..9199f20817 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -144,7 +144,6 @@ class SyncHandler(object):
         self.clock = hs.get_clock()
         self.response_cache = ResponseCache(hs)
         self.state = hs.get_state_handler()
-        self.device_handler = hs.get_device_handler()
 
     def wait_for_sync_for_user(self, sync_config, since_token=None, timeout=0,
                                full_state=False):
@@ -546,15 +545,9 @@ class SyncHandler(object):
 
         yield self._generate_sync_entry_for_to_device(sync_result_builder)
 
-        if since_token and since_token.device_list_key:
-            user_id = sync_config.user.to_string()
-            rooms = yield self.store.get_rooms_for_user(user_id)
-            joined_room_ids = set(r.room_id for r in rooms)
-            device_lists = yield self.device_handler.get_device_list_changes(
-                user_id, joined_room_ids, since_token.device_list_key
-            )
-        else:
-            device_lists = []
+        device_lists = yield self._generate_sync_entry_for_device_list(
+            sync_result_builder
+        )
 
         defer.returnValue(SyncResult(
             presence=sync_result_builder.presence,
@@ -568,6 +561,28 @@ class SyncHandler(object):
         ))
 
     @defer.inlineCallbacks
+    def _generate_sync_entry_for_device_list(self, sync_result_builder):
+        user_id = sync_result_builder.sync_config.user.to_string()
+        since_token = sync_result_builder.since_token
+
+        if since_token and since_token.device_list_key:
+            rooms = yield self.store.get_rooms_for_user(user_id)
+            room_ids = set(r.room_id for r in rooms)
+
+            user_ids_changed = set()
+            changed = yield self.store.get_user_whose_devices_changed(
+                since_token.device_list_key
+            )
+            for other_user_id in changed:
+                other_rooms = yield self.store.get_rooms_for_user(other_user_id)
+                if room_ids.intersection(e.room_id for e in other_rooms):
+                    user_ids_changed.add(other_user_id)
+
+            defer.returnValue(user_ids_changed)
+        else:
+            defer.returnValue([])
+
+    @defer.inlineCallbacks
     def _generate_sync_entry_for_to_device(self, sync_result_builder):
         """Generates the portion of the sync response. Populates
         `sync_result_builder` with the result.