summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-04-04 11:09:26 +0100
committerErik Johnston <erik@matrix.org>2017-04-04 11:14:16 +0100
commit3376f160124ff2f8915341c90a24ba83495fb8d9 (patch)
tree6f380359a24be370ead9d4dd8f5b38aa07c1484e /synapse
parentMove where we ack federation (diff)
downloadsynapse-3376f160124ff2f8915341c90a24ba83495fb8d9.tar.xz
Shuffle and comment synchrotron presence
Diffstat (limited to '')
-rw-r--r--synapse/app/synchrotron.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/synapse/app/synchrotron.py b/synapse/app/synchrotron.py
index c9c48f324f..7341970a81 100644
--- a/synapse/app/synchrotron.py
+++ b/synapse/app/synchrotron.py
@@ -106,6 +106,7 @@ UPDATE_SYNCING_USERS_MS = 10 * 1000
 
 class SynchrotronPresence(object):
     def __init__(self, hs):
+        self.hs = hs
         self.is_mine_id = hs.is_mine_id
         self.http_client = hs.get_simple_http_client()
         self.store = hs.get_datastore()
@@ -122,7 +123,8 @@ class SynchrotronPresence(object):
         self.process_id = random_string(16)
         logger.info("Presence process_id is %r", self.process_id)
 
-        self.sync_callback = None
+    def send_user_sync(self, user_id, is_syncing, last_sync_ms):
+        self.hs.get_tcp_replication().send_user_sync(user_id, is_syncing, last_sync_ms)
 
     def set_state(self, user, state, ignore_status_msg=False):
         # TODO Hows this supposed to work?
@@ -138,10 +140,10 @@ class SynchrotronPresence(object):
             curr_sync = self.user_to_num_current_syncs.get(user_id, 0)
             self.user_to_num_current_syncs[user_id] = curr_sync + 1
 
-            if self.sync_callback:
-                if self.user_to_num_current_syncs[user_id] == 1:
-                    now = self.clock.time_msec()
-                    self.sync_callback(user_id, True, now)
+            # If we went from no in flight sync to some, notify replication
+            if self.user_to_num_current_syncs[user_id] == 1:
+                now = self.clock.time_msec()
+                self.send_user_sync(user_id, True, now)
 
         def _end():
             # We check that the user_id is in user_to_num_current_syncs because
@@ -150,10 +152,10 @@ class SynchrotronPresence(object):
             if affect_presence and user_id in self.user_to_num_current_syncs:
                 self.user_to_num_current_syncs[user_id] -= 1
 
-                if self.sync_callback:
-                    if self.user_to_num_current_syncs[user_id] == 0:
-                        now = self.clock.time_msec()
-                        self.sync_callback(user_id, False, now)
+                # If we went from one in flight sync to non, notify replication
+                if self.user_to_num_current_syncs[user_id] == 0:
+                    now = self.clock.time_msec()
+                    self.send_user_sync(user_id, False, now)
 
         @contextlib.contextmanager
         def _user_syncing():