From 55bfc92ee03e9403648b34274f17cb670486a1b9 Mon Sep 17 00:00:00 2001 From: Krille Date: Fri, 8 Dec 2023 10:46:16 +0100 Subject: [PATCH] refactor: Make possible to wait for first sync and await first sync before create megolm session --- lib/encryption/key_manager.dart | 1 + lib/src/client.dart | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index c74539cb..f01ac1b8 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -502,6 +502,7 @@ class KeyManager { Future _createOutboundGroupSession( String roomId) async { await clearOrUseOutboundGroupSession(roomId, wipe: true); + await client.firstSyncReceived; final room = client.getRoomById(roomId); if (room == null) { throw Exception( diff --git a/lib/src/client.dart b/lib/src/client.dart index 770a4be2..7a91f892 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1586,9 +1586,9 @@ class Client extends MatrixApi { ); /// Timeout of 0, so that we don't see a spinner for 30 seconds. - final syncFuture = _sync(timeout: Duration.zero); + firstSyncReceived = _sync(timeout: Duration.zero); if (waitForFirstSync) { - await syncFuture; + await firstSyncReceived; } return; } catch (e, s) { @@ -2341,6 +2341,7 @@ class Client extends MatrixApi { Future? userDeviceKeysLoading; Future? roomsLoading; Future? _accountDataLoading; + Future? firstSyncReceived; Future? get accountDataLoading => _accountDataLoading;