diff --git a/client/src/components/chat-popup/chat-popup.component.jsx b/client/src/components/chat-popup/chat-popup.component.jsx index 96a87885e..0226cc354 100644 --- a/client/src/components/chat-popup/chat-popup.component.jsx +++ b/client/src/components/chat-popup/chat-popup.component.jsx @@ -42,8 +42,7 @@ export function ChatPopupComponent({ chatVisible, selectedConversation, toggleCh const { data: unreadData } = useQuery(UNREAD_CONVERSATION_COUNT, { fetchPolicy: "network-only", nextFetchPolicy: "network-only", - skip: chatVisible, // Skip when chat is visible - ...(pollInterval > 0 ? { pollInterval } : {}) + pollInterval: 60 * 1000 // TODO: This is a fix for now, should be coming from sockets }); // Socket connection status @@ -85,29 +84,25 @@ export function ChatPopupComponent({ chatVisible, selectedConversation, toggleCh // Get unread count from the cache const unreadCount = (() => { - if (chatVisible) { - try { - const cachedData = client.readQuery({ - query: CONVERSATION_LIST_QUERY, - variables: { offset: 0 } - }); + try { + const cachedData = client.readQuery({ + query: CONVERSATION_LIST_QUERY, + variables: { offset: 0 } + }); - if (!cachedData?.conversations) return 0; - - // Aggregate unread message count - return cachedData.conversations.reduce((total, conversation) => { - const unread = conversation.messages_aggregate?.aggregate?.count || 0; - return total + unread; - }, 0); - } catch (error) { - console.warn("Unread count not found in cache:", error); - return 0; // Fallback if not in cache + if (!cachedData?.conversations) { + return unreadData?.messages_aggregate?.aggregate?.count; } - } else if (unreadData?.messages_aggregate?.aggregate?.count) { - // Use the unread count from the query result - return unreadData.messages_aggregate.aggregate.count; + + // Aggregate unread message count + return cachedData.conversations.reduce((total, conversation) => { + const unread = conversation.messages_aggregate?.aggregate?.count || 0; + return total + unread; + }, 0); + } catch (error) { + console.warn("Unread count not found in cache:", error); + return 0; // Fallback if not in cache } - return 0; })(); return (