summary refs log tree commit diff
path: root/synapse/storage/e2e_room_keys.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2017-12-06 10:02:49 +0100
committerHubert Chathi <hubert@uhoreg.ca>2018-08-12 19:14:31 -0400
commit69e51c7ba48a84b48ab64c8c290a232d14193a18 (patch)
tree59d7a6647c398d63cb70611d11be45de93e2bcca /synapse/storage/e2e_room_keys.py
parentimplement /room_keys/version too (untested) (diff)
downloadsynapse-69e51c7ba48a84b48ab64c8c290a232d14193a18.tar.xz
make /room_keys/version work
Diffstat (limited to 'synapse/storage/e2e_room_keys.py')
-rw-r--r--synapse/storage/e2e_room_keys.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/synapse/storage/e2e_room_keys.py b/synapse/storage/e2e_room_keys.py
index 994878acf6..8efca11a8c 100644
--- a/synapse/storage/e2e_room_keys.py
+++ b/synapse/storage/e2e_room_keys.py
@@ -172,7 +172,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
         )
 
     @defer.inlineCallbacks
-    def get_e2e_room_key_version(self, user_id, version):
+    def get_e2e_room_key_version_info(self, user_id, version):
 
         row = yield self._simple_select_one(
             table="e2e_room_key_versions",
@@ -191,23 +191,35 @@ class EndToEndRoomKeyStore(SQLBaseStore):
 
         defer.returnValue(row)
 
-    def create_e2e_room_key_version(self, user_id, version, info):
+    def create_e2e_room_key_version(self, user_id, info):
+        """Atomically creates a new version of this user's e2e_room_keys store
+        with the given version info.
+        """
 
         def _create_e2e_room_key_version_txn(txn):
 
+            txn.execute(
+                "SELECT MAX(version) FROM e2e_room_key_versions WHERE user_id=?",
+                (user_id,)
+            )
+            current_version = txn.fetchone()[0]
+            if current_version is None:
+                current_version = 0
+
+            new_version = current_version + 1
+
             self._simple_insert_txn(
                 txn,
                 table="e2e_room_key_versions",
                 values={
                     "user_id": user_id,
-                    "version": version,
+                    "version": new_version,
                     "algorithm": info["algorithm"],
                     "auth_data": info["auth_data"],
                 },
-                lock=False,
             )
 
-            return True
+            return new_version
 
         return self.runInteraction(
             "create_e2e_room_key_version_txn", _create_e2e_room_key_version_txn