Skip to content

Commit

Permalink
fix: check if secrets are cached instead of checking sync
Browse files Browse the repository at this point in the history
chore: allow passing a timeout value to oneShotSync
  • Loading branch information
td-famedly committed Oct 30, 2023
1 parent 5900442 commit 200c9a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/encryption/ssss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ class OpenSSSS {
throw Exception('SSSS not unlocked');
}
await ssss.store(type, secret, keyId, privateKey, add: add);

while (!(await ssss.encryption.keyManager.isCached())) {
Logs().v('Wait for secret to come down sync');
await ssss.client.oneShotSync(timeout: Duration(seconds: 3));
}
}

Future<void> validateAndStripOtherKeys(String type, String secret) async {
Expand Down
8 changes: 0 additions & 8 deletions lib/encryption/utils/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,6 @@ class Bootstrap {
);
Logs().v('Store the secret...');
await newSsssKey?.store(megolmKey, base64.encode(privKey));
Logs().v('Wait for secret to come down sync');

if (!await encryption.keyManager.isCached()) {
await client.onSync.stream.firstWhere((syncUpdate) =>
syncUpdate.accountData != null &&
syncUpdate.accountData!
.any((accountData) => accountData.type == megolmKey));
}

Logs().v(
'And finally set all megolm keys as needing to be uploaded again...');
Expand Down
4 changes: 2 additions & 2 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,8 @@ class Client extends MatrixApi {

/// Immediately start a sync and wait for completion.
/// If there is an active sync already, wait for the active sync instead.
Future<void> oneShotSync() {
return _sync();
Future<void> oneShotSync({Duration? timeout}) {
return _sync(timeout: timeout);
}

/// Pass a timeout to set how long the server waits before sending an empty response.
Expand Down

0 comments on commit 200c9a5

Please sign in to comment.