@@ -2742,6 +2742,53 @@ void main() {
27422742 checkNotifiedOnce ();
27432743 }));
27442744
2745+ group ('one message per block?' , () {
2746+ final channelId = 1 ;
2747+ final topic = 'some topic' ;
2748+ void doTest ({required Narrow narrow, required bool expected}) {
2749+ test ('$narrow : ${expected ? 'yes' : 'no' }' , () => awaitFakeAsync ((async ) async {
2750+ final sender = eg.user ();
2751+ final channel = eg.stream (streamId: channelId);
2752+ final message1 = eg.streamMessage (
2753+ sender: sender,
2754+ stream: channel,
2755+ topic: topic,
2756+ flags: [MessageFlag .starred, MessageFlag .mentioned],
2757+ );
2758+ final message2 = eg.streamMessage (
2759+ sender: sender,
2760+ stream: channel,
2761+ topic: topic,
2762+ flags: [MessageFlag .starred, MessageFlag .mentioned],
2763+ );
2764+
2765+ await prepare (
2766+ narrow: narrow,
2767+ stream: channel,
2768+ );
2769+ connection.prepare (json: newestResult (
2770+ foundOldest: false ,
2771+ messages: [message1, message2],
2772+ ).toJson ());
2773+ await model.fetchInitial ();
2774+ checkNotifiedOnce ();
2775+
2776+ check (model).items.deepEquals (< Condition <Object ?>> [
2777+ (it) => it.isA <MessageListRecipientHeaderItem >(),
2778+ (it) => it.isA <MessageListMessageItem >(),
2779+ if (expected) (it) => it.isA <MessageListRecipientHeaderItem >(),
2780+ (it) => it.isA <MessageListMessageItem >(),
2781+ ]);
2782+ }));
2783+ }
2784+
2785+ doTest (narrow: CombinedFeedNarrow (), expected: false );
2786+ doTest (narrow: ChannelNarrow (channelId), expected: false );
2787+ doTest (narrow: TopicNarrow (channelId, eg.t (topic)), expected: false );
2788+ doTest (narrow: StarredMessagesNarrow (), expected: true );
2789+ doTest (narrow: MentionsNarrow (), expected: true );
2790+ });
2791+
27452792 test ('showSender is maintained correctly' , () => awaitFakeAsync ((async ) async {
27462793 // TODO(#150): This will get more complicated with message moves.
27472794 // Until then, we always compute this sequentially from oldest to newest.
@@ -3011,6 +3058,7 @@ void checkInvariants(MessageListView model) {
30113058 for (int j = 0 ; j < allMessages.length; j++ ) {
30123059 bool forcedShowSender = false ;
30133060 if (j == 0
3061+ || model.oneMessagePerBlock
30143062 || ! haveSameRecipient (allMessages[j- 1 ], allMessages[j])) {
30153063 check (model.items[i++ ]).isA <MessageListRecipientHeaderItem >()
30163064 .message.identicalTo (allMessages[j]);
0 commit comments