fix: Email notifications not sent when mention added to edited comment (#5145
* WIP: Need new email template * New emails
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { NotificationEventType } from "@shared/types";
|
||||
import DocumentNotificationEmail from "@server/emails/templates/DocumentNotificationEmail";
|
||||
import DocumentPublishedOrUpdatedEmail from "@server/emails/templates/DocumentPublishedOrUpdatedEmail";
|
||||
import {
|
||||
View,
|
||||
Subscription,
|
||||
@@ -26,7 +26,7 @@ beforeEach(async () => {
|
||||
describe("documents.publish", () => {
|
||||
test("should not send a notification to author", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("documents.publish", () => {
|
||||
|
||||
test("should send a notification to other users in team", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const user = await buildUser();
|
||||
@@ -82,7 +82,7 @@ describe("documents.publish", () => {
|
||||
|
||||
test("should send only one notification in a 12-hour window", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const user = await buildUser();
|
||||
@@ -125,7 +125,7 @@ describe("documents.publish", () => {
|
||||
|
||||
test("should not send a notification to users without collection access", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const user = await buildUser();
|
||||
@@ -159,7 +159,7 @@ describe("documents.publish", () => {
|
||||
describe("revisions.create", () => {
|
||||
test("should send a notification to other collaborators", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -187,7 +187,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification if viewed since update", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -219,7 +219,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification to last editor", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const user = await buildUser();
|
||||
@@ -247,7 +247,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should send a notification for subscriptions, even to collaborator", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -331,7 +331,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send multiple emails", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const collaborator0 = await buildUser();
|
||||
@@ -382,7 +382,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not create subscriptions if previously unsubscribed", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const collaborator0 = await buildUser();
|
||||
@@ -445,7 +445,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should send a notification for subscriptions to non-collaborators", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -487,7 +487,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification for subscriptions to collaborators if unsubscribed", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -532,7 +532,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification for subscriptions to members outside of the team", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -580,7 +580,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification if viewed since update", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const document = await buildDocument();
|
||||
@@ -610,7 +610,7 @@ describe("revisions.create", () => {
|
||||
|
||||
test("should not send a notification to last editor", async () => {
|
||||
const schedule = jest.spyOn(
|
||||
DocumentNotificationEmail.prototype,
|
||||
DocumentPublishedOrUpdatedEmail.prototype,
|
||||
"schedule"
|
||||
);
|
||||
const user = await buildUser();
|
||||
|
||||
@@ -6,8 +6,8 @@ import { Minute } from "@shared/utils/time";
|
||||
import subscriptionCreator from "@server/commands/subscriptionCreator";
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import CollectionCreatedEmail from "@server/emails/templates/CollectionCreatedEmail";
|
||||
import DocumentNotificationEmail from "@server/emails/templates/DocumentNotificationEmail";
|
||||
import MentionNotificationEmail from "@server/emails/templates/MentionNotificationEmail";
|
||||
import DocumentMentionedEmail from "@server/emails/templates/DocumentMentionedEmail";
|
||||
import DocumentPublishedOrUpdatedEmail from "@server/emails/templates/DocumentPublishedOrUpdatedEmail";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import {
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
CommentEvent,
|
||||
} from "@server/types";
|
||||
import CommentCreatedNotificationTask from "../tasks/CommentCreatedNotificationTask";
|
||||
import CommentUpdatedNotificationTask from "../tasks/CommentUpdatedNotificationTask";
|
||||
import BaseProcessor from "./BaseProcessor";
|
||||
|
||||
export default class NotificationsProcessor extends BaseProcessor {
|
||||
@@ -37,6 +38,7 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
"revisions.create",
|
||||
"collections.create",
|
||||
"comments.create",
|
||||
"comments.update",
|
||||
];
|
||||
|
||||
async perform(event: Event) {
|
||||
@@ -49,6 +51,8 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
return this.collectionCreated(event);
|
||||
case "comments.create":
|
||||
return this.commentCreated(event);
|
||||
case "comments.update":
|
||||
return this.commentUpdated(event);
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -59,6 +63,12 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
async commentUpdated(event: CommentEvent) {
|
||||
await CommentUpdatedNotificationTask.schedule(event, {
|
||||
delay: Minute,
|
||||
});
|
||||
}
|
||||
|
||||
async documentPublished(event: DocumentEvent) {
|
||||
// never send notifications when batch importing documents
|
||||
if (
|
||||
@@ -104,7 +114,7 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
documentId: document.id,
|
||||
});
|
||||
userIdsSentNotifications.push(recipient.id);
|
||||
await new MentionNotificationEmail(
|
||||
await new DocumentMentionedEmail(
|
||||
{
|
||||
to: recipient.email,
|
||||
documentId: event.documentId,
|
||||
@@ -137,7 +147,7 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
teamId: team.id,
|
||||
documentId: document.id,
|
||||
});
|
||||
await new DocumentNotificationEmail(
|
||||
await new DocumentPublishedOrUpdatedEmail(
|
||||
{
|
||||
to: recipient.email,
|
||||
userId: recipient.id,
|
||||
@@ -193,7 +203,7 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
documentId: document.id,
|
||||
});
|
||||
userIdsSentNotifications.push(recipient.id);
|
||||
await new MentionNotificationEmail(
|
||||
await new DocumentMentionedEmail(
|
||||
{
|
||||
to: recipient.email,
|
||||
documentId: event.documentId,
|
||||
@@ -241,7 +251,7 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
documentId: document.id,
|
||||
});
|
||||
|
||||
await new DocumentNotificationEmail(
|
||||
await new DocumentPublishedOrUpdatedEmail(
|
||||
{
|
||||
to: recipient.email,
|
||||
userId: recipient.id,
|
||||
|
||||
Reference in New Issue
Block a user