Initial
This commit is contained in:
@@ -267,7 +267,17 @@ export const registerMessagingHandlers = ({ socket, client, currentUser, bodysho
|
||||
return;
|
||||
}
|
||||
|
||||
const { conversationId, type, job_conversations, messageIds, ...fields } = data;
|
||||
const {
|
||||
conversationId,
|
||||
type,
|
||||
job_conversations,
|
||||
messageIds, // used by "conversation-marked-read"
|
||||
messageIdsMarkedRead, // used by "conversation-marked-unread"
|
||||
lastUnreadMessageId, // used by "conversation-marked-unread"
|
||||
unreadCount, // used by "conversation-marked-unread"
|
||||
...fields
|
||||
} = data;
|
||||
|
||||
logLocal("handleConversationChanged - Start", data);
|
||||
|
||||
const updatedAt = new Date().toISOString();
|
||||
@@ -313,15 +323,65 @@ export const registerMessagingHandlers = ({ socket, client, currentUser, bodysho
|
||||
return message;
|
||||
});
|
||||
},
|
||||
// Keep unread badge in sync (badge uses messages_aggregate.aggregate.count)
|
||||
messages_aggregate: () => ({
|
||||
__typename: "messages_aggregate",
|
||||
aggregate: { __typename: "messages_aggregate_fields", count: 0 }
|
||||
})
|
||||
}),
|
||||
unreadcnt: () => 0
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case "conversation-marked-unread": {
|
||||
if (!conversationId) break;
|
||||
|
||||
const safeUnreadCount = typeof unreadCount === "number" ? unreadCount : 1;
|
||||
const idsMarkedRead = Array.isArray(messageIdsMarkedRead) ? messageIdsMarkedRead : [];
|
||||
|
||||
client.cache.modify({
|
||||
id: client.cache.identify({ __typename: "conversations", id: conversationId }),
|
||||
fields: {
|
||||
// Bubble the conversation up in the list (since UI sorts by updated_at)
|
||||
updated_at: () => updatedAt,
|
||||
|
||||
// If details are already cached, flip the read flags appropriately
|
||||
messages(existingMessages = [], { readField }) {
|
||||
if (!Array.isArray(existingMessages) || existingMessages.length === 0) return existingMessages;
|
||||
|
||||
return existingMessages.map((msg) => {
|
||||
const id = readField("id", msg);
|
||||
|
||||
if (lastUnreadMessageId && id === lastUnreadMessageId) {
|
||||
return { ...msg, read: false };
|
||||
}
|
||||
|
||||
if (idsMarkedRead.includes(id)) {
|
||||
return { ...msg, read: true };
|
||||
}
|
||||
|
||||
return msg;
|
||||
});
|
||||
},
|
||||
|
||||
// Update unread badge
|
||||
messages_aggregate: () => ({
|
||||
__typename: "messages_aggregate",
|
||||
aggregate: {
|
||||
__typename: "messages_aggregate_fields",
|
||||
count: safeUnreadCount
|
||||
}
|
||||
}),
|
||||
|
||||
// Optional: keep legacy/parallel unread field consistent if present
|
||||
unreadcnt: () => safeUnreadCount
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "conversation-created":
|
||||
updateConversationList({ ...fields, job_conversations, updated_at: updatedAt });
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user