summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorreivilibre <oliverw@matrix.org>2021-12-15 10:40:52 +0000
committerGitHub <noreply@github.com>2021-12-15 10:40:52 +0000
commit17886d2603112531d4eda459d312f84d0d677652 (patch)
tree8b8cf5c06077fa59f560687cbbde72510ae7d36f /synapse/storage
parentAdd type hints to `synapse/storage/databases/main/e2e_room_keys.py` (#11549) (diff)
downloadsynapse-17886d2603112531d4eda459d312f84d0d677652.tar.xz
Add experimental support for MSC3202: allowing application services to masquerade as specific devices. (#11538)
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/databases/main/devices.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py
index 3932599988..273adb61fd 100644
--- a/synapse/storage/databases/main/devices.py
+++ b/synapse/storage/databases/main/devices.py
@@ -128,6 +128,26 @@ class DeviceWorkerStore(SQLBaseStore):
             allow_none=True,
         )
 
+    async def get_device_opt(
+        self, user_id: str, device_id: str
+    ) -> Optional[Dict[str, Any]]:
+        """Retrieve a device. Only returns devices that are not marked as
+        hidden.
+
+        Args:
+            user_id: The ID of the user which owns the device
+            device_id: The ID of the device to retrieve
+        Returns:
+            A dict containing the device information, or None if the device does not exist.
+        """
+        return await self.db_pool.simple_select_one(
+            table="devices",
+            keyvalues={"user_id": user_id, "device_id": device_id, "hidden": False},
+            retcols=("user_id", "device_id", "display_name"),
+            desc="get_device",
+            allow_none=True,
+        )
+
     async def get_devices_by_user(self, user_id: str) -> Dict[str, Dict[str, str]]:
         """Retrieve all of a user's registered devices. Only returns devices
         that are not marked as hidden.