diff options
author | David Baker <dbkr@users.noreply.github.com> | 2016-07-21 11:54:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-21 11:54:47 +0100 |
commit | 44adde498e07681e7ca4d672e3fa471865e92046 (patch) | |
tree | a7a3bf8ad3a6b4cd02d3dde34196626095b66191 /synapse/handlers | |
parent | Merge pull request #938 from matrix-org/rav/add_device_id_to_client_ips (diff) | |
parent | Fix PEP8 errors (diff) | |
download | synapse-44adde498e07681e7ca4d672e3fa471865e92046.tar.xz |
Merge pull request #939 from matrix-org/rav/get_devices_api
GET /devices endpoint
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) |