diff --git a/server/commands/commentDestroyer.ts b/server/commands/commentDestroyer.ts index 125264858..305a0f1be 100644 --- a/server/commands/commentDestroyer.ts +++ b/server/commands/commentDestroyer.ts @@ -24,6 +24,8 @@ export default async function commentDestroyer({ ip, transaction, }: Props): Promise { + const document = await comment.$get("document", { transaction }); + await comment.destroy({ transaction }); // Also destroy any child comments @@ -42,6 +44,7 @@ export default async function commentDestroyer({ teamId: user.teamId, actorId: user.id, documentId: comment.documentId, + collectionId: document?.collectionId, ip, }, { transaction } diff --git a/server/queues/processors/WebsocketsProcessor.ts b/server/queues/processors/WebsocketsProcessor.ts index 593635419..bc7f0a33e 100644 --- a/server/queues/processors/WebsocketsProcessor.ts +++ b/server/queues/processors/WebsocketsProcessor.ts @@ -372,15 +372,8 @@ export default class WebsocketsProcessor { } case "comments.delete": { - const comment = await Comment.scope([ - "defaultScope", - "withDocument", - ]).findByPk(event.modelId); - if (!comment) { - return; - } return socketio - .to(`collection-${comment.document.collectionId}`) + .to(`collection-${event.collectionId}`) .emit(event.name, { modelId: event.modelId, }); diff --git a/server/types.ts b/server/types.ts index 025f11efa..b54ec5425 100644 --- a/server/types.ts +++ b/server/types.ts @@ -279,12 +279,20 @@ export type PinEvent = BaseEvent & { collectionId?: string; }; -export type CommentEvent = BaseEvent & { - name: "comments.create" | "comments.update" | "comments.delete"; - modelId: string; - documentId: string; - actorId: string; -}; +export type CommentEvent = + | (BaseEvent & { + name: "comments.create" | "comments.update"; + modelId: string; + documentId: string; + actorId: string; + }) + | (BaseEvent & { + name: "comments.delete"; + modelId: string; + documentId: string; + actorId: string; + collectionId: string; + }); export type StarEvent = BaseEvent & { name: "stars.create" | "stars.update" | "stars.delete";