fix(chat): clear unread state for messages read in an open chat

Messages arriving while a conversation was open were never marked as read,
so the chat list kept showing them as unread after going back. The screen
now marks incoming messages read while it is on top and the app is in the
foreground, again when the app returns to the foreground, and on leaving.

Read state is now monotonic in Conversation.updateMessage, so a stale copy
of a message (attachment download, delayed resend) can no longer flip it
back to unread.

Also create the swipe-to-reply animation controller lazily instead of in
dispose().
This commit is contained in:
Julius Joska
2026-10-11 15:31:53 +02:00
parent 05eeccd83b
commit bfea7201f7
3 changed files with 103 additions and 4 deletions
+9 -1
View File
@@ -55,9 +55,17 @@ class Conversation {
/// Nahraď zprávu se stejným id (změna stavu přílohy, doručenka…).
/// Neexistující id se tiše ignoruje (zpráva mohla být smazána).
///
/// Přečtení je jednosměrné: aktualizace nesmí vrátit už přečtenou zprávu
/// mezi nepřečtené. Volající často drží kopii zprávy načtenou před
/// otevřením chatu (stahování přílohy, dodatečné odeslání) a bez téhle
/// pojistky by zápis po návratu ze stahování obnovil odznak nepřečtených.
void updateMessage(Message message) {
final index = messages.indexWhere((m) => m.id == message.id);
if (index >= 0) messages[index] = message;
if (index < 0) return;
messages[index] = messages[index].isRead && !message.isRead
? message.copyWith(isRead: true)
: message;
}
/// Označ všechny zprávy jako přečtené