Skip to content

anchors 8/n: Let new messages accumulate in bottom sliver #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented May 8, 2025

This is the next round after #1468.

After this PR, not only does the last message from the initial fetch go into the bottom sliver, but it remains there even while new messages arrive as events, and those new messages go into the bottom sliver below it.

The main motivation for this change is that it brings us closer to having a fetchNewer method, and therefore to being able to have the message list start out in the middle of history, #82. Along the way it also gives us the "90% solution" described in #83, so that new messages don't cause everything on the screen to jump up when you're already scrolled up in history.

Selected commit messages

f4b6e41 msglist test: Ensure later errors get reported in full too

Otherwise, if several different test cases in this file fail due to
checks failing inside checkInvariants, then only the first one gets
reported in detail with the comparison and the stack trace.

48983a3 msglist [nfc]: Move sliver boundary into the view-model

This will allow the model to maintain it over time as newer messages
arrive or get fetched.

e21f601 msglist: Let new messages accumulate in bottom sliver

This is NFC for the behavior at initial fetch. But thereafter, with
this change, messages never move between slivers, and new messages
go into the bottom sliver.

I believe the main user-visible consequence of this change is that if
the user is scrolled up in history and then a new message comes in,
the new message will no longer cause all the messages to shift upward.
This is the "90% solution" to #83.

On the other hand, if the user is scrolled all the way to the end,
then they still remain that way when a new message comes in --
there's specific logic to ensure that in MessageListScrollPosition,
and an existing test in test/widgets/message_list_test.dart verifies
it end to end.

The main motivation for this change is that it brings us closer to
having a fetchNewer method, and therefore to being able to have the
message list start out in the middle of history.

This change also allows us to revert a portion of fca651b, where
a test had had to be weakened slightly because messages began to
get moved between slivers.

@gnprice gnprice added the maintainer review PR ready for review by Zulip maintainers label May 8, 2025
@gnprice gnprice force-pushed the pr-preserve-sliver-boundary branch from e21f601 to 0811136 Compare May 13, 2025 23:50
gnprice added 8 commits May 15, 2025 17:35
Otherwise, if several different test cases in this file fail due to
checks failing inside checkInvariants, then only the first one gets
reported in detail with the comparison and the stack trace.
This will allow the model to maintain it over time as newer messages
arrive or get fetched.
This brings the behavior closer to what we'll want in the future,
and so allows the next commit affecting `middleItem` to be NFC.

This itself is practically NFC.  It's entirely NFC except in the
case where there are no messages, so that `items` consists only of a
history-start marker; and in that case, it causes that marker to go
in the top sliver rather than the bottom.

I believe the only observable effect of that change is that if the
viewport is so very short that the history-start marker is too tall
to fit (so that it's possible to scroll when that's the only item),
then the initial scroll position will be different.
This gives a bit more structured of an idea of what `middleItem`
is supposed to mean.  We'll use this for maintaining `middleItem`
as a more dynamic value in upcoming commits.
This new logic maintains `middleItem` according to its documented
relationship with `middleMessage`.  Because of the current
definition of `middleMessage`, that produces the same result as
the previous definition of `middleItem`.

The key reasoning for why this logic works is: this touches all the
code that modifies `items`, to ensure that code keeps `middleItem`
up to date.  And all the code which modifies `messages` (which is
the only way to modify `middleMessage`) already calls
`_reprocessAll` to compute `items` from scratch, except one site
in `_addMessage`.  Studying `_addMessage`, it also maintains
`middleItem` correctly, though for that conclusion one needs the
specifics of the definition of `middleMessage`.

This change involves no new test code: all this logic is in
scenarios well exercised by existing tests, and the invariant-checks
introduced in the previous commit then effectively test this logic.
To be sure of that, I also confirmed that commenting out any one of
these updates to `middleItem` causes some tests to fail.
This is NFC for the behavior at initial fetch.  But thereafter, with
this change, messages never move between slivers, and new messages
go into the bottom sliver.

I believe the main user-visible consequence of this change is that if
the user is scrolled up in history and then a new message comes in,
the new message will no longer cause all the messages to shift upward.
This is the "90% solution" to zulip#83.

On the other hand, if the user is scrolled all the way to the end,
then they still remain that way when a new message comes in --
there's specific logic to ensure that in MessageListScrollPosition,
and an existing test in test/widgets/message_list_test.dart verifies
it end to end.

The main motivation for this change is that it brings us closer to
having a `fetchNewer` method, and therefore to being able to have the
message list start out in the middle of history.

This change also allows us to revert a portion of fca651b, where
a test had had to be weakened slightly because messages began to
get moved between slivers.
@gnprice gnprice force-pushed the pr-preserve-sliver-boundary branch from 0811136 to 5aafc03 Compare May 16, 2025 00:41
@gnprice
Copy link
Member Author

gnprice commented May 16, 2025

Just rebased past the merge of #1512. That also slightly simplifies one of these commits:
489f48a msglist [nfc]: Maintain middleItem as a field

compared with its previous revision 09758b2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants