Skip to content

Commit 0cd2da5

Browse files
3 More test cases to go bitch
1 parent b033dc4 commit 0cd2da5

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

lib/model/message_list.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
487487
// Anchor message ID is used to fetch messages from a specific point in the list.
488488
// It is set when the user navigates to a message list page with a specific anchor message.
489489
int? anchorMessageId;
490-
int? get anchorIndex => anchorMessageId != null ? findItemWithMessageId(anchorMessageId!) : null;
490+
int get anchorIndex => anchorMessageId != null ? findItemWithMessageId(anchorMessageId!) : 0;
491491
factory MessageListView.init(
492492
{required PerAccountStore store, required Narrow narrow, int? anchorMessageId}) {
493493
final view = MessageListView._(store: store, narrow: narrow, anchorMessageId: anchorMessageId);
@@ -591,7 +591,9 @@ class MessageListView with ChangeNotifier, _MessageSequence {
591591
? kMessageListFetchBatchSize ~/2 // Fetch messages before and after anchor
592592
: 0, // Don't fetch newer messages when no anchor
593593
);
594-
anchorMessageId ??= result.messages.last.id;
594+
if(result.messages.isNotEmpty){
595+
anchorMessageId ??= result.messages.last.id;
596+
}
595597

596598
if (this.generation > generation) return;
597599
store.reconcileMessages(result.messages);

lib/widgets/message_list.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
483483
model!.addListener(_modelChanged);
484484
await model!.fetchInitial();
485485
setState(() {
486-
oldItems = model!.items.sublist(0, model!.anchorIndex!+1);
487-
newItems = model!.items.sublist(model!.anchorIndex!+1, model!.items.length);
486+
oldItems = model!.items.sublist(0, model!.anchorIndex+1);
487+
newItems = model!.items.sublist(model!.anchorIndex+1, model!.items.length);
488488
});
489489
}
490490

@@ -498,8 +498,8 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
498498
final previousLength = oldItems.length + newItems.length;
499499

500500
setState(() {
501-
oldItems = model!.items.sublist(0, model!.anchorIndex!+1);
502-
newItems = model!.items.sublist(model!.anchorIndex!+1, model!.items.length);
501+
oldItems = model!.items.sublist(0, model!.anchorIndex+1);
502+
newItems = model!.items.sublist(model!.anchorIndex+1, model!.items.length);
503503
// The actual state lives in the [MessageListView] model.
504504
// This method was called because that just changed.
505505
});

test/widgets/message_list_test.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void main() {
366366
await tester.tap(find.byType(ScrollToBottomButton));
367367
await tester.pumpAndSettle();
368368
check(isButtonVisible(tester)).equals(false);
369-
check(scrollController.position.pixels).equals(0);
369+
check(scrollController.position.maxScrollExtent - scrollController.position.pixels).isLessThan(36);
370370
});
371371
});
372372

@@ -720,6 +720,10 @@ void main() {
720720
final existingMessage = eg.streamMessage(
721721
stream: eg.stream(), topic: 'new topic', content: 'Existing message');
722722
prepareGetMessageResponse([existingMessage, message]);
723+
// Prepare response for fetchInitial after move
724+
connection.prepare(json: eg.newestGetMessagesResult(
725+
foundOldest: true,
726+
messages: [existingMessage, message]).toJson());
723727
handleMessageMoveEvent([message], 'new topic');
724728
await tester.pump(const Duration(seconds: 1));
725729

@@ -732,6 +736,10 @@ void main() {
732736
await setupMessageListPage(tester, narrow: narrow, messages: [message], streams: [channel]);
733737

734738
prepareGetMessageResponse([message]);
739+
// Prepare response for fetchInitial after move
740+
connection.prepare(json: eg.newestGetMessagesResult(
741+
foundOldest: true,
742+
messages: [message]).toJson());
735743
handleMessageMoveEvent([message], 'new topic');
736744
await tester.pump(const Duration(seconds: 1));
737745

0 commit comments

Comments
 (0)