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:
@@ -152,6 +152,38 @@ export const registerMessagingHandlers = ({ socket, client }) => {
|
|||||||
return;
|
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({
|
client.cache.modify({
|
||||||
id: cacheId,
|
id: cacheId,
|
||||||
fields: {
|
fields: {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export default function ChatArchiveButton({ conversation, bodyshop }) {
|
|||||||
|
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.emit("conversation-modified", {
|
socket.emit("conversation-modified", {
|
||||||
|
type: "conversation-archived",
|
||||||
conversationId: conversation.id,
|
conversationId: conversation.id,
|
||||||
bodyshopId: bodyshop.id,
|
bodyshopId: bodyshop.id,
|
||||||
archived: updatedConversation.data.update_conversations_by_pk.archived
|
archived: updatedConversation.data.update_conversations_by_pk.archived
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default function ChatConversationComponent({
|
|||||||
}) {
|
}) {
|
||||||
const [loading, error] = subState;
|
const [loading, error] = subState;
|
||||||
|
|
||||||
|
if (conversation?.archived) return null;
|
||||||
if (loading) return <LoadingSkeleton />;
|
if (loading) return <LoadingSkeleton />;
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ const redisSocketEvents = ({
|
|||||||
const conversationModified = ({ bodyshopId, conversationId, ...fields }) => {
|
const conversationModified = ({ bodyshopId, conversationId, ...fields }) => {
|
||||||
try {
|
try {
|
||||||
// Retrieve the room name for the conversation
|
// 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
|
// Emit the updated data to all clients in the room
|
||||||
io.to(room).emit("conversation-changed", {
|
io.to(room).emit("conversation-changed", {
|
||||||
conversationId,
|
conversationId,
|
||||||
|
|||||||
Reference in New Issue
Block a user