From 2af5f0a22d48ffa29ddca3eb7032f1da4dc9429a Mon Sep 17 00:00:00 2001 From: MartinCupela <32706194+MartinCupela@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:35:36 +0100 Subject: [PATCH] fix: show unread messages indicators for target channel only (#2597) --- src/components/MessageList/hooks/useMarkRead.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/MessageList/hooks/useMarkRead.ts b/src/components/MessageList/hooks/useMarkRead.ts index 311f64fc3..06a1bcf18 100644 --- a/src/components/MessageList/hooks/useMarkRead.ts +++ b/src/components/MessageList/hooks/useMarkRead.ts @@ -35,7 +35,7 @@ export const useMarkRead = < }: UseMarkReadParams) => { const { client } = useChatContext('useMarkRead'); const { markRead, setChannelUnreadUiState } = useChannelActionContext('useMarkRead'); - const { channel } = useChannelStateContext('useMarkRead'); + const { channel } = useChannelStateContext('useMarkRead'); const previousRenderMessageListScrolledToBottom = useRef(isMessageListScrolledToBottom); useEffect(() => { @@ -51,7 +51,6 @@ export const useMarkRead = < }; const handleMessageNew = (event: Event) => { - const newMessageToCurrentChannel = event.cid === channel.cid; const isOwnMessage = event.user?.id && event.user.id === client.user?.id; const mainChannelUpdated = !event.message?.parent_id || event.message?.show_in_channel; if (isOwnMessage) return; @@ -72,16 +71,12 @@ export const useMarkRead = < unread_messages: previousUnreadCount + 1, }; }); - } else if ( - newMessageToCurrentChannel && - mainChannelUpdated && - shouldMarkRead(channel.countUnread()) - ) { + } else if (mainChannelUpdated && shouldMarkRead(channel.countUnread())) { markRead(); } }; - client.on('message.new', handleMessageNew); + channel.on('message.new', handleMessageNew); document.addEventListener('visibilitychange', onVisibilityChange); const hasScrolledToBottom = @@ -92,7 +87,7 @@ export const useMarkRead = < previousRenderMessageListScrolledToBottom.current = isMessageListScrolledToBottom; return () => { - client.off('message.new', handleMessageNew); + channel.off('message.new', handleMessageNew); document.removeEventListener('visibilitychange', onVisibilityChange); }; }, [