diff --git a/lib/components/pinnable/scroll_view.dart b/lib/components/pinnable/scroll_view.dart index 1bfb3b580..9f9d4c6ba 100644 --- a/lib/components/pinnable/scroll_view.dart +++ b/lib/components/pinnable/scroll_view.dart @@ -55,7 +55,7 @@ class PinnableMessageScrollView extends ScrollView { (context, index) => itemBuilder(index + offset), findChildIndexCallback: (key) { final index = findChildIndexCallback(key); - return index == null ? null : index - offset; + return index == null || index == -1 ? null : index - offset; }, childCount: intermediateCount, semanticIndexOffset: offset, diff --git a/lib/models/adapters/messages.dart b/lib/models/adapters/messages.dart index e8cfd5f01..b47969e45 100644 --- a/lib/models/adapters/messages.dart +++ b/lib/models/adapters/messages.dart @@ -36,7 +36,13 @@ class UpdateDeltaEvent extends DeltaEvent { } class ClearDeltaEvent extends DeltaEvent { - const ClearDeltaEvent(); + final String messageId; + final DateTime timestamp; + + const ClearDeltaEvent({ + required this.messageId, + required this.timestamp, + }); } DeltaEvent? _toDeltaEvent( @@ -107,7 +113,10 @@ DeltaEvent? _toDeltaEvent( timestamp: data['timestamp'].toDate()); return AppendDeltaEvent(model); case "clear": - return const ClearDeltaEvent(); + return ClearDeltaEvent( + messageId: change.doc.id, + timestamp: data['timestamp'].toDate(), + ); case "host": if (data['hosterChannelId'] == null) { // Since we might have some events saved without this field. diff --git a/lib/models/messages.dart b/lib/models/messages.dart index 77df9c3d0..ed67bc502 100644 --- a/lib/models/messages.dart +++ b/lib/models/messages.dart @@ -45,7 +45,12 @@ class MessagesModel extends ChangeNotifier { } } } else if (event is ClearDeltaEvent) { - _messages = [ChatClearedEventModel()]; + _messages = [ + ChatClearedEventModel( + messageId: event.messageId, + timestamp: event.timestamp, + ) + ]; _tts?.stop(); } notifyListeners(); diff --git a/lib/models/messages/message.dart b/lib/models/messages/message.dart index 0648712d7..5f4e51e4e 100644 --- a/lib/models/messages/message.dart +++ b/lib/models/messages/message.dart @@ -23,5 +23,7 @@ class SystemMessageModel extends MessageModel { } class ChatClearedEventModel extends MessageModel { - ChatClearedEventModel() : super(messageId: "", timestamp: DateTime.now()); + ChatClearedEventModel( + {required String messageId, required DateTime timestamp}) + : super(messageId: messageId, timestamp: timestamp); }