summary refs log tree commit diff
path: root/synapse/storage/__init__.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-29 14:59:52 +0100
committerErik Johnston <erik@matrix.org>2014-09-29 14:59:52 +0100
commit3ccb17ce592d7e75e0bd0237c347d64f63d5eb10 (patch)
treec5931cd53ad04a32430a51afcb8b7a06ea88920d /synapse/storage/__init__.py
parentAdd auth check to test if a user is an admin or not. (diff)
downloadsynapse-3ccb17ce592d7e75e0bd0237c347d64f63d5eb10.tar.xz
SYN-48: Implement WHOIS rest servlet
Diffstat (limited to 'synapse/storage/__init__.py')
-rw-r--r--synapse/storage/__init__.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 169a80dce4..749347d5a8 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -294,18 +294,54 @@ class DataStore(RoomMemberStore, RoomStore,
 
         defer.returnValue(self.min_token)
 
-    def insert_client_ip(self, user, access_token, ip, user_agent):
+    def insert_client_ip(self, user, access_token, device_id, ip, user_agent):
         return self._simple_insert(
             "user_ips",
             {
                 "user": user.to_string(),
                 "access_token": access_token,
+                "device_id": device_id,
                 "ip": ip,
                 "user_agent": user_agent,
-                "last_used": int(self._clock.time()),
+                "last_seen": int(self._clock.time_msec()),
             }
         )
 
+    def get_user_ip_and_agents(self, user):
+        return self._simple_select_list(
+            table="user_ips",
+            keyvalues={"user": user.to_string()},
+            retcols=[
+                "device_id", "access_token", "ip", "user_agent", "last_seen"
+            ],
+        )
+
+        d = {}
+        for r in res:
+            device = d.setdefault(r["device_id"], {})
+            session = device.setdefault(r["access_token"], [])
+            session.append({
+                "ip": r["ip"],
+                "user_agent": r["user_agent"],
+                "last_seen": r["last_seen"],
+            })
+
+        defer.returnValue(
+            [
+                {
+                    "device_id": k,
+                    "sessions": [
+                        {
+                            "access_token": x,
+                            "connections": y,
+                        }
+                        for x, y in v.items()
+                    ]
+                }
+                for k, v in d.items()
+            ]
+        )
+
     def snapshot_room(self, room_id, user_id, state_type=None, state_key=None):
         """Snapshot the room for an update by a user
         Args: