refactor: redesign status history

This commit is contained in:
cogwheel0
2025-09-28 15:58:46 +05:30
parent 0ff48eeb38
commit cb86ad8cd2
3 changed files with 616 additions and 325 deletions

View File

@@ -499,8 +499,26 @@ class ChatMessagesNotifier extends Notifier<List<ChatMessage>> {
}
void appendStatusUpdate(String messageId, ChatStatusUpdate update) {
final withTimestamp = update.occurredAt == null
? update.copyWith(occurredAt: DateTime.now())
: update;
updateMessageById(messageId, (current) {
final history = [...current.statusHistory, update];
final history = [...current.statusHistory];
if (history.isNotEmpty) {
final last = history.last;
final sameAction =
last.action != null && last.action == withTimestamp.action;
final sameDescription =
(withTimestamp.description?.isNotEmpty ?? false) &&
withTimestamp.description == last.description;
if (sameAction && sameDescription) {
history[history.length - 1] = withTimestamp;
return current.copyWith(statusHistory: history);
}
}
history.add(withTimestamp);
return current.copyWith(statusHistory: history);
});
}