fix: Don't run syncs while the client is being initialized

Fixes that a sync could be done / processed while the client was still being initialized (loaded from database). This has lead to multiple bugs, such as the verified status of keys getting lost, notifications that come in during app startup displaying oddly, etc.

Additionally, the init lock was released too early; it is now released when the init is actually done.
This commit is contained in:
Sorunome 2021-06-25 12:46:36 +02:00
parent 616d25034f
commit b664640a05
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
1 changed files with 5 additions and 1 deletions

View File

@ -889,7 +889,6 @@ class Client extends MatrixApi {
_initLock = false;
return;
}
_initLock = false;
encryption?.dispose();
try {
@ -934,6 +933,7 @@ class Client extends MatrixApi {
accountData = await database.getAccountData(id);
presences.clear();
}
_initLock = false;
onLoginStateChanged.add(LoginState.logged);
Logs().i(
@ -1032,6 +1032,10 @@ class Client extends MatrixApi {
_retryDelay = Future.delayed(Duration(seconds: syncErrorTimeoutSec));
if (!isLogged() || _disposed || _aborted) return null;
try {
if (_initLock) {
Logs().d('Running sync while init isn\'t done yet, dropping request');
return;
}
var syncError;
await _checkSyncFilter();
final syncRequest = sync(