From e0e09c2f67df7d2e5eab55562dc0adf8fc3718cb Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Mon, 20 Sep 2021 11:41:40 +0200 Subject: [PATCH] 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. --- lib/src/client.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 0fd76337..46b61586 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -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);