summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-04-23 18:27:25 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-04-23 18:27:25 +0100
commit191f7f09cee4e148949af9e33c5c8f60184acf90 (patch)
tree66b56676ce58b49142e2420da02b2c6c3acdc794
parentMumble ReST mumble ``fixed-width`` mumble (diff)
downloadsynapse-191f7f09cee4e148949af9e33c5c8f60184acf90.tar.xz
Generate presence event-stream JSON structures directly
-rw-r--r--synapse/handlers/presence.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index bbc7a0f200..6332f50974 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -836,6 +836,8 @@ class PresenceEventSource(object):
 
         presence = self.hs.get_handlers().presence_handler
         cachemap = presence._user_cachemap
+        clock = self.clock
+        latest_serial = None
 
         updates = []
         # TODO(paul): use a DeferredList ? How to limit concurrency.
@@ -845,18 +847,17 @@ class PresenceEventSource(object):
             if cached.serial <= from_key:
                 continue
 
-            if (yield self.is_visible(observer_user, observed_user)):
-                updates.append((observed_user, cached))
+            if not (yield self.is_visible(observer_user, observed_user)):
+                continue
+
+            if latest_serial is None or cached.serial > latest_serial:
+                latest_serial = cached.serial
+            updates.append(cached.make_event(user=observed_user, clock=clock))
 
         # TODO(paul): limit
 
         if updates:
-            clock = self.clock
-
-            latest_serial = max([x[1].serial for x in updates])
-            data = [x[1].make_event(user=x[0], clock=clock) for x in updates]
-
-            defer.returnValue((data, latest_serial))
+            defer.returnValue((updates, latest_serial))
         else:
             defer.returnValue(([], presence._user_cachemap_latest_serial))