Skip to content

Commit defe54b

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 34dbe33 commit defe54b

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
@@ -479,7 +479,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
479479
/// which might be made internally by this class in order to
480480
/// fetch the messages from scratch, e.g. after certain events.
481481
Anchor get anchor => _anchor;
482-
final Anchor _anchor;
482+
Anchor _anchor;
483483

484484
void _register() {
485485
store.registerMessageList(this);
@@ -756,6 +756,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
756756
}
757757
}
758758

759+
void jumpToEnd() {
760+
assert(fetched);
761+
assert(!haveNewest);
762+
assert(anchor != AnchorCode.newest);
763+
_anchor = AnchorCode.newest;
764+
_reset();
765+
notifyListeners();
766+
fetchInitial();
767+
}
768+
759769
/// Add [outboxMessage] if it belongs to the view.
760770
void addOutboxMessage(OutboxMessage outboxMessage) {
761771
// TODO(#1441) implement this

lib/widgets/message_list.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
543543
// redirected us to the new location of the operand message ID.
544544
widget.onNarrowChanged(model.narrow);
545545
}
546+
// TODO when model reset, reset scroll
546547
setState(() {
547548
// The actual state lives in the [MessageListView] model.
548549
// This method was called because that just changed.
@@ -618,6 +619,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
618619
// MessageList's dartdoc.
619620
child: SafeArea(
620621
child: ScrollToBottomButton(
622+
model: model,
621623
scrollController: scrollController,
622624
visible: _scrollToBottomVisible))),
623625
])))));
@@ -817,13 +819,23 @@ class _MessageListLoadingMore extends StatelessWidget {
817819
}
818820

819821
class ScrollToBottomButton extends StatelessWidget {
820-
const ScrollToBottomButton({super.key, required this.scrollController, required this.visible});
822+
const ScrollToBottomButton({
823+
super.key,
824+
required this.model,
825+
required this.scrollController,
826+
required this.visible,
827+
});
821828

822-
final ValueNotifier<bool> visible;
829+
final MessageListView model;
823830
final MessageListScrollController scrollController;
831+
final ValueNotifier<bool> visible;
824832

825833
void _scrollToBottom() {
826-
scrollController.position.scrollToEnd();
834+
if (model.haveNewest) {
835+
scrollController.position.scrollToEnd();
836+
} else {
837+
model.jumpToEnd();
838+
}
827839
}
828840

829841
@override

0 commit comments

Comments
 (0)