Skip to content

Commit

Permalink
unreads: Take a missed opportunity for a debugLog to fire when helpful
Browse files Browse the repository at this point in the history
For this debug check to work, it just needs a known read state for
one message.

When `oldUnreadsMissing` is false (the common case), the model holds
one of two answers for a message's read state: known-unread or
known-read.

When `oldUnreadsMissing` is true, the model holds known-unread or
unknown.

Before, we were skipping the debug check on seeing that
`oldUnreadsMissing` is true. That's earlier than we need to abort,
because the model might still hold a known-unread state for the
message. Now, we go ahead with the debug check if that's the case,
and still skip it otherwise.

Done by using our new `isUnread` helper, in this separate commit
because it's not NFC in debug mode.
  • Loading branch information
chrisbobbe committed Jan 3, 2025
1 parent d65701d commit 7d64e2f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,14 @@ class Unreads extends ChangeNotifier {
// https://chat.zulip.org/#narrow/stream/378-api-design/topic/mark-as-read.20events.20with.20message.20moves.3F/near/1639957
final bool isRead = event.flags.contains(MessageFlag.read);
assert(() {
final isUnreadLocally = _slowIsPresentInDms(messageId) || _slowIsPresentInStreams(messageId);
final isUnreadLocally = isUnread(messageId);
final isUnreadInEvent = !isRead;
if (!oldUnreadsMissing && isUnreadLocally != isUnreadInEvent) {

// Unread state unknown because of [oldUnreadsMissing].
// We were going to check something but can't; shrug.
if (isUnreadLocally == null) return true;

if (isUnreadLocally != isUnreadInEvent) {
// If this happens, then either:
// - the server and client have been out of sync about the message's
// unread state since before this event, or
Expand Down

0 comments on commit 7d64e2f

Please sign in to comment.