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-26 10:49:55 +0100
committerGitHub <noreply@github.com>2016-07-26 10:49:55 +0100
commitd34e9f93b7f39fce5a98a45af3e95d3fe08b4798 (patch)
treefa88fe4599b38eac5a9f634fe9ee25da3692e333 /synapse/storage/devices.py
parentfederation doesn't work over ipv6 yet thanks to twisted (diff)
parentImplement updating devices (diff)
downloadsynapse-d34e9f93b7f39fce5a98a45af3e95d3fe08b4798.tar.xz
Merge pull request #949 from matrix-org/rav/update_devices
Implement updates and deletes for devices
Diffstat (limited to 'synapse/storage/devices.py')
-rw-r--r--synapse/storage/devices.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py
index 1cc6e07f2b..afd6530cab 100644
--- a/synapse/storage/devices.py
+++ b/synapse/storage/devices.py
@@ -76,6 +76,46 @@ class DeviceStore(SQLBaseStore):
             desc="get_device",
         )
 
+    def delete_device(self, user_id, device_id):
+        """Delete a device.
+
+        Args:
+            user_id (str): The ID of the user which owns the device
+            device_id (str): The ID of the device to delete
+        Returns:
+            defer.Deferred
+        """
+        return self._simple_delete_one(
+            table="devices",
+            keyvalues={"user_id": user_id, "device_id": device_id},
+            desc="delete_device",
+        )
+
+    def update_device(self, user_id, device_id, new_display_name=None):
+        """Update a device.
+
+        Args:
+            user_id (str): The ID of the user which owns the device
+            device_id (str): The ID of the device to update
+            new_display_name (str|None): new displayname for device; None
+               to leave unchanged
+        Raises:
+            StoreError: if the device is not found
+        Returns:
+            defer.Deferred
+        """
+        updates = {}
+        if new_display_name is not None:
+            updates["display_name"] = new_display_name
+        if not updates:
+            return defer.succeed(None)
+        return self._simple_update_one(
+            table="devices",
+            keyvalues={"user_id": user_id, "device_id": device_id},
+            updatevalues=updates,
+            desc="update_device",
+        )
+
     @defer.inlineCallbacks
     def get_devices_by_user(self, user_id):
         """Retrieve all of a user's registered devices.