Skip to content

Commit ed57148

Browse files
committed
msglist: Set unreads.oldUnreadsMissing to false on batched mark-all-as-read
1 parent e7fe06c commit ed57148

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

lib/widgets/message_list.dart

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,24 @@ class MarkAsReadWidget extends StatelessWidget {
366366
await showErrorDialog(context: context,
367367
title: zulipLocalizations.errorMarkAsReadFailedTitle,
368368
message: e.toString());
369+
return;
370+
}
371+
if (!context.mounted) return;
372+
if (narrow == const AllMessagesNarrow()) {
373+
// We've learned that the mark-all-as-read work succeeded, so we know
374+
// there can't be ancient unreads we don't know about. Update the
375+
// Unreads model to reflect that.
376+
//
377+
// [Unreads] is supposed to do this naturally, in
378+
// handleUpdateMessageFlagsEvent. That's based on the documented behavior
379+
// that a completed mark-all-as-read task gets signaled by `all: true` on
380+
// the [UpdateMessageFlagsAddEvent]. But when using this new batch-
381+
// processing protocol, it seems clients have to track progress and
382+
// success themselves; the event from the last batch is unmarked.
383+
// Discussion:
384+
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20Mark-as-read/near/1680275>
385+
PerAccountStoreWidget.of(context).unreads.oldUnreadsMissing = false;
369386
}
370-
// TODO: clear Unreads.oldUnreadsMissing when `narrow` is [AllMessagesNarrow]
371-
// In the rare case that the user had more than 50K total unreads
372-
// on the server, the client won't have known about all of them;
373-
// this was communicated to the client via `oldUnreadsMissing`.
374-
//
375-
// However, since we successfully marked **everything** as read,
376-
// we know that we now have a correct data set of unreads.
377387
}
378388

379389
@override

test/widgets/message_list_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,23 @@ void main() {
570570
});
571571
});
572572

573+
testWidgets('markNarrowAsRead on mark-all-as-read when Unreads.oldUnreadsMissing: true', (tester) async {
574+
const narrow = AllMessagesNarrow();
575+
await setupMessageListPage(tester,
576+
narrow: narrow, messages: [message], unreadMsgs: unreadMsgs);
577+
check(isMarkAsReadButtonVisible(tester)).isTrue();
578+
store.unreads.oldUnreadsMissing = true;
579+
580+
final connection = store.connection as FakeApiConnection;
581+
connection.prepare(json: UpdateMessageFlagsForNarrowResult(
582+
processedCount: 11, updatedCount: 3,
583+
firstProcessedId: null, lastProcessedId: null,
584+
foundOldest: true, foundNewest: true).toJson());
585+
await tester.tap(find.byType(MarkAsReadWidget));
586+
await tester.pumpAndSettle();
587+
check(store.unreads.oldUnreadsMissing).isFalse();
588+
});
589+
573590
testWidgets('markNarrowAsRead on invalid response', (WidgetTester tester) async {
574591
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
575592
final narrow = TopicNarrow.ofMessage(message);

0 commit comments

Comments
 (0)