feature/IO-3000-messaging-sockets-migrations2 -

- Checkpoint, archiving works, cannot unarchive yet

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-11-21 13:23:28 -08:00
parent e734da7adc
commit 1cdd905037
4 changed files with 35 additions and 1 deletions

View File

@@ -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: {

View File

@@ -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

View File

@@ -15,6 +15,7 @@ export default function ChatConversationComponent({
}) {
const [loading, error] = subState;
if (conversation?.archived) return null;
if (loading) return <LoadingSkeleton />;
if (error) return <AlertComponent message={error.message} type="error" />;

View File

@@ -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,