summary refs log tree commit diff
path: root/synapse/storage/devices.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-07-25 17:51:24 +0100
committerRichard van der Hoff <richard@matrix.org>2016-07-26 07:35:48 +0100
commit012b4c19132d57fdbc1b6b0e304eb60eaf19200f (patch)
tree93570c6bc031416b50061e3bc1f83fb519dca007 /synapse/storage/devices.py
parentImplement deleting devices (diff)
downloadsynapse-012b4c19132d57fdbc1b6b0e304eb60eaf19200f.tar.xz
Implement updating devices
You can update the displayname of devices now.
Diffstat (limited to 'synapse/storage/devices.py')
-rw-r--r--synapse/storage/devices.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py
index 4689980f80..afd6530cab 100644
--- a/synapse/storage/devices.py
+++ b/synapse/storage/devices.py
@@ -81,7 +81,7 @@ class DeviceStore(SQLBaseStore):
 
         Args:
             user_id (str): The ID of the user which owns the device
-            device_id (str): The ID of the device to retrieve
+            device_id (str): The ID of the device to delete
         Returns:
             defer.Deferred
         """
@@ -91,6 +91,31 @@ class DeviceStore(SQLBaseStore):
             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.