From cafb1e3d79b8b7728688e2c0cb3e4f7c22e13fe6 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 20 Aug 2023 07:17:55 +0200 Subject: [PATCH] fix: First story appears to be unencrypted sometimes --- .../client_stories_extension.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/utils/matrix_sdk_extensions/client_stories_extension.dart b/lib/utils/matrix_sdk_extensions/client_stories_extension.dart index 413ef31c..dd11af0f 100644 --- a/lib/utils/matrix_sdk_extensions/client_stories_extension.dart +++ b/lib/utils/matrix_sdk_extensions/client_stories_extension.dart @@ -72,11 +72,22 @@ extension ClientStoriesExtension on Client { invite: invite, ); if (getRoomById(roomId) == null) { - // Wait for room actually appears in sync - await onSync.stream - .firstWhere((sync) => sync.rooms?.join?.containsKey(roomId) ?? false); + // Wait for room actually appears in sync and is encrypted. This is a + // workaround for https://github.com/krille-chan/fluffychat/issues/520 + await onSync.stream.firstWhere( + (sync) => + sync.rooms?.join?[roomId]?.state + ?.any((state) => state.type == EventTypes.Encrypted) ?? + false, + ); } - return getRoomById(roomId)!; + final room = getRoomById(roomId); + if (room == null || !room.encrypted) { + throw Exception( + 'Unable to create and wait for encrypted room to appear in Sync.', + ); + } + return room; } Future getStoriesRoom(BuildContext context) async {