Separate documents.delete event

This commit is contained in:
Tom Moor
2022-08-24 00:21:19 +02:00
parent 4f1277f912
commit d17e6f3432
2 changed files with 18 additions and 27 deletions

View File

@@ -134,17 +134,6 @@ class SocketProvider extends React.Component<Props> {
let document = documents.get(documentId); let document = documents.get(documentId);
const previousTitle = document?.title; 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 // if we already have the latest version (it was us that performed
// the change) then we don't need to update anything either. // the change) then we don't need to update anything either.
if (document?.updatedAt === documentDescriptor.updatedAt) { if (document?.updatedAt === documentDescriptor.updatedAt) {
@@ -246,6 +235,16 @@ class SocketProvider extends React.Component<Props> {
} }
}); });
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) => { this.socket.on("groups.delete", (event: WebsocketEntityDeletedEvent) => {
groups.remove(event.modelId); groups.remove(event.modelId);
}); });

View File

@@ -59,28 +59,20 @@ export default class WebsocketsProcessor {
return; return;
} }
if (!document.publishedAt) { socketio
return socketio.to(`user-${document.createdById}`).emit("entities", { .to(
event: event.name, document.publishedAt
documentIds: [ ? `collection-${document.collectionId}`
{ : `user-${document.createdById}`
id: document.id, )
updatedAt: document.updatedAt, .emit(event.name, {
}, modelId: event.documentId,
],
}); });
}
return socketio return socketio
.to(`collection-${document.collectionId}`) .to(`collection-${document.collectionId}`)
.emit("entities", { .emit("entities", {
event: event.name, event: event.name,
documentIds: [
{
id: document.id,
updatedAt: document.updatedAt,
},
],
collectionIds: [ collectionIds: [
{ {
id: document.collectionId, id: document.collectionId,