Skip to content

Commit 20655ab

Browse files
authored
fix: auto scroll to bottom when the message was deleted or removed from the list (#3188)
* fix: update the stream-chat version to 9.13.0 on v7 * fix: fix: auto scroll to bottom when the message was deleted or removed from the list
1 parent 2cde1db commit 20655ab

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

package/src/components/MessageList/MessageList.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,13 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
576576
]);
577577

578578
useEffect(() => {
579+
/**
580+
* Condition to check if a message is removed from MessageList.
581+
* Eg: This would happen when giphy search is cancelled, message is deleted with visibility "never" etc.
582+
* If such a case arises, we scroll to bottom.
583+
*/
584+
const isMessageRemovedFromMessageList =
585+
messageListLengthAfterUpdate < messageListLengthBeforeUpdate.current;
579586
/**
580587
* Scroll down when
581588
* created_at timestamp of top message before update is lesser than created_at timestamp of top message after update - channel has resynced
@@ -585,18 +592,10 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
585592
return;
586593
}
587594

588-
/**
589-
* Condition to check if a message is removed from MessageList.
590-
* Eg: This would happen when giphy search is cancelled, etc.
591-
* If such a case arises, we scroll to bottom.
592-
*/
593-
const isMessageRemovedFromMessageList =
594-
messageListLengthAfterUpdate < messageListLengthBeforeUpdate.current;
595595
if (
596-
isMessageRemovedFromMessageList ||
597-
(topMessageBeforeUpdate.current?.created_at &&
598-
topMessageAfterUpdate?.created_at &&
599-
topMessageBeforeUpdate.current.created_at < topMessageAfterUpdate.created_at)
596+
topMessageBeforeUpdate.current?.created_at &&
597+
topMessageAfterUpdate?.created_at &&
598+
topMessageBeforeUpdate.current.created_at < topMessageAfterUpdate.created_at
600599
) {
601600
channelResyncScrollSet.current = false;
602601
setScrollToBottomButtonVisible(false);
@@ -616,8 +615,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
616615
}
617616
};
618617

619-
// TODO: Think about if this is really needed?
620-
if (threadList) {
618+
if (threadList || isMessageRemovedFromMessageList) {
621619
scrollToBottomIfNeeded();
622620
}
623621

0 commit comments

Comments
 (0)