diff --git a/client/src/components/chat-affix/registerMessagingSocketHandlers.js b/client/src/components/chat-affix/registerMessagingSocketHandlers.js index 56a2dbe70..f2d9d1ef9 100644 --- a/client/src/components/chat-affix/registerMessagingSocketHandlers.js +++ b/client/src/components/chat-affix/registerMessagingSocketHandlers.js @@ -359,7 +359,7 @@ export const registerMessagingHandlers = ({ socket, client }) => { const jobId = client.cache.readFragment({ id: client.cache.identify(jc), fragment: gql` - fragment JobConversationLink on job_conversations { + fragment JobConversationLinkAdded on job_conversations { jobid conversationid } @@ -382,20 +382,27 @@ export const registerMessagingHandlers = ({ socket, client }) => { break; case "tag-removed": - client.cache.modify({ - id: client.cache.identify({ __typename: "conversations", id: conversationId }), - fields: { - job_conversations: (existing = [], { readField }) => { - return existing.filter((jobRef) => { - // Read the `jobid` field safely, even if the structure is normalized - const jobId = readField("jobid", jobRef); - return jobId !== fields.jobId; - }); - } - } - }); - break; + try { + const conversationCacheId = client.cache.identify({ __typename: "conversations", id: conversationId }); + // Evict the specific cache entry for job_conversations + client.cache.evict({ + id: conversationCacheId, + fieldName: "job_conversations" + }); + + // Garbage collect evicted entries + client.cache.gc(); + + logLocal("handleConversationChanged - tag removed - Refetched conversation list after state change", { + conversationId, + type + }); + } catch (error) { + console.error("Error refetching queries after conversation state change: (Tag Removed)", error); + } + + break; default: logLocal("handleConversationChanged - Unhandled type", { type }); client.cache.modify({