From 44721019fa3ec0b2217326a7c0dd0b23a84849e4 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 3 Dec 2024 10:39:14 -0800 Subject: [PATCH] feature/IO-3048-Fix-Job-Bug-Messaging - Do not allow more than 1 of the same job to be associated with a conversation Signed-off-by: Dave Richer --- .../registerMessagingSocketHandlers.js | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/client/src/components/chat-affix/registerMessagingSocketHandlers.js b/client/src/components/chat-affix/registerMessagingSocketHandlers.js index 41d65427d..56a2dbe70 100644 --- a/client/src/components/chat-affix/registerMessagingSocketHandlers.js +++ b/client/src/components/chat-affix/registerMessagingSocketHandlers.js @@ -353,22 +353,26 @@ export const registerMessagingHandlers = ({ socket, client }) => { id: client.cache.identify({ __typename: "conversations", id: conversationId }), fields: { job_conversations: (existing = []) => { - // Ensure no duplicates based on `jobid` - const existingIds = new Set( - existing.map( - (jc) => - client.cache.readFragment({ - id: client.cache.identify(jc), - fragment: gql` - fragment JobConversationId on job_conversations { - jobid - } - ` - })?.jobid - ) + // Ensure no duplicates based on both `conversationid` and `jobid` + const existingLinks = new Set( + existing.map((jc) => { + const jobId = client.cache.readFragment({ + id: client.cache.identify(jc), + fragment: gql` + fragment JobConversationLink on job_conversations { + jobid + conversationid + } + ` + })?.jobid; + return `${jobId}:${conversationId}`; // Unique identifier for a job-conversation link + }) ); - const newItems = formattedJobConversations.filter((jc) => !existingIds.has(jc.jobid)); + const newItems = formattedJobConversations.filter((jc) => { + const uniqueLink = `${jc.jobid}:${jc.conversationid}`; + return !existingLinks.has(uniqueLink); + }); return [...existing, ...newItems]; }