Skip to content
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

message_view: Update autoscroll on message sent. #23539

Closed

Conversation

JoeyPriceless
Copy link
Collaborator

Updates the autoscroll behavior when sending a message. Will now autoscroll to the bottom of the message list if bottom of the view is visible, moving the message selection to the message at the top of the view.

Concerns message_list_view.js and message_viewport.js.

Fixes #23298

Design considerations
When designing the implementation, I had to move the code that reduces the scrolling depending on how much the compose box shrinks after being cleared. This is because it was now needed to determine whether the user had scrolled up at the beginning of the render function while taking into account the size of the written message. I was unsure whether to add an argument to is_scrolled_up() and offets_from_bottom(). Ultimately I decided to add arguments since this is the only context in which these functions are used. Please tell me if you'd like to me to handle this differently.

Screen capture:
chrome_ta3FAD4kVZ

@zulipbot
Copy link
Member

Hello @zulip/design, @zulip/server-message-view members, this pull request was labeled with the "area: message view", "UI experiment" labels, so you may want to check it out!

// Ok, we are finally ready to actually scroll.
// Find out how close we are to the bottom of the feed. The +1 is to make sure we get
// consistent behavior when composing a message right after an autoscroll.
const scroll_amount = $message_viewport.offset_from_bottom($last_visible, true) + 1;
if (scroll_amount > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always be true? Or can $message_viewport.offset_from_bottom be negative?

Copy link
Collaborator Author

@JoeyPriceless JoeyPriceless Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As specified in $message_viewport.offset_from_bottom's comment, the return value is positive if the last row is hidden. If we scroll all the way to the bottom past the last row, the return value would be negative and it would not be necessary to scroll.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so this is a check on whether the previous last message was visible or not?

Also, why is that the correct amount to scroll, then? Our previous logic based the scroll amount on the height of the new message; what's the thinking behind this calculation being correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the previous behavior had a case where it did a partial scroll if the height of the new message was smaller than the scroll_limit, with the scroll_limit being the distance between the selected message and the top of the screen.

Since we no longer care about pushing the selected message off screen, the logic can be simplified. This calculation is sufficient since the height of the new message is included in the offset_from_bottom calculation. As long as the bottom of the last message will be visible when the compose box is empty, we want to scroll to the bottom of the feed.


// Ok, we are finally ready to actually scroll.
// Find out how close we are to the bottom of the feed. The +1 is to make sure we get
// consistent behavior when composing a message right after an autoscroll.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain specifically what happens if we don't have this +1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets say we post a message that triggers the autoscroll. The view would then scroll down to the bottom of the feed. If we then instantly write another message, offset_from_bottom would return 0 since we were just moved to the bottom. The scroll would then not trigger on the second message and our newest message would be hidden from us.

I realize now that a neater solution would be to remove the +1 and use >= on L1017...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds good -- can you make that tweak?

Copy link
Collaborator Author

@JoeyPriceless JoeyPriceless Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tweak has been made. However I'm having a slightly different off-by-one problem.

After running system_initiated_animate_scroll with the value from offset_from_bottom, value returned from calling offset_from_bottom again is consistently off by about 0.1 to 1 px.

In order to address this I changed message_viewport.js's is_scrolled_up method to have an error margin of 1 px.

This seems to work well but I'm not quite sure why the scroll method doesn't actually go all the way down. Do you have any thoughts on this?

@timabbott timabbott added the product review Added by maintainers when a PR needs product review. label Nov 16, 2022
@JoeyPriceless JoeyPriceless force-pushed the scroll_to_sent_message branch from 49fb9f5 to 1c66aa0 Compare December 5, 2022 15:36
@JoeyPriceless
Copy link
Collaborator Author

@timabbott Thanks for the review and sorry for the late response on my part.

I've updated the commit to address your comments. I also removed the return value of _maybe_autoscroll since it is no longer necessary.

@alya
Copy link
Contributor

alya commented Dec 8, 2022

Sorry this got lost! There was no comment tagging me, so I was not aware that my review was the next step on this PR.

@alya
Copy link
Contributor

alya commented Dec 8, 2022

It's a bit hard to figure out how to test, but I was able to generate an example where the feed scrolled correctly when I sent a message, and the blue box moved down.

@alya
Copy link
Contributor

alya commented Dec 8, 2022

Anyway, I think we could try this on CZO. This issue was reported again today, and I'd love to see an improvement here.

I'm wondering if we'll actually want to be more aggressive with scrolling, and do so any time the bottom message in the feed is at least partially in view, rather than requiring the bottom of the feed to be visible. But we can start with this.

@timabbott tagging for another look from you / CZO deployment if/when it's ready.

@alya alya added chat.zulip.org review Added by maintainers when a PR requires chat.zulip.org testing to proceed. and removed product review Added by maintainers when a PR needs product review. labels Dec 8, 2022
@alya
Copy link
Contributor

alya commented Feb 24, 2023

@JoeyPriceless Would you be up for getting this PR rebased?

@alya
Copy link
Contributor

alya commented Mar 1, 2023

@amanagr Would you be up for doing a rebase? We just got another bump on #8021, and I'd love to get this tested.

@amanagr amanagr force-pushed the scroll_to_sent_message branch from 1c66aa0 to d75c606 Compare March 2, 2023 13:38
@amanagr amanagr force-pushed the scroll_to_sent_message branch from d75c606 to 41ead8b Compare March 2, 2023 14:13
E-Ledere added a commit to E-Ledere/zulip that referenced this pull request Mar 30, 2023
@bkraul
Copy link

bkraul commented May 13, 2023

Is there any hope of getting this PR merged? This is a much needed feature.

@alya alya added the post release Issues to focus attention on after the current major release label May 19, 2023
@alya
Copy link
Contributor

alya commented May 19, 2023

@timabbott Let's get this tested soon after the release. The current behavior has been regularly bugging me as well.

@bawachhe
Copy link

some folks on our team are also hoping for this feature. as you mentioned, @alya, you wanted this to get tested "soon after the release". I'm assuming you mean release 7.0, which as of this post is 1 month old; furthermore there's a 7.1 release 2 weeks old, now, which apparently still doesn't have this feature in it, going by the "open" status.

I understand product dev, and QA in particular, is a big process. Just wondering if this is still something you're eyeing as part of that process or if it got kinda forgotten again.

Updates the autoscroll behavior when sending a message. Will now
autoscroll to the bottom of the message list if bottom of the view is
visible, moving the message selection to the message at the top of
the view.

Concerns message_list_view.js and message_viewport.js.

Fixes zulip#23298
@shameondev shameondev force-pushed the scroll_to_sent_message branch from 41ead8b to 433db9a Compare June 29, 2023 10:12
@shameondev
Copy link
Member

Hey @timabbott, I've added this PR to your "integration review" list. If I'm getting it right, we'd like to give it some time to settle in CZO after the release.

@shameondev shameondev added the integration review Added by maintainers when a PR may be ready for integration. label Jun 29, 2023
@timabbott timabbott force-pushed the main branch 2 times, most recently from 4ec3636 to 88b200c Compare August 18, 2023 23:51
@zulipbot
Copy link
Member

zulipbot commented Oct 3, 2023

Heads up @JoeyPriceless, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

@ajonesw
Copy link

ajonesw commented Jan 29, 2024

looking forward to this issue being fixed — we have just started using Zulip as a Slack alternative and are all finding that you have to click scroll after sending a message really difficult to get past 🤞

@alya alya added completion candidate PRs with reviews that may unblock merging and removed post release Issues to focus attention on after the current major release integration review Added by maintainers when a PR may be ready for integration. chat.zulip.org review Added by maintainers when a PR requires chat.zulip.org testing to proceed. labels Feb 1, 2024
@timabbott
Copy link
Member

Closing as this effort was finally integrated via #29398; thanks for the work on this @JoeyPriceless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scroll to sent message when bottom of the screen is in view
8 participants