Files
outline/server/queues/tasks/CollectionAddUserNotificationsTask.ts
Tom Moor 47d168a29b 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
2024-01-31 15:01:27 -08:00

33 lines
933 B
TypeScript

import { NotificationEventType } from "@shared/types";
import { Notification, User } from "@server/models";
import { CollectionUserEvent } from "@server/types";
import BaseTask, { TaskPriority } from "./BaseTask";
export default class CollectionAddUserNotificationsTask extends BaseTask<CollectionUserEvent> {
public async perform(event: CollectionUserEvent) {
const recipient = await User.findByPk(event.userId);
if (!recipient) {
return;
}
if (
!recipient.isSuspended &&
recipient.subscribedToEventType(NotificationEventType.AddUserToCollection)
) {
await Notification.create({
event: NotificationEventType.AddUserToCollection,
userId: event.userId,
actorId: event.actorId,
teamId: event.teamId,
collectionId: event.collectionId,
});
}
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}