hotfix/IO-3128-Unread-Messages-Not-Updating - Initial fix just to make sure clients see messages, will poll and update every 60 seconds if the chat window is closed and has never been opened.
This commit is contained in:
@@ -42,8 +42,7 @@ export function ChatPopupComponent({ chatVisible, selectedConversation, toggleCh
|
|||||||
const { data: unreadData } = useQuery(UNREAD_CONVERSATION_COUNT, {
|
const { data: unreadData } = useQuery(UNREAD_CONVERSATION_COUNT, {
|
||||||
fetchPolicy: "network-only",
|
fetchPolicy: "network-only",
|
||||||
nextFetchPolicy: "network-only",
|
nextFetchPolicy: "network-only",
|
||||||
skip: chatVisible, // Skip when chat is visible
|
pollInterval: 60 * 1000 // TODO: This is a fix for now, should be coming from sockets
|
||||||
...(pollInterval > 0 ? { pollInterval } : {})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Socket connection status
|
// Socket connection status
|
||||||
@@ -85,14 +84,15 @@ export function ChatPopupComponent({ chatVisible, selectedConversation, toggleCh
|
|||||||
|
|
||||||
// Get unread count from the cache
|
// Get unread count from the cache
|
||||||
const unreadCount = (() => {
|
const unreadCount = (() => {
|
||||||
if (chatVisible) {
|
|
||||||
try {
|
try {
|
||||||
const cachedData = client.readQuery({
|
const cachedData = client.readQuery({
|
||||||
query: CONVERSATION_LIST_QUERY,
|
query: CONVERSATION_LIST_QUERY,
|
||||||
variables: { offset: 0 }
|
variables: { offset: 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!cachedData?.conversations) return 0;
|
if (!cachedData?.conversations) {
|
||||||
|
return unreadData?.messages_aggregate?.aggregate?.count;
|
||||||
|
}
|
||||||
|
|
||||||
// Aggregate unread message count
|
// Aggregate unread message count
|
||||||
return cachedData.conversations.reduce((total, conversation) => {
|
return cachedData.conversations.reduce((total, conversation) => {
|
||||||
@@ -103,11 +103,6 @@ export function ChatPopupComponent({ chatVisible, selectedConversation, toggleCh
|
|||||||
console.warn("Unread count not found in cache:", error);
|
console.warn("Unread count not found in cache:", error);
|
||||||
return 0; // Fallback if not in cache
|
return 0; // Fallback if not in cache
|
||||||
}
|
}
|
||||||
} else if (unreadData?.messages_aggregate?.aggregate?.count) {
|
|
||||||
// Use the unread count from the query result
|
|
||||||
return unreadData.messages_aggregate.aggregate.count;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user