diff --git a/server/emails/templates/CollectionCreatedEmail.tsx b/server/emails/templates/CollectionCreatedEmail.tsx index a8b773c6d..143b77cf1 100644 --- a/server/emails/templates/CollectionCreatedEmail.tsx +++ b/server/emails/templates/CollectionCreatedEmail.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { NotificationEventType } from "@shared/types"; -import { Collection, Notification, User } from "@server/models"; +import { Collection, User } from "@server/models"; import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import BaseEmail, { EmailProps } from "./BaseEmail"; import Body from "./components/Body"; @@ -32,20 +32,6 @@ export default class CollectionCreatedEmail extends BaseEmail< InputProps, BeforeSend > { - public constructor(notification: Notification) { - super( - { - to: notification.user.email, - userId: notification.userId, - collectionId: notification.collectionId, - teamUrl: notification.team.url, - }, - { - notificationId: notification.id, - } - ); - } - protected async beforeSend({ userId, collectionId }: Props) { const collection = await Collection.scope("withUser").findByPk( collectionId diff --git a/server/emails/templates/CommentCreatedEmail.tsx b/server/emails/templates/CommentCreatedEmail.tsx index cdffbdbe0..e7a0f99d8 100644 --- a/server/emails/templates/CommentCreatedEmail.tsx +++ b/server/emails/templates/CommentCreatedEmail.tsx @@ -3,13 +3,7 @@ import * as React from "react"; import { NotificationEventType } from "@shared/types"; import { Day } from "@shared/utils/time"; import env from "@server/env"; -import { - Collection, - Comment, - Document, - Notification, - User, -} from "@server/models"; +import { Collection, Comment, Document, User } from "@server/models"; import DocumentHelper from "@server/models/helpers/DocumentHelper"; import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper"; @@ -50,22 +44,6 @@ export default class CommentCreatedEmail extends BaseEmail< InputProps, BeforeSend > { - public constructor(notification: Notification) { - super( - { - to: notification.user.email, - userId: notification.userId, - documentId: notification.documentId, - teamUrl: notification.team.url, - actorName: notification.actor.name, - commentId: notification.commentId, - }, - { - notificationId: notification.id, - } - ); - } - protected async beforeSend({ documentId, userId, commentId }: InputProps) { const document = await Document.unscoped().findByPk(documentId); if (!document) { diff --git a/server/emails/templates/CommentMentionedEmail.tsx b/server/emails/templates/CommentMentionedEmail.tsx index 0910f74cd..10b4ac1e5 100644 --- a/server/emails/templates/CommentMentionedEmail.tsx +++ b/server/emails/templates/CommentMentionedEmail.tsx @@ -3,13 +3,7 @@ import * as React from "react"; import { NotificationEventType } from "@shared/types"; import { Day } from "@shared/utils/time"; import env from "@server/env"; -import { - Collection, - Comment, - Document, - Notification, - User, -} from "@server/models"; +import { Collection, Comment, Document, User } from "@server/models"; import DocumentHelper from "@server/models/helpers/DocumentHelper"; import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper"; @@ -48,22 +42,6 @@ export default class CommentMentionedEmail extends BaseEmail< InputProps, BeforeSend > { - public constructor(notification: Notification) { - super( - { - to: notification.user.email, - userId: notification.userId, - documentId: notification.documentId, - teamUrl: notification.team.url, - actorName: notification.actor.name, - commentId: notification.commentId, - }, - { - notificationId: notification.id, - } - ); - } - protected async beforeSend({ documentId, commentId, userId }: InputProps) { const document = await Document.unscoped().findByPk(documentId); if (!document) { diff --git a/server/emails/templates/DocumentMentionedEmail.tsx b/server/emails/templates/DocumentMentionedEmail.tsx index 766c1e715..dd5ddaab5 100644 --- a/server/emails/templates/DocumentMentionedEmail.tsx +++ b/server/emails/templates/DocumentMentionedEmail.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { Document, Notification } from "@server/models"; +import { Document } from "@server/models"; import BaseEmail, { EmailProps } from "./BaseEmail"; import Body from "./components/Body"; import Button from "./components/Button"; @@ -26,20 +26,6 @@ export default class DocumentMentionedEmail extends BaseEmail< InputProps, BeforeSend > { - public constructor(notification: Notification) { - super( - { - to: notification.user.email, - documentId: notification.documentId, - teamUrl: notification.team.url, - actorName: notification.actor.name, - }, - { - notificationId: notification.id, - } - ); - } - protected async beforeSend({ documentId }: InputProps) { const document = await Document.unscoped().findByPk(documentId); if (!document) { diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx index 485cc7145..b9bc6fd2b 100644 --- a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx +++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx @@ -3,13 +3,7 @@ import * as React from "react"; import { NotificationEventType } from "@shared/types"; import { Day } from "@shared/utils/time"; import env from "@server/env"; -import { - Document, - Collection, - User, - Revision, - Notification, -} from "@server/models"; +import { Document, Collection, User, Revision } from "@server/models"; import DocumentHelper from "@server/models/helpers/DocumentHelper"; import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import BaseEmail, { EmailProps } from "./BaseEmail"; @@ -50,25 +44,6 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< InputProps, BeforeSend > { - public constructor(notification: Notification) { - super( - { - to: notification.user.email, - userId: notification.userId, - eventType: notification.event as - | NotificationEventType.PublishDocument - | NotificationEventType.UpdateDocument, - revisionId: notification.revisionId, - documentId: notification.documentId, - teamUrl: notification.team.url, - actorName: notification.actor.name, - }, - { - notificationId: notification.id, - } - ); - } - protected async beforeSend({ documentId, revisionId, diff --git a/server/queues/processors/EmailsProcessor.ts b/server/queues/processors/EmailsProcessor.ts index f30713610..dffdce5f5 100644 --- a/server/queues/processors/EmailsProcessor.ts +++ b/server/queues/processors/EmailsProcessor.ts @@ -21,30 +21,79 @@ export default class NotificationsProcessor extends BaseProcessor { return; } + const notificationId = notification.id; + switch (notification.event) { case NotificationEventType.UpdateDocument: case NotificationEventType.PublishDocument: { - await new DocumentPublishedOrUpdatedEmail(notification).schedule(); + await new DocumentPublishedOrUpdatedEmail( + { + to: notification.user.email, + userId: notification.userId, + eventType: notification.event, + revisionId: notification.revisionId, + documentId: notification.documentId, + teamUrl: notification.team.url, + actorName: notification.actor.name, + }, + { notificationId } + ).schedule(); return; } case NotificationEventType.MentionedInDocument: { - await new DocumentMentionedEmail(notification).schedule(); + await new DocumentMentionedEmail( + { + to: notification.user.email, + documentId: notification.documentId, + teamUrl: notification.team.url, + actorName: notification.actor.name, + }, + { notificationId } + ).schedule(); return; } case NotificationEventType.MentionedInComment: { - await new CommentMentionedEmail(notification).schedule(); + await new CommentMentionedEmail( + { + to: notification.user.email, + userId: notification.userId, + documentId: notification.documentId, + teamUrl: notification.team.url, + actorName: notification.actor.name, + commentId: notification.commentId, + }, + { notificationId: notification.id } + ).schedule(); return; } case NotificationEventType.CreateCollection: { - await new CollectionCreatedEmail(notification).schedule(); + await new CollectionCreatedEmail( + { + to: notification.user.email, + userId: notification.userId, + collectionId: notification.collectionId, + teamUrl: notification.team.url, + }, + { notificationId: notification.id } + ).schedule(); return; } case NotificationEventType.CreateComment: { - await new CommentCreatedEmail(notification).schedule(); + await new CommentCreatedEmail( + { + to: notification.user.email, + userId: notification.userId, + documentId: notification.documentId, + teamUrl: notification.team.url, + actorName: notification.actor.name, + commentId: notification.commentId, + }, + { notificationId: notification.id } + ).schedule(); } } }