summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-11-18 15:25:55 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-11-18 15:25:55 +0000
commit759db7d7d51029e23540cffee09b03da2c33a744 (patch)
tree9d6afbc306401e9e15ca49c724a8537c93c13304 /synapse/handlers
parentDon't expect all _user_cachemap entries to definitely contain a "last_active"... (diff)
downloadsynapse-759db7d7d51029e23540cffee09b03da2c33a744.tar.xz
Added ability to .get_state() from the PresenceHandler by returning a complete m.presence event
Diffstat (limited to '')
-rw-r--r--synapse/handlers/presence.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 36d864e3f1..325ae45257 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -165,7 +165,7 @@ class PresenceHandler(BaseHandler):
         defer.returnValue(False)
 
     @defer.inlineCallbacks
-    def get_state(self, target_user, auth_user):
+    def get_state(self, target_user, auth_user, as_event=False):
         if target_user.is_mine:
             visible = yield self.is_presence_visible(
                 observer_user=auth_user,
@@ -191,7 +191,20 @@ class PresenceHandler(BaseHandler):
             state["last_active_ago"] = int(
                 self.clock.time_msec() - state.pop("last_active")
             )
-        defer.returnValue(state)
+
+        if as_event:
+            content = state
+
+            content["user_id"] = target_user.to_string()
+
+            if "last_active" in content:
+                content["last_active_ago"] = int(
+                    self._clock.time_msec() - content.pop("last_active")
+                )
+
+            defer.returnValue({"type": "m.presence", "content": content})
+        else:
+            defer.returnValue(state)
 
     @defer.inlineCallbacks
     @log_function