From 5c12f52c8da5a60d89b479cb8f299af87e60fae3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 6 Mar 2023 19:28:12 -0500 Subject: [PATCH] do not send mention and document published emails to one user --- .../processors/NotificationsProcessor.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/server/queues/processors/NotificationsProcessor.ts b/server/queues/processors/NotificationsProcessor.ts index ca277eec5..db58d7ad2 100644 --- a/server/queues/processors/NotificationsProcessor.ts +++ b/server/queues/processors/NotificationsProcessor.ts @@ -81,15 +81,10 @@ export default class NotificationsProcessor extends BaseProcessor { await this.createDocumentSubscriptions(document, event); - const recipients = await NotificationHelper.getDocumentNotificationRecipients( - document, - "documents.publish", - document.lastModifiedById, - false - ); - - // send notifs to mentioned users + // Send notifications to mentioned users first const mentions = parseMentions(document); + const userIdsSentNotifications: string[] = []; + for (const mention of mentions) { const [recipient, actor] = await Promise.all([ User.findByPk(mention.modelId), @@ -103,6 +98,7 @@ export default class NotificationsProcessor extends BaseProcessor { teamId: team.id, documentId: document.id, }); + userIdsSentNotifications.push(recipient.id); await MentionNotificationEmail.schedule( { to: recipient.email, @@ -116,6 +112,17 @@ export default class NotificationsProcessor extends BaseProcessor { } } + const recipients = ( + await NotificationHelper.getDocumentNotificationRecipients( + document, + "documents.publish", + document.lastModifiedById, + false + ) + ).filter( + (recipient) => !userIdsSentNotifications.includes(recipient.userId) + ); + for (const recipient of recipients) { const notify = await this.shouldNotify(document, recipient.user);