fix: First story appears to be unencrypted sometimes

This commit is contained in:
krille-chan 2023-08-20 07:17:55 +02:00
parent b5aa68476f
commit cafb1e3d79
No known key found for this signature in database

View file

@ -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<Room?> getStoriesRoom(BuildContext context) async {