feat: Add waitForFirstSync parameter to init method

Just using the .init() method to wait for the client
to initialize is a more easy way than listen to onLoginStateChanged.
But by default it waits for the first sync.
This should be configurable.
This commit is contained in:
Krille Fear 2021-09-20 11:41:40 +02:00
parent e7de73d3a4
commit e0e09c2f67
1 changed files with 7 additions and 1 deletions

View File

@ -884,6 +884,7 @@ class Client extends MatrixApi {
String newDeviceName,
String newDeviceID,
String newOlmAccount,
bool waitForFirstSync = true,
}) async {
if ((newToken != null ||
newUserID != null ||
@ -1002,7 +1003,12 @@ class Client extends MatrixApi {
Logs().i(
'Successfully connected as ${userID.localpart} with ${homeserver.toString()}',
);
return _sync();
final syncFuture = _sync();
if (waitForFirstSync) {
await syncFuture;
}
return;
} catch (e, s) {
Logs().e('Initialization failed', e, s);
await logout().catchError((_) => null);