From e8eb7638c459b80b68c914cc8e09c0a0ad903e5a Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:57:38 -0400 Subject: [PATCH] Scroll to bottom of conversation when message is sent --- ts/components/conversation/Timeline.tsx | 9 ++++++++- ts/models/conversations.ts | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ts/components/conversation/Timeline.tsx b/ts/components/conversation/Timeline.tsx index 0ec645ea0..c47627ef9 100644 --- a/ts/components/conversation/Timeline.tsx +++ b/ts/components/conversation/Timeline.tsx @@ -594,7 +594,14 @@ export class Timeline extends React.Component< } } - if (oldItems.length !== newItems.length) { + // We know that all items will be in order and that items can only be added at either + // end, so we can check for equality without checking each item in the array + const haveItemsChanged = + oldItems.length !== newItems.length || + oldItems.at(0) !== newItems.at(0) || + oldItems.at(-1) !== newItems.at(-1); + + if (haveItemsChanged) { this.updateIntersectionObserver(); // This condition is somewhat arbitrary. diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 1770194cf..7c965390b 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1436,7 +1436,10 @@ export class ConversationModel extends window.Backbone newestId && messageIds && messageIds[messageIds.length - 1] === newestId; if (isJustSent && existingConversation && !isLatestInMemory) { - void this.loadNewestMessages(undefined, undefined); + // The message is being sent before the user has scrolled down to load the newest + // messages into memory; in that case, we scroll the user all the way down by + // loading the newest message + drop(this.loadNewestMessages(newestId, undefined)); } else if ( // The message has to be not a story or has to be a story reply in direct // conversation.