Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 7 additions & 3 deletions packages/react/src/views/ChatBody/ChatBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ const ChatBody = ({
};

useEffect(() => {
if (messageListRef.current) {
messageListRef.current.scrollTop = messageListRef.current.scrollHeight;
const lastMessage = messages[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain this change ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scroll to the bottom only if the last message is not about pinning. When you pin a message, A new message is sent to chat about the pinning. Need to ignore it and not scroll down to it.
image

if (
lastMessage &&
lastMessage.t !== "message_pinned"
) {
scrollToBottom();
}
}, [messages]);
}, [messages.length]);

useEffect(() => {
checkOverflow();
Expand Down
16 changes: 15 additions & 1 deletion packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ const ChatHeader = ({

const closeThread = useMessageStore((state) => state.closeThread);

const handleCloseThread = useCallback(() => {
const threadMessageId = threadMainMessage?._id;
closeThread();
setTimeout(() => {
const element = document.getElementById(`ec-message-body-${threadMessageId}`);
if (element) {
element.scrollIntoView({
behavior: 'instant',
block: 'start',
});
}
}, 300);
}, [closeThread, threadMainMessage]);

const setShowMembers = useMemberStore((state) => state.setShowMembers);
const setShowSearch = useSearchMessageStore((state) => state.setShowSearch);
const setShowPinned = usePinnedMessageStore((state) => state.setShowPinned);
Expand Down Expand Up @@ -430,7 +444,7 @@ const ChatHeader = ({
{isThreadOpen && (
<DynamicHeader
title={threadMainMessage}
handleClose={closeThread}
handleClose={handleCloseThread}
iconName="arrow-back"
/>
)}
Expand Down
Loading