Merged in feature/IO-3048-Fix-Job-Bug-Messaging (pull request #1987)
feature/IO-3048-Fix-Job-Bug-Messaging - Do not allow more than 1 of the same job to be associated with a conversation
This commit is contained in:
@@ -353,22 +353,26 @@ export const registerMessagingHandlers = ({ socket, client }) => {
|
|||||||
id: client.cache.identify({ __typename: "conversations", id: conversationId }),
|
id: client.cache.identify({ __typename: "conversations", id: conversationId }),
|
||||||
fields: {
|
fields: {
|
||||||
job_conversations: (existing = []) => {
|
job_conversations: (existing = []) => {
|
||||||
// Ensure no duplicates based on `jobid`
|
// Ensure no duplicates based on both `conversationid` and `jobid`
|
||||||
const existingIds = new Set(
|
const existingLinks = new Set(
|
||||||
existing.map(
|
existing.map((jc) => {
|
||||||
(jc) =>
|
const jobId = client.cache.readFragment({
|
||||||
client.cache.readFragment({
|
id: client.cache.identify(jc),
|
||||||
id: client.cache.identify(jc),
|
fragment: gql`
|
||||||
fragment: gql`
|
fragment JobConversationLink on job_conversations {
|
||||||
fragment JobConversationId on job_conversations {
|
jobid
|
||||||
jobid
|
conversationid
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
})?.jobid
|
})?.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];
|
return [...existing, ...newItems];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user