From c7e894fcb57430ec9794bf879f00702ffbeb5edc Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Sat, 11 Nov 2023 15:39:43 -0500 Subject: [PATCH] msglist: Set unreads.oldUnreadsMissing to false on batched mark-all-as-read --- lib/widgets/message_list.dart | 12 +++++------- test/widgets/message_list_test.dart | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index 58f75a9ef3..f6203f7715 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -433,14 +433,12 @@ class MarkAsReadWidget extends StatelessWidget { await showErrorDialog(context: context, title: zulipLocalizations.errorMarkAsReadFailedTitle, message: e.toString()); + return; + } + if (!context.mounted) return; + if (narrow is AllMessagesNarrow && !useLegacy) { + PerAccountStoreWidget.of(context).unreads.handleAllMessagesReadSuccess(); } - // 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 diff --git a/test/widgets/message_list_test.dart b/test/widgets/message_list_test.dart index d671f4fb51..517b80add9 100644 --- a/test/widgets/message_list_test.dart +++ b/test/widgets/message_list_test.dart @@ -25,6 +25,7 @@ import '../model/binding.dart'; import '../model/message_list_test.dart'; import '../model/test_store.dart'; import '../flutter_checks.dart'; +import '../model/unreads_checks.dart'; import '../stdlib_checks.dart'; import '../test_images.dart'; import 'content_checks.dart'; @@ -755,6 +756,22 @@ 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; + + 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); @@ -793,6 +810,9 @@ void main() { narrow: narrow, messages: [message], unreadMsgs: unreadMsgs); check(isMarkAsReadButtonVisible(tester)).isTrue(); + // Might as well test with oldUnreadsMissing: true. + store.unreads.oldUnreadsMissing = true; + connection.zulipFeatureLevel = 154; connection.prepare(json: {}); await tester.tap(find.byType(MarkAsReadWidget)); @@ -802,6 +822,10 @@ void main() { ..bodyFields.deepEquals({}); await tester.pumpAndSettle(); // process pending timers + + // Check that [Unreads.handleAllMessagesReadSuccess] wasn't called; + // in the legacy protocol, that'd be redundant with the mark-read event. + check(store.unreads).oldUnreadsMissing.isTrue(); }); testWidgets('StreamNarrow on legacy server', (WidgetTester tester) async {