From 38d1831259dea5a6eaab9acadfd2b5a880d960b3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 11 Sep 2020 11:19:30 -0700 Subject: [PATCH] fix: Send events for draft documents down user channel always --- server/services/websockets.js | 58 +++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/server/services/websockets.js b/server/services/websockets.js index df4602908..2ad97e308 100644 --- a/server/services/websockets.js +++ b/server/services/websockets.js @@ -26,22 +26,24 @@ export default class Websockets { paranoid: false, }); - return socketio - .to(`collection-${document.collectionId}`) - .emit("entities", { - event: event.name, - documentIds: [ - { - id: document.id, - updatedAt: document.updatedAt, - }, - ], - collectionIds: [ - { - id: document.collectionId, - }, - ], - }); + const channel = document.publishedAt + ? `collection-${document.collectionId}` + : `user-${event.actorId}`; + + return socketio.to(channel).emit("entities", { + event: event.name, + documentIds: [ + { + id: document.id, + updatedAt: document.updatedAt, + }, + ], + collectionIds: [ + { + id: document.collectionId, + }, + ], + }); } case "documents.delete": { const document = await Document.findByPk(event.documentId, { @@ -84,17 +86,19 @@ export default class Websockets { paranoid: false, }); - return socketio - .to(`collection-${document.collectionId}`) - .emit("entities", { - event: event.name, - documentIds: [ - { - id: document.id, - updatedAt: document.updatedAt, - }, - ], - }); + const channel = document.publishedAt + ? `collection-${document.collectionId}` + : `user-${event.actorId}`; + + return socketio.to(channel).emit("entities", { + event: event.name, + documentIds: [ + { + id: document.id, + updatedAt: document.updatedAt, + }, + ], + }); } case "documents.create": { const document = await Document.findByPk(event.documentId);