From 1cdd905037d7e65bef5a7156367802de2da1fbd7 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 21 Nov 2024 13:23:28 -0800 Subject: [PATCH] feature/IO-3000-messaging-sockets-migrations2 - - Checkpoint, archiving works, cannot unarchive yet Signed-off-by: Dave Richer --- .../registerMessagingSocketHandlers.js | 32 +++++++++++++++++++ .../chat-archive-button.component.jsx | 1 + .../chat-conversation.component.jsx | 1 + server/web-sockets/redisSocketEvents.js | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/client/src/components/chat-affix/registerMessagingSocketHandlers.js b/client/src/components/chat-affix/registerMessagingSocketHandlers.js index ab4473e97..325770541 100644 --- a/client/src/components/chat-affix/registerMessagingSocketHandlers.js +++ b/client/src/components/chat-affix/registerMessagingSocketHandlers.js @@ -152,6 +152,38 @@ export const registerMessagingHandlers = ({ socket, client }) => { return; } + if (type === "conversation-archived") { + // Remove all messages associated with this conversation + const messageRefs = client.cache.readFragment({ + id: cacheId, + fragment: gql` + fragment ConversationMessages on conversations { + messages { + id + } + } + ` + }); + + if (messageRefs?.messages) { + messageRefs.messages.forEach((message) => { + const messageCacheId = client.cache.identify({ + __typename: "messages", + id: message.id + }); + if (messageCacheId) { + client.cache.evict({ id: messageCacheId }); + } + }); + } + + // Evict the conversation itself + client.cache.evict({ id: cacheId }); + client.cache.gc(); // Trigger garbage collection to clean up unused entries + + return; + } + client.cache.modify({ id: cacheId, fields: { diff --git a/client/src/components/chat-archive-button/chat-archive-button.component.jsx b/client/src/components/chat-archive-button/chat-archive-button.component.jsx index f7ed348c1..2b8bcd054 100644 --- a/client/src/components/chat-archive-button/chat-archive-button.component.jsx +++ b/client/src/components/chat-archive-button/chat-archive-button.component.jsx @@ -20,6 +20,7 @@ export default function ChatArchiveButton({ conversation, bodyshop }) { if (socket) { socket.emit("conversation-modified", { + type: "conversation-archived", conversationId: conversation.id, bodyshopId: bodyshop.id, archived: updatedConversation.data.update_conversations_by_pk.archived diff --git a/client/src/components/chat-conversation/chat-conversation.component.jsx b/client/src/components/chat-conversation/chat-conversation.component.jsx index 32e52d5f2..4188fbabe 100644 --- a/client/src/components/chat-conversation/chat-conversation.component.jsx +++ b/client/src/components/chat-conversation/chat-conversation.component.jsx @@ -15,6 +15,7 @@ export default function ChatConversationComponent({ }) { const [loading, error] = subState; + if (conversation?.archived) return null; if (loading) return ; if (error) return ; diff --git a/server/web-sockets/redisSocketEvents.js b/server/web-sockets/redisSocketEvents.js index 90893a505..366461adc 100644 --- a/server/web-sockets/redisSocketEvents.js +++ b/server/web-sockets/redisSocketEvents.js @@ -174,7 +174,7 @@ const redisSocketEvents = ({ const conversationModified = ({ bodyshopId, conversationId, ...fields }) => { try { // Retrieve the room name for the conversation - const room = getBodyshopConversationRoom({ bodyshopId, conversationId }); + const room = getBodyshopRoom(bodyshopId); // Emit the updated data to all clients in the room io.to(room).emit("conversation-changed", { conversationId,