diff --git a/app/components/SocketProvider.tsx b/app/components/SocketProvider.tsx index 1f6b15796..76e3ca256 100644 --- a/app/components/SocketProvider.tsx +++ b/app/components/SocketProvider.tsx @@ -190,26 +190,8 @@ class SocketProvider extends React.Component { const collectionId = collectionDescriptor.id; const collection = collections.get(collectionId); - if (event.event === "collections.delete") { - if (collection) { - collection.deletedAt = collectionDescriptor.updatedAt; - } - - const deletedDocuments = documents.inCollection(collectionId); - deletedDocuments.forEach((doc) => { - doc.deletedAt = collectionDescriptor.updatedAt; - policies.remove(doc.id); - }); - documents.removeCollectionDocuments(collectionId); - memberships.removeCollectionMemberships(collectionId); - collections.remove(collectionId); - policies.remove(collectionId); - 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 (collection?.updatedAt === collectionDescriptor.updatedAt) { continue; } @@ -264,6 +246,24 @@ class SocketProvider extends React.Component { } }); + this.socket.on( + "collections.delete", + (event: WebsocketEntityDeletedEvent) => { + const collectionId = event.modelId; + const deletedAt = new Date().toISOString(); + + const deletedDocuments = documents.inCollection(collectionId); + deletedDocuments.forEach((doc) => { + doc.deletedAt = deletedAt; + policies.remove(doc.id); + }); + documents.removeCollectionDocuments(collectionId); + memberships.removeCollectionMemberships(collectionId); + collections.remove(collectionId); + policies.remove(collectionId); + } + ); + this.socket.on("pins.create", (event: PartialWithId) => { pins.add(event); }); diff --git a/server/queues/processors/WebsocketsProcessor.ts b/server/queues/processors/WebsocketsProcessor.ts index 0e9234245..bcf96325b 100644 --- a/server/queues/processors/WebsocketsProcessor.ts +++ b/server/queues/processors/WebsocketsProcessor.ts @@ -211,8 +211,7 @@ export default class WebsocketsProcessor { }); } - case "collections.update": - case "collections.delete": { + case "collections.update": { const collection = await Collection.findByPk(event.collectionId, { paranoid: false, }); @@ -230,6 +229,14 @@ export default class WebsocketsProcessor { }); } + case "collections.delete": { + return socketio + .to(`collection-${event.collectionId}`) + .emit(event.name, { + modelId: event.collectionId, + }); + } + case "collections.move": { return socketio .to(`collection-${event.collectionId}`)