summary refs log tree commit diff
path: root/synapse/handlers/presence.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-10-12 14:47:53 +0100
committerMark Haines <mjark@negativecurvature.net>2015-10-12 14:47:53 +0100
commit885301486c6a29ac999d7c6b39ad3e5faf2a568c (patch)
tree0d4f7725eb0f5c9db473309faaa9aa6ae4396b60 /synapse/handlers/presence.py
parentadd steve to authors (diff)
parentFix some races in the synapse presence handler caused by not yielding on defe... (diff)
downloadsynapse-885301486c6a29ac999d7c6b39ad3e5faf2a568c.tar.xz
Merge pull request #297 from matrix-org/markjh/presence_races
Fix some races in the synapse presence handler caused by not yielding…
Diffstat (limited to 'synapse/handlers/presence.py')
-rw-r--r--synapse/handlers/presence.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index e91e81831e..ce60642127 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -378,7 +378,7 @@ class PresenceHandler(BaseHandler):
 
         # TODO(paul): perform a presence push as part of start/stop poll so
         #   we don't have to do this all the time
-        self.changed_presencelike_data(target_user, state)
+        yield self.changed_presencelike_data(target_user, state)
 
     def bump_presence_active_time(self, user, now=None):
         if now is None:
@@ -422,12 +422,12 @@ class PresenceHandler(BaseHandler):
     @log_function
     def started_user_eventstream(self, user):
         # TODO(paul): Use "last online" state
-        self.set_state(user, user, {"presence": PresenceState.ONLINE})
+        return self.set_state(user, user, {"presence": PresenceState.ONLINE})
 
     @log_function
     def stopped_user_eventstream(self, user):
         # TODO(paul): Save current state as "last online" state
-        self.set_state(user, user, {"presence": PresenceState.OFFLINE})
+        return self.set_state(user, user, {"presence": PresenceState.OFFLINE})
 
     @defer.inlineCallbacks
     def user_joined_room(self, user, room_id):
@@ -1263,6 +1263,11 @@ class UserPresenceCache(object):
         self.state = {"presence": PresenceState.OFFLINE}
         self.serial = None
 
+    def __repr__(self):
+        return "UserPresenceCache(state=%r, serial=%r)" % (
+            self.state, self.serial
+        )
+
     def update(self, state, serial):
         assert("mtime_age" not in state)