summary refs log tree commit diff
path: root/synapse/handlers/sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-02-19 09:37:50 +0000
committerErik Johnston <erik@matrix.org>2016-02-19 09:37:50 +0000
commite5ad2e52679d85aa3b158294161dd87bde3719b8 (patch)
tree9616f09c9652e92b5c8ce63ccd1a5129e87aa796 /synapse/handlers/sync.py
parentMerge pull request #573 from matrix-org/erikj/sync_fix (diff)
parent"You are not..." (diff)
downloadsynapse-e5ad2e52679d85aa3b158294161dd87bde3719b8.tar.xz
Merge pull request #582 from matrix-org/erikj/presence
Rewrite presence for performance.
Diffstat (limited to 'synapse/handlers/sync.py')
-rw-r--r--synapse/handlers/sync.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index b2b9b928c9..efeec72fd8 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -582,6 +582,28 @@ class SyncHandler(BaseHandler):
             if room_sync:
                 joined.append(room_sync)
 
+        # For each newly joined room, we want to send down presence of
+        # existing users.
+        presence_handler = self.hs.get_handlers().presence_handler
+        extra_presence_users = set()
+        for room_id in newly_joined_rooms:
+            users = yield self.store.get_users_in_room(event.room_id)
+            extra_presence_users.update(users)
+
+        # For each new member, send down presence.
+        for joined_sync in joined:
+            it = itertools.chain(joined_sync.timeline.events, joined_sync.state.values())
+            for event in it:
+                if event.type == EventTypes.Member:
+                    if event.membership == Membership.JOIN:
+                        extra_presence_users.add(event.state_key)
+
+        states = yield presence_handler.get_states(
+            [u for u in extra_presence_users if u != user_id],
+            as_event=True,
+        )
+        presence.extend(states)
+
         account_data_for_user = sync_config.filter_collection.filter_account_data(
             self.account_data_for_user(account_data)
         )