Skip to content

Commit dad2f97

Browse files
committed
unreads: Fix false positives in a debug-only warning
We don't expect UpdateMessageEvent to signal a change in a message's read state; that's what UpdateMessageFlagsEvent is for. Our unreads model does process `UpdateMessageEvent`s, though, to apply changes in a message's mentioned state. Also, we expect the client to be synced with the server for all messages' read state, assuming !oldUnreadsMissing. Where we process `UpdateMessageEvent`s, we have a `debugLog` line to alert us if one of these expectations isn't being met. It's been giving false positives when we get an UpdateMessageEvent for a bulk message move where some of the moved messages are read and some aren't. Since the server only intends the event's `flags` to apply to the event's `messageId` (one message), we should only be checking that message, not all the messages in the event's `messageIds`. From the API doc on `flags`: https://zulip.com/api/get-events#update_message > The user's personal message flags for the message with ID > message_id following the edit.
1 parent 28b3536 commit dad2f97

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/model/unreads.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,13 @@ class Unreads extends ChangeNotifier {
253253
// https://chat.zulip.org/#narrow/stream/378-api-design/topic/mark-as-read.20events.20with.20message.20moves.3F/near/1639957
254254
final bool isRead = event.flags.contains(MessageFlag.read);
255255
assert(() {
256-
if (!oldUnreadsMissing && !event.messageIds.every((messageId) {
257-
final isUnreadLocally = _slowIsPresentInDms(messageId) || _slowIsPresentInStreams(messageId);
258-
return isUnreadLocally == !isRead;
259-
})) {
256+
final isUnreadLocally = _slowIsPresentInDms(messageId) || _slowIsPresentInStreams(messageId);
257+
final isUnreadInEvent = !isRead;
258+
if (!oldUnreadsMissing && isUnreadLocally != isUnreadInEvent) {
260259
// If this happens, then either:
261-
// - the server and client have been out of sync about a message's
260+
// - the server and client have been out of sync about the message's
262261
// unread state since before this event, or
263-
// - this event was unexpectedly used to announce a change in a
262+
// - this event was unexpectedly used to announce a change in the
264263
// message's 'read' flag.
265264
debugLog('Unreads warning: got surprising UpdateMessageEvent');
266265
}

0 commit comments

Comments
 (0)