summary refs log tree commit diff
path: root/synapse/storage/devices.py
diff options
context:
space:
mode:
authorDavid Baker <dbkr@users.noreply.github.com>2016-07-21 11:54:47 +0100
committerGitHub <noreply@github.com>2016-07-21 11:54:47 +0100
commit44adde498e07681e7ca4d672e3fa471865e92046 (patch)
treea7a3bf8ad3a6b4cd02d3dde34196626095b66191 /synapse/storage/devices.py
parentMerge pull request #938 from matrix-org/rav/add_device_id_to_client_ips (diff)
parentFix PEP8 errors (diff)
downloadsynapse-44adde498e07681e7ca4d672e3fa471865e92046.tar.xz
Merge pull request #939 from matrix-org/rav/get_devices_api
GET /devices endpoint
Diffstat (limited to 'synapse/storage/devices.py')
-rw-r--r--synapse/storage/devices.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py
index 9065e96d28..1cc6e07f2b 100644
--- a/synapse/storage/devices.py
+++ b/synapse/storage/devices.py
@@ -65,7 +65,7 @@ class DeviceStore(SQLBaseStore):
             user_id (str): The ID of the user which owns the device
             device_id (str): The ID of the device to retrieve
         Returns:
-            defer.Deferred for a namedtuple containing the device information
+            defer.Deferred for a dict containing the device information
         Raises:
             StoreError: if the device is not found
         """
@@ -75,3 +75,23 @@ class DeviceStore(SQLBaseStore):
             retcols=("user_id", "device_id", "display_name"),
             desc="get_device",
         )
+
+    @defer.inlineCallbacks
+    def get_devices_by_user(self, user_id):
+        """Retrieve all of a user's registered devices.
+
+        Args:
+            user_id (str):
+        Returns:
+            defer.Deferred: resolves to a dict from device_id to a dict
+            containing "device_id", "user_id" and "display_name" for each
+            device.
+        """
+        devices = yield self._simple_select_list(
+            table="devices",
+            keyvalues={"user_id": user_id},
+            retcols=("user_id", "device_id", "display_name"),
+            desc="get_devices_by_user"
+        )
+
+        defer.returnValue({d["device_id"]: d for d in devices})