Add notifications for document and collection access (#6460)

* Add notification for added to document

* Add notifications for document and collection access

* Add notification delay

* fix: Collection notifications not appearing

* Add notification settings
This commit is contained in:
Tom Moor
2024-01-31 15:01:27 -08:00
committed by GitHub
parent 5ce8827a8c
commit 47d168a29b
18 changed files with 437 additions and 31 deletions

View File

@@ -1,9 +1,11 @@
import { NotificationEventType } from "@shared/types";
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 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 { Event, NotificationEvent } from "@server/types";
import BaseProcessor from "./BaseProcessor";
@@ -23,6 +25,10 @@ export default class EmailsProcessor extends BaseProcessor {
const notificationId = notification.id;
if (notification.user.isSuspended) {
return;
}
switch (notification.event) {
case NotificationEventType.UpdateDocument:
case NotificationEventType.PublishDocument: {
@@ -41,6 +47,34 @@ export default class EmailsProcessor extends BaseProcessor {
return;
}
case NotificationEventType.AddUserToDocument: {
await new DocumentSharedEmail(
{
to: notification.user.email,
userId: notification.userId,
documentId: notification.documentId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule();
return;
}
case NotificationEventType.AddUserToCollection: {
await new CollectionSharedEmail(
{
to: notification.user.email,
userId: notification.userId,
collectionId: notification.collectionId,
teamUrl: notification.team.url,
actorName: notification.actor.name,
},
{ notificationId }
).schedule();
return;
}
case NotificationEventType.MentionedInDocument: {
await new DocumentMentionedEmail(
{