Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
]);

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

/**
* Condition to check if a message is removed from MessageList.
* Eg: This would happen when giphy search is cancelled, etc.
* If such a case arises, we scroll to bottom.
*/
const isMessageRemovedFromMessageList =
messageListLengthAfterUpdate < messageListLengthBeforeUpdate.current;
if (
isMessageRemovedFromMessageList ||
(topMessageBeforeUpdate.current?.created_at &&
topMessageAfterUpdate?.created_at &&
topMessageBeforeUpdate.current.created_at < topMessageAfterUpdate.created_at)
topMessageBeforeUpdate.current?.created_at &&
topMessageAfterUpdate?.created_at &&
topMessageBeforeUpdate.current.created_at < topMessageAfterUpdate.created_at
) {
channelResyncScrollSet.current = false;
setScrollToBottomButtonVisible(false);
Expand All @@ -615,8 +614,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
}
};

// TODO: Think about if this is really needed?
if (threadList) {
if (threadList || isMessageRemovedFromMessageList) {
scrollToBottomIfNeeded();
}

Expand Down