summary refs log tree commit diff
path: root/synapse/handlers/message.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-11-18 15:28:58 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-11-18 15:28:58 +0000
commit33d328d967341d8819632bc3c5406b8c54f54504 (patch)
treec170a1bd70dfb9250b0b493387b4ae36433c5857 /synapse/handlers/message.py
parentAdded ability to .get_state() from the PresenceHandler by returning a complet... (diff)
downloadsynapse-33d328d967341d8819632bc3c5406b8c54f54504.tar.xz
Include room members' presence in room initialSync
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r--synapse/handlers/message.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 778cdb2317..21f9df30ec 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -299,6 +299,10 @@ class MessageHandler(BaseHandler):
                       feedback=False):
         yield self.auth.check_joined_room(room_id, user_id)
 
+        # TODO(paul): I wish I was called with user objects not user_id
+        #   strings...
+        auth_user = self.hs.parse_userid(user_id)
+
         # TODO: These concurrently
         state_tuples = yield self.store.get_current_state(room_id)
         state = [self.hs.serialize_event(x) for x in state_tuples]
@@ -323,6 +327,23 @@ class MessageHandler(BaseHandler):
         start_token = now_token.copy_and_replace("room_key", token[0])
         end_token = now_token.copy_and_replace("room_key", token[1])
 
+        room_members = yield self.store.get_room_members(room_id)
+
+        presence_handler = self.hs.get_handlers().presence_handler
+        presence = []
+        for m in room_members:
+            try:
+                member_presence = yield presence_handler.get_state(
+                    target_user=self.hs.parse_userid(m.user_id),
+                    auth_user=auth_user,
+                    as_event=True,
+                )
+                presence.append(member_presence)
+            except Exception as e:
+                logger.exception("Failed to get member presence of %r",
+                    m.user_id
+                )
+
         defer.returnValue({
             "membership": member_event.membership,
             "room_id": room_id,
@@ -332,5 +353,5 @@ class MessageHandler(BaseHandler):
                 "end": end_token.to_string(),
             },
             "state": state,
-            #"presence": presence
+            "presence": presence
         })