Skip to content

Commit 70def74

Browse files
committed
wip jumpToEnd; TODO test, doc; TODO discuss criterion a bit more
When the message list is truly far back in history -- for example, at first unread in the combined feed or a busy channel, for a user who has some old unreads going back months and years -- trying to scroll smoothly to the bottom is hopeless. The only way to get to the newest messages in any reasonable amount of time is to jump there. So, do that.
1 parent eaae6ec commit 70def74

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/model/message_list.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
449449
/// which might be made internally by this class in order to
450450
/// fetch the messages from scratch, e.g. after certain events.
451451
Anchor get anchor => _anchor;
452-
final Anchor _anchor;
452+
Anchor _anchor;
453453

454454
void _register() {
455455
store.registerMessageList(this);
@@ -726,6 +726,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
726726
}
727727
}
728728

729+
void jumpToEnd() {
730+
assert(fetched);
731+
assert(!haveNewest);
732+
assert(anchor != AnchorCode.newest);
733+
_anchor = AnchorCode.newest;
734+
_reset();
735+
notifyListeners();
736+
fetchInitial();
737+
}
738+
729739
void handleUserTopicEvent(UserTopicEvent event) {
730740
switch (_canAffectVisibility(event)) {
731741
case VisibilityEffect.none:

lib/widgets/message_list.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
511511
// redirected us to the new location of the operand message ID.
512512
widget.onNarrowChanged(model.narrow);
513513
}
514+
// TODO when model reset, reset scroll
514515
setState(() {
515516
// The actual state lives in the [MessageListView] model.
516517
// This method was called because that just changed.
@@ -586,6 +587,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
586587
// MessageList's dartdoc.
587588
child: SafeArea(
588589
child: ScrollToBottomButton(
590+
model: model,
589591
scrollController: scrollController,
590592
visible: _scrollToBottomVisible))),
591593
])))));
@@ -786,13 +788,23 @@ class _MessageListLoadingMore extends StatelessWidget {
786788
}
787789

788790
class ScrollToBottomButton extends StatelessWidget {
789-
const ScrollToBottomButton({super.key, required this.scrollController, required this.visible});
791+
const ScrollToBottomButton({
792+
super.key,
793+
required this.model,
794+
required this.scrollController,
795+
required this.visible,
796+
});
790797

791-
final ValueNotifier<bool> visible;
798+
final MessageListView model;
792799
final MessageListScrollController scrollController;
800+
final ValueNotifier<bool> visible;
793801

794802
void _scrollToBottom() {
795-
scrollController.position.scrollToEnd();
803+
if (model.haveNewest) {
804+
scrollController.position.scrollToEnd();
805+
} else {
806+
model.jumpToEnd();
807+
}
796808
}
797809

798810
@override

0 commit comments

Comments
 (0)