Skip to content

Commit

Permalink
fix: add messageId and timestamp to clear event (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 authored Jul 6, 2022
1 parent 9a37d80 commit 0055d9e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/components/pinnable/scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions lib/models/adapters/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion lib/models/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion lib/models/messages/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 0055d9e

Please sign in to comment.