diff --git a/web/src/message_list_view.js b/web/src/message_list_view.js index 43a5d2b632..4cdcf01545 100644 --- a/web/src/message_list_view.js +++ b/web/src/message_list_view.js @@ -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); diff --git a/web/src/message_viewport.ts b/web/src/message_viewport.ts index ce8cb41d68..52b7861c66 100644 --- a/web/src/message_viewport.ts +++ b/web/src/message_viewport.ts @@ -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({