message_view: For message sent by current user, always scroll into view.

Now whenever the bottom of the feed is visible, we always scroll to the
message/s just sent by the current user, updating the selected message
if necessary.

Scroll behaviour for messages sent by other users remains unchanged.

Fixes: #23298.
This commit is contained in:
N-Shar-ma 2024-03-22 03:21:36 +05:30 committed by Tim Abbott
parent a7719184ad
commit 358bb6b342
2 changed files with 20 additions and 5 deletions

View File

@ -1007,13 +1007,17 @@ export class MessageListView {
}
if (list === message_lists.current && messages_are_new) {
let sent_by_me = false;
if (messages.some((message) => message.sent_by_me)) {
sent_by_me = true;
}
if (started_scrolled_up) {
return {
need_user_to_scroll: true,
};
}
const new_messages_height = this._new_messages_height(new_dom_elements);
const need_user_to_scroll = this._maybe_autoscroll(new_messages_height);
const need_user_to_scroll = this._maybe_autoscroll(new_messages_height, sent_by_me);
if (need_user_to_scroll) {
return {
@ -1057,10 +1061,11 @@ export class MessageListView {
return scroll_limit;
}
_maybe_autoscroll(new_messages_height) {
_maybe_autoscroll(new_messages_height, sent_by_me) {
// If we are near the bottom of our feed (the bottom is visible) and can
// scroll up without moving the pointer out of the viewport, do so, by
// up to the amount taken up by the new message.
// up to the amount taken up by the new message. For messages sent by
// the current user, we scroll it into view.
//
// returns `true` if we need the user to scroll
@ -1095,6 +1100,13 @@ export class MessageListView {
return false;
}
if (sent_by_me) {
// For messages sent by the current user we always autoscroll,
// updating the selected row if needed.
message_viewport.system_initiated_animate_scroll(new_messages_height, true);
return false;
}
const info = message_viewport.message_viewport_info();
const scroll_limit = this._scroll_limit($selected_row, info);

View File

@ -358,8 +358,11 @@ export function stop_auto_scrolling(): void {
}
}
export function system_initiated_animate_scroll(scroll_amount: number): void {
message_scroll_state.set_update_selection_on_next_scroll(false);
export function system_initiated_animate_scroll(
scroll_amount: number,
update_selection_on_scroll = false,
): void {
message_scroll_state.set_update_selection_on_next_scroll(update_selection_on_scroll);
const viewport_offset = scrollTop();
in_stoppable_autoscroll = true;
$scroll_container.animate({