Files
outline/server/utils/emails.ts
Hemachandar 7f17a51e11 feat: Add email headers to enhance threading (#7477)
* feat: Add email headers to enhance threading

* tsc

* review

* change comment mentioned email subject

* paginated load

* rename util method

* add tests

* group events

* test for unsupported notification

* typo

* review
2024-09-03 17:20:56 -07:00

45 lines
1.4 KiB
TypeScript

import { NotificationEventType } from "@shared/types";
import { getBaseDomain } from "@shared/utils/domains";
const Domain = getBaseDomain();
const EmailThreadSupportedNotifications = [
NotificationEventType.PublishDocument,
NotificationEventType.UpdateDocument,
NotificationEventType.MentionedInDocument,
NotificationEventType.CreateComment,
NotificationEventType.MentionedInComment,
];
// Gmail creates a new thread for every 100 messages.
export const MaxMessagesInEmailThread = 100;
export const isEmailThreadSupportedNotification = (
event: NotificationEventType
) => EmailThreadSupportedNotifications.includes(event);
export const getEmailThreadEventGroup = (
event: NotificationEventType
): NotificationEventType[] | undefined => {
switch (event) {
case NotificationEventType.PublishDocument:
case NotificationEventType.UpdateDocument:
return [
NotificationEventType.PublishDocument,
NotificationEventType.UpdateDocument,
];
case NotificationEventType.MentionedInDocument:
case NotificationEventType.MentionedInComment:
return [
NotificationEventType.MentionedInDocument,
NotificationEventType.MentionedInComment,
];
case NotificationEventType.CreateComment:
return [NotificationEventType.CreateComment];
default:
return;
}
};
export const getEmailMessageId = (text: string) => `<${text}@${Domain}>`;