summary refs log tree commit diff
path: root/synapse/handlers/device.py
diff options
context:
space:
mode:
authorLuke Barnard <lukebarnard1@users.noreply.github.com>2017-03-14 10:02:56 +0000
committerGitHub <noreply@github.com>2017-03-14 10:02:56 +0000
commitf29d85d9e4e0e19ada3b1187439287adc82cfa74 (patch)
tree856c056128030040e3206873ef08a6f947698012 /synapse/handlers/device.py
parentMerge pull request #1990 from matrix-org/rav/log_config_comments (diff)
parentImplement _simple_delete_many_txn, use it to delete devices (diff)
downloadsynapse-f29d85d9e4e0e19ada3b1187439287adc82cfa74.tar.xz
Merge pull request #1993 from matrix-org/luke/delete-devices
Implement delete_devices API
Diffstat (limited to 'synapse/handlers/device.py')
-rw-r--r--synapse/handlers/device.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py
index e859b3165f..efaa0c8d6e 100644
--- a/synapse/handlers/device.py
+++ b/synapse/handlers/device.py
@@ -170,6 +170,40 @@ class DeviceHandler(BaseHandler):
         yield self.notify_device_update(user_id, [device_id])
 
     @defer.inlineCallbacks
+    def delete_devices(self, user_id, device_ids):
+        """ Delete several devices
+
+        Args:
+            user_id (str):
+            device_ids (str): The list of device IDs to delete
+
+        Returns:
+            defer.Deferred:
+        """
+
+        try:
+            yield self.store.delete_devices(user_id, device_ids)
+        except errors.StoreError, e:
+            if e.code == 404:
+                # no match
+                pass
+            else:
+                raise
+
+        # Delete access tokens and e2e keys for each device. Not optimised as it is not
+        # considered as part of a critical path.
+        for device_id in device_ids:
+            yield self.store.user_delete_access_tokens(
+                user_id, device_id=device_id,
+                delete_refresh_tokens=True,
+            )
+            yield self.store.delete_e2e_keys_by_device(
+                user_id=user_id, device_id=device_id
+            )
+
+        yield self.notify_device_update(user_id, device_ids)
+
+    @defer.inlineCallbacks
     def update_device(self, user_id, device_id, content):
         """ Update the given device