From b8d715594e3cb4693c9111537cb66a47317943aa Mon Sep 17 00:00:00 2001 From: PhilReact Date: Thu, 5 Dec 2024 14:11:29 +0200 Subject: [PATCH] fix scrolldown when new msg --- src/components/Chat/ChatList.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/ChatList.tsx b/src/components/Chat/ChatList.tsx index 8c16c93..3cae591 100644 --- a/src/components/Chat/ChatList.tsx +++ b/src/components/Chat/ChatList.tsx @@ -37,6 +37,7 @@ export const ChatList = ({ const hasLoadedInitialRef = useRef(false); const scrollingIntervalRef = useRef(null); + const lastSeenUnreadMessageTimestamp = useRef(null); // Initialize the virtualizer @@ -108,7 +109,7 @@ export const ChatList = ({ setTimeout(() => { const hasUnreadMessages = totalMessages.some( - (msg) => msg.unread && !msg?.chatReference && !msg?.isTemp + (msg) => msg.unread && !msg?.chatReference && !msg?.isTemp && (!msg?.chatReference && msg?.timestamp > lastSeenUnreadMessageTimestamp.current || 0) ); if (parentRef.current) { const { scrollTop, scrollHeight, clientHeight } = parentRef.current; @@ -152,6 +153,7 @@ export const ChatList = ({ })) ); setShowScrollButton(false); + lastSeenUnreadMessageTimestamp.current = Date.now() }, []); const sentNewMessageGroupFunc = useCallback(() => { @@ -385,7 +387,7 @@ export const ChatList = ({ Scroll to Unread Messages )} - {showScrollDownButton && ( + {showScrollDownButton && !showScrollButton && (