Skip to content

Commit 0c4653d

Browse files
sirpengignprice
authored andcommitted
msglist: Unconditionally add ApiNarrowIsUnread in markNarrowAsRead
Fixes: #377
1 parent 32ce11a commit 0c4653d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/widgets/message_list.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,13 @@ Future<void> markNarrowAsRead(BuildContext context, Narrow narrow) async {
824824
int responseCount = 0;
825825
int updatedCount = 0;
826826

827-
final apiNarrow = switch (narrow) {
828-
// Since there's a database index on is:unread, it's a fast
829-
// search query and thus worth using as an optimization
830-
// when processing all messages.
831-
AllMessagesNarrow() => [ApiNarrowIsUnread()],
832-
_ => narrow.apiEncode(),
833-
};
827+
// Include `is:unread` in the narrow. That has a database index, so
828+
// this can be an important optimization in narrows with a lot of history.
829+
// The server applies the same optimization within the (deprecated)
830+
// specialized endpoints for marking messages as read; see
831+
// `do_mark_stream_messages_as_read` in `zulip:zerver/actions/message_flags.py`.
832+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
833+
834834
while (true) {
835835
final result = await updateMessageFlagsForNarrow(connection,
836836
anchor: anchor,

test/widgets/message_list_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:http/http.dart' as http;
99
import 'package:zulip/api/model/events.dart';
1010
import 'package:zulip/api/model/initial_snapshot.dart';
1111
import 'package:zulip/api/model/model.dart';
12+
import 'package:zulip/api/model/narrow.dart';
1213
import 'package:zulip/api/route/messages.dart';
1314
import 'package:zulip/model/localizations.dart';
1415
import 'package:zulip/model/narrow.dart';
@@ -589,6 +590,7 @@ void main() {
589590
firstProcessedId: null, lastProcessedId: null,
590591
foundOldest: true, foundNewest: true).toJson());
591592
await tester.tap(find.byType(MarkAsReadWidget));
593+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
592594
check(connection.lastRequest).isA<http.Request>()
593595
..method.equals('POST')
594596
..url.path.equals('/api/v1/messages/flags/narrow')
@@ -597,7 +599,7 @@ void main() {
597599
'include_anchor': 'false',
598600
'num_before': '0',
599601
'num_after': '1000',
600-
'narrow': jsonEncode(narrow.apiEncode()),
602+
'narrow': jsonEncode(apiNarrow),
601603
'op': 'add',
602604
'flag': 'read',
603605
});
@@ -647,6 +649,7 @@ void main() {
647649
firstProcessedId: 1, lastProcessedId: 1989,
648650
foundOldest: true, foundNewest: false).toJson());
649651
await tester.tap(find.byType(MarkAsReadWidget));
652+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
650653
check(connection.lastRequest).isA<http.Request>()
651654
..method.equals('POST')
652655
..url.path.equals('/api/v1/messages/flags/narrow')
@@ -655,7 +658,7 @@ void main() {
655658
'include_anchor': 'false',
656659
'num_before': '0',
657660
'num_after': '1000',
658-
'narrow': jsonEncode(narrow.apiEncode()),
661+
'narrow': jsonEncode(apiNarrow),
659662
'op': 'add',
660663
'flag': 'read',
661664
});
@@ -674,7 +677,7 @@ void main() {
674677
'include_anchor': 'false',
675678
'num_before': '0',
676679
'num_after': '1000',
677-
'narrow': jsonEncode(narrow.apiEncode()),
680+
'narrow': jsonEncode(apiNarrow),
678681
'op': 'add',
679682
'flag': 'read',
680683
});
@@ -693,6 +696,7 @@ void main() {
693696
firstProcessedId: null, lastProcessedId: null,
694697
foundOldest: true, foundNewest: false).toJson());
695698
await tester.tap(find.byType(MarkAsReadWidget));
699+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
696700
check(connection.lastRequest).isA<http.Request>()
697701
..method.equals('POST')
698702
..url.path.equals('/api/v1/messages/flags/narrow')
@@ -701,7 +705,7 @@ void main() {
701705
'include_anchor': 'false',
702706
'num_before': '0',
703707
'num_after': '1000',
704-
'narrow': jsonEncode(narrow.apiEncode()),
708+
'narrow': jsonEncode(apiNarrow),
705709
'op': 'add',
706710
'flag': 'read',
707711
});

0 commit comments

Comments
 (0)