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:
@@ -5,10 +5,14 @@ import {
|
||||
Event,
|
||||
DocumentEvent,
|
||||
CommentEvent,
|
||||
CollectionUserEvent,
|
||||
DocumentUserEvent,
|
||||
} from "@server/types";
|
||||
import CollectionAddUserNotificationsTask from "../tasks/CollectionAddUserNotificationsTask";
|
||||
import CollectionCreatedNotificationsTask from "../tasks/CollectionCreatedNotificationsTask";
|
||||
import CommentCreatedNotificationsTask from "../tasks/CommentCreatedNotificationsTask";
|
||||
import CommentUpdatedNotificationsTask from "../tasks/CommentUpdatedNotificationsTask";
|
||||
import DocumentAddUserNotificationsTask from "../tasks/DocumentAddUserNotificationsTask";
|
||||
import DocumentPublishedNotificationsTask from "../tasks/DocumentPublishedNotificationsTask";
|
||||
import RevisionCreatedNotificationsTask from "../tasks/RevisionCreatedNotificationsTask";
|
||||
import BaseProcessor from "./BaseProcessor";
|
||||
@@ -16,8 +20,10 @@ import BaseProcessor from "./BaseProcessor";
|
||||
export default class NotificationsProcessor extends BaseProcessor {
|
||||
static applicableEvents: Event["name"][] = [
|
||||
"documents.publish",
|
||||
"documents.add_user",
|
||||
"revisions.create",
|
||||
"collections.create",
|
||||
"collections.add_user",
|
||||
"comments.create",
|
||||
"comments.update",
|
||||
];
|
||||
@@ -26,10 +32,14 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
switch (event.name) {
|
||||
case "documents.publish":
|
||||
return this.documentPublished(event);
|
||||
case "documents.add_user":
|
||||
return this.documentAddUser(event);
|
||||
case "revisions.create":
|
||||
return this.revisionCreated(event);
|
||||
case "collections.create":
|
||||
return this.collectionCreated(event);
|
||||
case "collections.add_user":
|
||||
return this.collectionAddUser(event);
|
||||
case "comments.create":
|
||||
return this.commentCreated(event);
|
||||
case "comments.update":
|
||||
@@ -51,6 +61,16 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
await DocumentPublishedNotificationsTask.schedule(event);
|
||||
}
|
||||
|
||||
async documentAddUser(event: DocumentUserEvent) {
|
||||
if (!event.data.isNew || event.userId === event.actorId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await DocumentAddUserNotificationsTask.schedule(event, {
|
||||
delay: Minute,
|
||||
});
|
||||
}
|
||||
|
||||
async revisionCreated(event: RevisionEvent) {
|
||||
await RevisionCreatedNotificationsTask.schedule(event);
|
||||
}
|
||||
@@ -68,6 +88,16 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
await CollectionCreatedNotificationsTask.schedule(event);
|
||||
}
|
||||
|
||||
async collectionAddUser(event: CollectionUserEvent) {
|
||||
if (!event.data.isNew || event.userId === event.actorId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await CollectionAddUserNotificationsTask.schedule(event, {
|
||||
delay: Minute,
|
||||
});
|
||||
}
|
||||
|
||||
async commentCreated(event: CommentEvent) {
|
||||
await CommentCreatedNotificationsTask.schedule(event, {
|
||||
delay: Minute,
|
||||
|
||||
Reference in New Issue
Block a user