diff --git a/packages/neon/neon_talk/lib/src/blocs/room.dart b/packages/neon/neon_talk/lib/src/blocs/room.dart index edcb4bb32e2..93e38080d29 100644 --- a/packages/neon/neon_talk/lib/src/blocs/room.dart +++ b/packages/neon/neon_talk/lib/src/blocs/room.dart @@ -392,10 +392,15 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc { // If there are multiple messages updating the same parent message only the newest is applied because it already contains all values for (final newHiddenMessage in newHiddenMessages) { final parent = newHiddenMessage.parent!; + if (message.id == parent.id) { // Conversion from ChatMessage to ChatMessageWithParent is necessary because parent messages can't have parents of their own return spreed.ChatMessageWithParent.fromJson(parent.toJson()); } + + if (message.parent?.id == parent.id) { + return message.rebuild((b) => b.parent.replace(parent)); + } } return message; diff --git a/packages/neon/neon_talk/test/room_bloc_test.dart b/packages/neon/neon_talk/test/room_bloc_test.dart index 96bf636aa41..bdb379f24f7 100644 --- a/packages/neon/neon_talk/test/room_bloc_test.dart +++ b/packages/neon/neon_talk/test/room_bloc_test.dart @@ -118,7 +118,17 @@ Account mockTalkAccount() { json.encode({ 'ocs': { 'meta': {'status': '', 'statuscode': 0}, - 'data': List.generate(messageCount, (i) => getChatMessage(id: messageCount - i - 1)), + 'data': List.generate( + messageCount, + (i) => getChatMessage( + id: messageCount - i - 1, + parent: messageCount - i - 2 >= 0 + ? getChatMessage( + id: messageCount - i - 2, + ) + : null, + ), + ), }, }), 200, @@ -360,8 +370,8 @@ void main() { roomBloc.messages.transformResult((e) => BuiltList(e.map((m) => m.parent?.id))), emitsInOrder([ Result>.loading(), - Result.success(BuiltList([null, null, null])), - Result.success(BuiltList([message.id, null, null, null])), + Result.success(BuiltList([1, 0, null])), + Result.success(BuiltList([1, 1, 0, null])), ]), ); @@ -593,6 +603,26 @@ void main() { ), ]), ); + expect( + roomBloc.messages.transformResult((e) => BuiltList(e.map((m) => m.parent?.messageType))), + emitsInOrder([ + Result>.loading(), + Result.success( + BuiltList([ + spreed.MessageType.comment, + spreed.MessageType.comment, + null, + ]), + ), + Result.success( + BuiltList([ + spreed.MessageType.commentDeleted, + null, + null, + ]), + ), + ]), + ); final message = MockChatMessage(); when(() => message.id).thenReturn(1);