Skip to content

Commit f420613

Browse files
committed
narrow [nfc]: Make Narrow.containsMessage return nullable bool
Done as preparation to implement a new Narrow subclass for keyword search. We can't really implement a client-side "contains-message" predicate for search; it's up to the server to decide whether a message matches the search query. A simple path to representing that, done here, is to just change Narrow.containsMessage's contract to say that it always returns null if the narrow is a search narrow. The app-code changes show just small behavior choices for a message-list page in a search narrow, which we'll implement soon: - Message events are ignored - Outbox messages never appear Various TODOs in tests; we'll handle all of those as part of adding the keyword-search Narrow subclass.
1 parent 55e14f4 commit f420613

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

lib/model/message_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
939939
bool _shouldAddOutboxMessage(OutboxMessage outboxMessage) {
940940
assert(haveNewest);
941941
return !outboxMessage.hidden
942-
&& narrow.containsMessage(outboxMessage)
942+
&& narrow.containsMessage(outboxMessage) == true
943943
&& _messageVisible(outboxMessage);
944944
}
945945

@@ -1026,7 +1026,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
10261026
/// Add [MessageEvent.message] to this view, if it belongs here.
10271027
void handleMessageEvent(MessageEvent event) {
10281028
final message = event.message;
1029-
if (!narrow.containsMessage(message) || !_messageVisible(message)) {
1029+
if (narrow.containsMessage(message) != true || !_messageVisible(message)) {
10301030
assert(event.localMessageId == null || outboxMessages.none((message) =>
10311031
message.localMessageId == int.parse(event.localMessageId!, radix: 10)));
10321032
return;

lib/model/narrow.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ sealed class Narrow {
1919
/// This does not necessarily mean the message list would show this message
2020
/// when navigated to this narrow; in particular it does not address the
2121
/// question of whether the stream or topic, or the sending user, is muted.
22-
bool containsMessage(MessageBase message);
22+
///
23+
/// Null when the client is unable to predict whether the message
24+
/// satisfies the filters of this narrow, e.g. when this is a search narrow.
25+
bool? containsMessage(MessageBase message);
2326

2427
/// This narrow, expressed as an [ApiNarrow].
2528
ApiNarrow apiEncode();

lib/widgets/message_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class MessageListAppBarTitle extends StatelessWidget {
587587
// either still fetching messages (and the user can reopen the
588588
// sheet after that finishes) or there aren't any messages to
589589
// act on anyway.
590-
assert(someMessage == null || narrow.containsMessage(someMessage));
590+
assert(someMessage == null || narrow.containsMessage(someMessage)!);
591591
showTopicActionSheet(context,
592592
channelId: streamId,
593593
topic: topic,

test/model/message_list_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,9 @@ void checkInvariants(MessageListView model) {
30013001
final allMessages = [...model.messages, ...model.outboxMessages];
30023002

30033003
for (final message in allMessages) {
3004-
check(model.narrow.containsMessage(message)).isTrue();
3004+
check(model.narrow.containsMessage(message))
3005+
.isNotNull() // TODO allow/expect null if narrow is a search narrow.
3006+
.isTrue();
30053007

30063008
if (message is! MessageBase<StreamConversation>) continue;
30073009
final conversation = message.conversation;

test/widgets/action_sheet_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
6363
Future<void> Function()? beforeLongPress,
6464
}) async {
6565
addTearDown(testBinding.reset);
66-
assert(narrow.containsMessage(message));
66+
// TODO(#1667) will be null in a search narrow; remove `!`.
67+
assert(narrow.containsMessage(message)!);
6768

6869
await testBinding.globalStore.add(
6970
eg.selfAccount,

test/widgets/compose_box_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,10 @@ void main() {
17021702

17031703
Message msgInNarrow(Narrow narrow) {
17041704
final List<Message> messages = [message, dmMessage];
1705-
return messages.where((m) => narrow.containsMessage(m)).single;
1705+
return messages.where(
1706+
// TODO(#1667) will be null in a search narrow; remove `!`.
1707+
(m) => narrow.containsMessage(m)!
1708+
).single;
17061709
}
17071710

17081711
int msgIdInNarrow(Narrow narrow) => msgInNarrow(narrow).id;

test/widgets/emoji_reaction_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ void main() {
330330
required Narrow narrow,
331331
}) async {
332332
addTearDown(testBinding.reset);
333-
assert(narrow.containsMessage(message));
333+
// TODO(#1667) will be null in a search narrow; remove `!`.
334+
assert(narrow.containsMessage(message)!);
334335

335336
final httpClient = FakeImageHttpClient();
336337
debugNetworkImageHttpClientProvider = () => httpClient;

0 commit comments

Comments
 (0)