diff --git a/desktop/src/features/channels/useUnreadChannels.ts b/desktop/src/features/channels/useUnreadChannels.ts index e08f6ffa4b..5d4bc0ac1d 100644 --- a/desktop/src/features/channels/useUnreadChannels.ts +++ b/desktop/src/features/channels/useUnreadChannels.ts @@ -1,7 +1,10 @@ import * as React from "react"; import { useQueryClient } from "@tanstack/react-query"; -import { updateChannelLastMessageAt } from "@/features/channels/hooks"; +import { + channelsQueryKey, + updateChannelLastMessageAt, +} from "@/features/channels/hooks"; import { getChannelIdFromTags } from "@/features/messages/lib/threading"; import { mergeTimelineCacheMessages } from "@/features/messages/hooks"; import { relayClient } from "@/shared/api/relayClient"; @@ -180,11 +183,12 @@ export function useUnreadChannels( const handleIncomingMessage = React.useEffectEvent((event: RelayEvent) => { const channelId = getChannelIdFromTags(event.tags); - if ( - !channelId || - channelId === activeChannelId || - !liveChannelIds.has(channelId) - ) { + if (!channelId || channelId === activeChannelId) { + return; + } + + if (!liveChannelIds.has(channelId)) { + void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); return; } @@ -203,6 +207,12 @@ export function useUnreadChannels( ); }); + React.useEffect(() => { + return relayClient.subscribeToReconnects(() => { + void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); + }); + }, [queryClient]); + React.useEffect(() => { if (liveChannelIds.size === 0) { return;