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 Feb 12, 2024
1 parent 763995b commit c7e894f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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 {
Expand Down

0 comments on commit c7e894f

Please sign in to comment.