diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-07-20 16:34:00 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-07-20 16:42:32 +0100 |
commit | bc8f265f0a8443e918b17a94f4b2fa319e70a21f (patch) | |
tree | 78d0a5d38d1c5edb9a9600a532500248f987c90d /synapse/handlers | |
parent | More doc-comments (diff) | |
download | synapse-bc8f265f0a8443e918b17a94f4b2fa319e70a21f.tar.xz |
GET /devices endpoint
implement a GET /devices endpoint which lists all of the user's devices. It also returns the last IP where we saw that device, so there is some dancing to fish that out of the user_ips table.
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/device.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index 8d7d9874f8..6bbbf59e52 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -69,3 +69,30 @@ class DeviceHandler(BaseHandler): attempts += 1 raise StoreError(500, "Couldn't generate a device ID.") + + @defer.inlineCallbacks + def get_devices_by_user(self, user_id): + """ + Retrieve the given user's devices + + Args: + user_id (str): + Returns: + defer.Deferred: dict[str, dict[str, X]]: map from device_id to + info on the device + """ + + devices = yield self.store.get_devices_by_user(user_id) + + ips = yield self.store.get_last_client_ip_by_device( + devices=((user_id, device_id) for device_id in devices.keys()) + ) + + for device_id in devices.keys(): + ip = ips.get((user_id, device_id), {}) + devices[device_id].update({ + "last_seen_ts": ip.get("last_seen"), + "last_seen_ip": ip.get("ip"), + }) + + defer.returnValue(devices) |