mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-22 12:44:30 +03:00
apply suggestions from PR review
This commit is contained in:
parent
e9d587d0d8
commit
0dc4c4e1ce
2 changed files with 21 additions and 16 deletions
|
@ -100,6 +100,8 @@ class E2eRoomKeysHandler(object):
|
|||
rooms
|
||||
session_id(string): session ID to delete keys for, for None to delete keys
|
||||
for all sessions
|
||||
Raises:
|
||||
NotFoundError: if the backup version does not exist
|
||||
Returns:
|
||||
A dict containing the count and hash for the backup version
|
||||
"""
|
||||
|
@ -216,7 +218,7 @@ class E2eRoomKeysHandler(object):
|
|||
if changed:
|
||||
version_hash = version_hash + 1
|
||||
yield self.store.update_e2e_room_keys_version(
|
||||
user_id, version, {"hash": str(version_hash)}
|
||||
user_id, version, None, version_hash
|
||||
)
|
||||
|
||||
count = yield self.store.count_e2e_room_keys(user_id, version)
|
||||
|
@ -366,10 +368,6 @@ class E2eRoomKeysHandler(object):
|
|||
if old_info["algorithm"] != version_info["algorithm"]:
|
||||
raise SynapseError(400, "Algorithm does not match", Codes.INVALID_PARAM)
|
||||
|
||||
# don't allow the user to set the hash
|
||||
if "hash" in version_info:
|
||||
del version_info["hash"]
|
||||
|
||||
yield self.store.update_e2e_room_keys_version(
|
||||
user_id, version, version_info
|
||||
)
|
||||
|
|
|
@ -169,7 +169,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
|||
|
||||
@staticmethod
|
||||
def _get_e2e_room_keys_multi_txn(txn, user_id, version, room_keys):
|
||||
if not len(room_keys):
|
||||
if not room_keys:
|
||||
return {}
|
||||
|
||||
where_clauses = []
|
||||
|
@ -185,6 +185,10 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
|||
% (",".join(["?" for _ in sessions]),)
|
||||
)
|
||||
|
||||
# check if we're actually querying something
|
||||
if not where_clauses:
|
||||
return {}
|
||||
|
||||
sql = """
|
||||
SELECT room_id, session_id, first_message_index, forwarded_count,
|
||||
is_verified, session_data
|
||||
|
@ -282,6 +286,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
|||
version(str)
|
||||
algorithm(str)
|
||||
auth_data(object): opaque dict supplied by the client
|
||||
hash(int): tag of the keys in the backup
|
||||
"""
|
||||
|
||||
def _get_e2e_room_keys_version_info_txn(txn):
|
||||
|
@ -351,21 +356,23 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
|||
"create_e2e_room_keys_version_txn", _create_e2e_room_keys_version_txn
|
||||
)
|
||||
|
||||
def update_e2e_room_keys_version(self, user_id, version, info):
|
||||
def update_e2e_room_keys_version(self, user_id, version, info=None, version_hash=None):
|
||||
"""Update a given backup version
|
||||
|
||||
Args:
|
||||
user_id(str): the user whose backup version we're updating
|
||||
version(str): the version ID of the backup version we're updating
|
||||
info(dict): the new backup version info to store
|
||||
version_hash(str): tag of the keys in the backup
|
||||
"""
|
||||
updatevalues = {}
|
||||
|
||||
if "auth_data" in info:
|
||||
if info and "auth_data" in info:
|
||||
updatevalues["auth_data"] = json.dumps(info["auth_data"])
|
||||
if "hash" in info:
|
||||
updatevalues["hash"] = info["hash"]
|
||||
if version_hash:
|
||||
updatevalues["hash"] = version_hash
|
||||
|
||||
if updatevalues:
|
||||
return self._simple_update(
|
||||
table="e2e_room_keys_versions",
|
||||
keyvalues={"user_id": user_id, "version": version},
|
||||
|
|
Loading…
Reference in a new issue