From 5a58a65106d963cd95d3d2df31afe2459b2b902e Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Tue, 19 Nov 2024 18:31:21 +0100 Subject: [PATCH] fix: listen to correct channel read events --- .../ChannelPreview/hooks/useChannelPreviewData.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts b/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts index 8b35a1685..a678e7042 100644 --- a/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts +++ b/package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts @@ -30,6 +30,13 @@ export const useChannelPreviewData = < const channelLastMessage = channel.lastMessage(); const channelLastMessageString = `${channelLastMessage?.id}${channelLastMessage?.updated_at}`; + useEffect(() => { + const { unsubscribe } = client.on('notification.mark_read', () => { + setUnread(channel.countUnread()); + }); + return unsubscribe; + }, [channel, client]); + useEffect(() => { if ( channelLastMessage && @@ -56,7 +63,7 @@ export const useChannelPreviewData = < setForceUpdate((prev) => prev + 1); } }; - const { unsubscribe } = client.on('notification.mark_read', handleReadEvent); + const { unsubscribe } = client.on('message.read', handleReadEvent); return unsubscribe; }, [client, channel]);