Separate collections.delete event
This commit is contained in:
@@ -190,26 +190,8 @@ class SocketProvider extends React.Component<Props> {
|
|||||||
const collectionId = collectionDescriptor.id;
|
const collectionId = collectionDescriptor.id;
|
||||||
const collection = collections.get(collectionId);
|
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
|
// 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 (collection?.updatedAt === collectionDescriptor.updatedAt) {
|
if (collection?.updatedAt === collectionDescriptor.updatedAt) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -264,6 +246,24 @@ class SocketProvider extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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<Pin>) => {
|
this.socket.on("pins.create", (event: PartialWithId<Pin>) => {
|
||||||
pins.add(event);
|
pins.add(event);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -211,8 +211,7 @@ export default class WebsocketsProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
case "collections.update":
|
case "collections.update": {
|
||||||
case "collections.delete": {
|
|
||||||
const collection = await Collection.findByPk(event.collectionId, {
|
const collection = await Collection.findByPk(event.collectionId, {
|
||||||
paranoid: false,
|
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": {
|
case "collections.move": {
|
||||||
return socketio
|
return socketio
|
||||||
.to(`collection-${event.collectionId}`)
|
.to(`collection-${event.collectionId}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user