diff --git a/packages/neon_framework/packages/talk_app/lib/src/blocs/message_bloc.dart b/packages/neon_framework/packages/talk_app/lib/src/blocs/message_bloc.dart index 3506393440e..f0f2a6a4358 100644 --- a/packages/neon_framework/packages/talk_app/lib/src/blocs/message_bloc.dart +++ b/packages/neon_framework/packages/talk_app/lib/src/blocs/message_bloc.dart @@ -35,18 +35,7 @@ class _TalkMessageBloc extends Bloc implements TalkMessageBloc { return; } - final matches = - referenceRegex.allMatches(chatMessage.message).map((match) => match.group(0)!.trim()).toBuiltList(); - - references.add( - references.value.rebuild((b) { - for (final match in matches) { - b[match] ??= Result.loading(); - } - - b.removeWhere((key, value) => !matches.contains(key)); - }), - ); + matches = referenceRegex.allMatches(chatMessage.message).map((match) => match.group(0)!.trim()).toBuiltList(); if (matches.isNotEmpty) { referencesBloc.loadReferences(matches); @@ -55,12 +44,9 @@ class _TalkMessageBloc extends Bloc implements TalkMessageBloc { referencesSubscription = referencesBloc.references.listen((result) { references.add( - references.value.rebuild((b) { - for (final url in references.value.keys) { - b[url] = result[url] ?? Result.loading(); - } - - b.removeWhere((key, value) => !result.keys.contains(key)); + BuiltMap({ + for (final entry in result.entries) + if (matches.contains(entry.key)) entry.key: entry.value, }), ); }); @@ -70,6 +56,7 @@ class _TalkMessageBloc extends Bloc implements TalkMessageBloc { final spreed.$ChatMessageInterface chatMessage; final ReferencesBloc referencesBloc; final bool isParent; + BuiltList matches = BuiltList(); StreamSubscription>? referenceRegexSubscription; StreamSubscription>>? referencesSubscription; diff --git a/packages/neon_framework/packages/talk_app/lib/src/widgets/message.dart b/packages/neon_framework/packages/talk_app/lib/src/widgets/message.dart index 6b2d88c7c07..a8db63d66d1 100644 --- a/packages/neon_framework/packages/talk_app/lib/src/widgets/message.dart +++ b/packages/neon_framework/packages/talk_app/lib/src/widgets/message.dart @@ -430,11 +430,10 @@ class _TalkCommentMessageState extends State { if (parent != null) parent, text, for (final entry in references.entries.take(3)) - if (entry.value.data?.openGraphObject.name != entry.key) - TalkReferencePreview( - url: entry.key, - openGraphObject: entry.value.data?.openGraphObject, - ), + TalkReferencePreview( + url: entry.key, + openGraphObject: entry.value.data?.openGraphObject, + ), if (!widget.isParent && widget.chatMessage.reactions.isNotEmpty) TalkReactions( chatMessage: widget.chatMessage, diff --git a/packages/neon_framework/packages/talk_app/test/goldens/message_comment_message_with_references.png b/packages/neon_framework/packages/talk_app/test/goldens/message_comment_message_with_references.png index b526ddaf5ea..383f6d43ea9 100644 Binary files a/packages/neon_framework/packages/talk_app/test/goldens/message_comment_message_with_references.png and b/packages/neon_framework/packages/talk_app/test/goldens/message_comment_message_with_references.png differ diff --git a/packages/neon_framework/packages/talk_app/test/message_bloc_test.dart b/packages/neon_framework/packages/talk_app/test/message_bloc_test.dart index 359ae0ddc31..cbd16b1de65 100644 --- a/packages/neon_framework/packages/talk_app/test/message_bloc_test.dart +++ b/packages/neon_framework/packages/talk_app/test/message_bloc_test.dart @@ -51,21 +51,20 @@ void main() { references.add( BuiltMap({ - for (final key in ['a', 'b']) key: Result.success(reference), + 'a': Result.loading(), + 'b': Result.success(reference), + 'c': Result.error('error'), + 'd': Result.success(reference), }), ); - expect( bloc.references, emitsInOrder(>>[ + BuiltMap(), BuiltMap({ 'a': Result.loading(), - 'b': Result.loading(), - 'c': Result.loading(), - }), - BuiltMap({ - 'a': Result.success(reference), 'b': Result.success(reference), + 'c': Result.error('error'), }), ]), ); diff --git a/packages/neon_framework/packages/talk_app/test/message_test.dart b/packages/neon_framework/packages/talk_app/test/message_test.dart index dc618c20e3b..ee2cd1efe8c 100644 --- a/packages/neon_framework/packages/talk_app/test/message_test.dart +++ b/packages/neon_framework/packages/talk_app/test/message_test.dart @@ -725,7 +725,7 @@ void main() { await tester.pumpAndSettle(); - expect(find.byType(TalkReferencePreview), findsExactly(2)); + expect(find.byType(TalkReferencePreview), findsExactly(3)); for (final url in ['a', 'b']) { expect( find.byWidgetPredicate( @@ -735,6 +735,13 @@ void main() { findsOne, ); } + expect( + find.byWidgetPredicate( + (widget) => + widget is TalkReferencePreview && widget.url == 'c' && widget.openGraphObject == brokenOpenGraphObject, + ), + findsOne, + ); await expectLater( find.byType(TalkCommentMessage).first,