Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,13 @@ Future<void> markNarrowAsRead(BuildContext context, Narrow narrow) async {
int responseCount = 0;
int updatedCount = 0;

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

while (true) {
final result = await updateMessageFlagsForNarrow(connection,
anchor: anchor,
Expand Down
12 changes: 8 additions & 4 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:http/http.dart' as http;
import 'package:zulip/api/model/events.dart';
import 'package:zulip/api/model/initial_snapshot.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/api/model/narrow.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/model/localizations.dart';
import 'package:zulip/model/narrow.dart';
Expand Down Expand Up @@ -589,6 +590,7 @@ void main() {
firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: true).toJson());
await tester.tap(find.byType(MarkAsReadWidget));
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags/narrow')
Expand All @@ -597,7 +599,7 @@ void main() {
'include_anchor': 'false',
'num_before': '0',
'num_after': '1000',
'narrow': jsonEncode(narrow.apiEncode()),
'narrow': jsonEncode(apiNarrow),
'op': 'add',
'flag': 'read',
});
Expand Down Expand Up @@ -647,6 +649,7 @@ void main() {
firstProcessedId: 1, lastProcessedId: 1989,
foundOldest: true, foundNewest: false).toJson());
await tester.tap(find.byType(MarkAsReadWidget));
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags/narrow')
Expand All @@ -655,7 +658,7 @@ void main() {
'include_anchor': 'false',
'num_before': '0',
'num_after': '1000',
'narrow': jsonEncode(narrow.apiEncode()),
'narrow': jsonEncode(apiNarrow),
'op': 'add',
'flag': 'read',
});
Expand All @@ -674,7 +677,7 @@ void main() {
'include_anchor': 'false',
'num_before': '0',
'num_after': '1000',
'narrow': jsonEncode(narrow.apiEncode()),
'narrow': jsonEncode(apiNarrow),
'op': 'add',
'flag': 'read',
});
Expand All @@ -693,6 +696,7 @@ void main() {
firstProcessedId: null, lastProcessedId: null,
foundOldest: true, foundNewest: false).toJson());
await tester.tap(find.byType(MarkAsReadWidget));
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages/flags/narrow')
Expand All @@ -701,7 +705,7 @@ void main() {
'include_anchor': 'false',
'num_before': '0',
'num_after': '1000',
'narrow': jsonEncode(narrow.apiEncode()),
'narrow': jsonEncode(apiNarrow),
'op': 'add',
'flag': 'read',
});
Expand Down