diff --git a/app/components/SocketProvider.tsx b/app/components/SocketProvider.tsx index 20feff2a2..bb983ef38 100644 --- a/app/components/SocketProvider.tsx +++ b/app/components/SocketProvider.tsx @@ -134,17 +134,6 @@ class SocketProvider extends React.Component { let document = documents.get(documentId); const previousTitle = document?.title; - if (event.event === "documents.delete") { - const document = documents.get(documentId); - - if (document) { - document.deletedAt = documentDescriptor.updatedAt; - } - - policies.remove(documentId); - continue; - } - // if we already have the latest version (it was us that performed // the change) then we don't need to update anything either. if (document?.updatedAt === documentDescriptor.updatedAt) { @@ -246,6 +235,16 @@ class SocketProvider extends React.Component { } }); + this.socket.on("documents.delete", (event: WebsocketEntityDeletedEvent) => { + const document = documents.get(event.modelId); + + if (document) { + document.deletedAt = new Date().toISOString(); + } + + policies.remove(event.modelId); + }); + this.socket.on("groups.delete", (event: WebsocketEntityDeletedEvent) => { groups.remove(event.modelId); }); diff --git a/server/queues/processors/WebsocketsProcessor.ts b/server/queues/processors/WebsocketsProcessor.ts index 1e2cf14aa..726a80037 100644 --- a/server/queues/processors/WebsocketsProcessor.ts +++ b/server/queues/processors/WebsocketsProcessor.ts @@ -59,28 +59,20 @@ export default class WebsocketsProcessor { return; } - if (!document.publishedAt) { - return socketio.to(`user-${document.createdById}`).emit("entities", { - event: event.name, - documentIds: [ - { - id: document.id, - updatedAt: document.updatedAt, - }, - ], + socketio + .to( + document.publishedAt + ? `collection-${document.collectionId}` + : `user-${document.createdById}` + ) + .emit(event.name, { + modelId: event.documentId, }); - } return socketio .to(`collection-${document.collectionId}`) .emit("entities", { event: event.name, - documentIds: [ - { - id: document.id, - updatedAt: document.updatedAt, - }, - ], collectionIds: [ { id: document.collectionId,