do not send mention and document published emails to one user

This commit is contained in:
Tom Moor
2023-03-06 19:28:12 -05:00
parent aaf6a0cb41
commit 5c12f52c8d

View File

@@ -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);