fix: Remove potential race conditions and database issues with OTK upload
This commit is contained in:
parent
b5ac500136
commit
2c7ae759f8
|
@ -68,7 +68,7 @@ class Encryption {
|
|||
}
|
||||
|
||||
void handleDeviceOneTimeKeysCount(Map<String, int> countJson) {
|
||||
olmManager.handleDeviceOneTimeKeysCount(countJson);
|
||||
Zone.root.run(() => olmManager.handleDeviceOneTimeKeysCount(countJson));
|
||||
}
|
||||
|
||||
void onSync() {
|
||||
|
|
|
@ -130,6 +130,8 @@ class OlmManager {
|
|||
return isValid;
|
||||
}
|
||||
|
||||
bool _uploadKeysLock = false;
|
||||
|
||||
/// Generates new one time keys, signs everything and upload it to the server.
|
||||
Future<bool> uploadKeys(
|
||||
{bool uploadDeviceKeys = false, int oldKeyCount = 0}) async {
|
||||
|
@ -137,6 +139,12 @@ class OlmManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (_uploadKeysLock) {
|
||||
return false;
|
||||
}
|
||||
_uploadKeysLock = true;
|
||||
|
||||
try {
|
||||
// generate one-time keys
|
||||
// we generate 2/3rds of max, so that other keys people may still have can
|
||||
// still be used
|
||||
|
@ -193,6 +201,9 @@ class OlmManager {
|
|||
_olmAccount.mark_keys_as_published();
|
||||
await client.database?.updateClientKeys(pickledOlmAccount, client.id);
|
||||
return response['signed_curve25519'] == oneTimeKeysCount;
|
||||
} finally {
|
||||
_uploadKeysLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void handleDeviceOneTimeKeysCount(Map<String, int> countJson) {
|
||||
|
|
Loading…
Reference in a new issue