Files
outline/server/queues/processors/EmailsProcessor.ts
Tom Moor ba7b6e88e7 fix: Translate access request emails and set email language and direction (#14147)
* fix: Allow every mention notification to be turned off and unsubscribed

- The Mentioned and Group mentions settings now control both the document and comment event types.
- Mention, share, collection invite, and access request emails now have an unsubscribe link and List-Unsubscribe header.

* fix: Translate access request emails and set email language and direction

- The access request email now uses the language of the recipient.
- Emails now set lang and dir on the HTML document, and RTL emails align content to the right.
2026-10-20 20:23:21 -04:00

235 lines
7.9 KiB
TypeScript

import { NotificationEventType } from "@shared/types";
import { Minute } from "@shared/utils/time";
import CollectionCreatedEmail from "@server/emails/templates/CollectionCreatedEmail";
import CollectionSharedEmail from "@server/emails/templates/CollectionSharedEmail";
import CommentCreatedEmail from "@server/emails/templates/CommentCreatedEmail";
import CommentMentionedEmail from "@server/emails/templates/CommentMentionedEmail";
import CommentResolvedEmail from "@server/emails/templates/CommentResolvedEmail";
import DocumentAccessRequestEmail from "@server/emails/templates/DocumentAccessRequestEmail";
import DocumentMentionedEmail from "@server/emails/templates/DocumentMentionedEmail";
import DocumentPublishedOrUpdatedEmail from "@server/emails/templates/DocumentPublishedOrUpdatedEmail";
import DocumentSharedEmail from "@server/emails/templates/DocumentSharedEmail";
import { Notification } from "@server/models";
import type { Event, NotificationEvent } from "@server/types";
import BaseProcessor from "./BaseProcessor";
import GroupDocumentMentionedEmail from "@server/emails/templates/GroupDocumentMentionedEmail";
import GroupCommentMentionedEmail from "@server/emails/templates/GroupCommentMentionedEmail";
export default class EmailsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["notifications.create"];
async perform(event: NotificationEvent) {
const notification = await Notification.scope([
"withTeam",
"withUser",
"withActor",
]).findByPk(event.modelId);
if (!notification) {
return;
}
const notificationId = notification.id;
if (notification.user.isSuspended) {
return;
}
switch (notification.event) {
case NotificationEventType.UpdateDocument:
case NotificationEventType.PublishDocument: {
// No need to delay email here as the notification itself is already delayed
await new DocumentPublishedOrUpdatedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
eventType: notification.event,
revisionId: notification.revisionId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorId: notification.actorId,
actorName: notification.actor.name,
},
{ notificationId }
).schedule();
return;
}
case NotificationEventType.AddUserToDocument: {
await new DocumentSharedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
membershipId: notification.membershipId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.AddUserToCollection: {
await new CollectionSharedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
collectionId: notification.collectionId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.GroupMentionedInDocument: {
await new GroupDocumentMentionedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
revisionId: notification.revisionId,
groupId: notification.groupId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule();
return;
}
case NotificationEventType.MentionedInDocument: {
// No need to delay email here as the notification itself is already delayed
await new DocumentMentionedEmail(
{
to: notification.user.email,
language: notification.user.language,
documentId: notification.documentId,
revisionId: notification.revisionId,
userId: notification.userId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule();
return;
}
case NotificationEventType.GroupMentionedInComment: {
await new GroupCommentMentionedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
commentId: notification.commentId,
groupId: notification.groupId,
},
{ notificationId }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.MentionedInComment: {
await new CommentMentionedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
commentId: notification.commentId,
},
{ notificationId: notification.id }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.CreateCollection: {
await new CollectionCreatedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
collectionId: notification.collectionId,
teamUrl: notification.team.url,
},
{ notificationId: notification.id }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.CreateComment: {
await new CommentCreatedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
commentId: notification.commentId,
},
{ notificationId: notification.id }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.ResolveComment: {
await new CommentResolvedEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
commentId: notification.commentId,
},
{ notificationId: notification.id }
).schedule({
delay: Minute.ms,
});
return;
}
case NotificationEventType.RequestDocumentAccess: {
await new DocumentAccessRequestEmail(
{
to: notification.user.email,
language: notification.user.language,
userId: notification.userId,
documentId: notification.documentId,
actorId: notification.actorId,
teamUrl: notification.team.url,
},
{ notificationId: notification.id }
).schedule({
delay: Minute.ms,
});
return;
}
}
}
}