Skip to content

Commit

Permalink
msglist: Set unreads.oldUnreadsMissing to false on batched mark-all-a…
Browse files Browse the repository at this point in the history
…s-read
  • Loading branch information
chrisbobbe committed Nov 11, 2023
1 parent e7fe06c commit ed57148
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,24 @@ class MarkAsReadWidget extends StatelessWidget {
await showErrorDialog(context: context,
title: zulipLocalizations.errorMarkAsReadFailedTitle,
message: e.toString());
return;
}
if (!context.mounted) return;
if (narrow == const AllMessagesNarrow()) {
// We've learned that the mark-all-as-read work succeeded, so we know
// there can't be ancient unreads we don't know about. Update the
// Unreads model to reflect that.
//
// [Unreads] is supposed to do this naturally, in
// handleUpdateMessageFlagsEvent. That's based on the documented behavior
// that a completed mark-all-as-read task gets signaled by `all: true` on
// the [UpdateMessageFlagsAddEvent]. But when using this new batch-
// processing protocol, it seems clients have to track progress and
// success themselves; the event from the last batch is unmarked.
// Discussion:
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20Mark-as-read/near/1680275>
PerAccountStoreWidget.of(context).unreads.oldUnreadsMissing = false;
}
// TODO: clear Unreads.oldUnreadsMissing when `narrow` is [AllMessagesNarrow]
// In the rare case that the user had more than 50K total unreads
// on the server, the client won't have known about all of them;
// this was communicated to the client via `oldUnreadsMissing`.
//
// However, since we successfully marked **everything** as read,
// we know that we now have a correct data set of unreads.
}

@override
Expand Down
17 changes: 17 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,23 @@ void main() {
});
});

testWidgets('markNarrowAsRead on mark-all-as-read when Unreads.oldUnreadsMissing: true', (tester) async {
const narrow = AllMessagesNarrow();
await setupMessageListPage(tester,
narrow: narrow, messages: [message], unreadMsgs: unreadMsgs);
check(isMarkAsReadButtonVisible(tester)).isTrue();
store.unreads.oldUnreadsMissing = true;

final connection = store.connection as FakeApiConnection;
connection.prepare(json: UpdateMessageFlagsForNarrowResult(
processedCount: 11, updatedCount: 3,
firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: true).toJson());
await tester.tap(find.byType(MarkAsReadWidget));
await tester.pumpAndSettle();
check(store.unreads.oldUnreadsMissing).isFalse();
});

testWidgets('markNarrowAsRead on invalid response', (WidgetTester tester) async {
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
final narrow = TopicNarrow.ofMessage(message);
Expand Down

0 comments on commit ed57148

Please sign in to comment.