Files
outline/server/queues/tasks/ReactionRemovedNotificationsTask.ts
codegen-sh[bot]andTom Moor 4fc6ac1f15 Add in-app reaction notifications (#9893)
* Add ReactionsCreate notification event type

- Add ReactionsCreate to NotificationEventType enum and defaults
- Add notification settings UI with SmileyIcon and proper labels
- Create ReactionsCreateNotificationsTask to handle comment reactions
- Update NotificationsProcessor to handle comments.add_reaction events
- Add eventText and path handling in client Notification model
- Notifications are enabled by default but never send emails

* Applied automatic fixes

* Show the actual emoji in the notification

* Cleanup notifications if reaction is removed

* PR feedback

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
2025-08-11 18:54:43 -04:00

60 lines
1.6 KiB
TypeScript

import { NotificationEventType } from "@shared/types";
import { Notification, User } from "@server/models";
import { CommentReactionEvent } from "@server/types";
import BaseTask, { TaskPriority } from "./BaseTask";
import { createContext } from "@server/context";
import { sequelize } from "@server/storage/database";
import { Op } from "sequelize";
export default class ReactionRemovedNotificationsTask extends BaseTask<CommentReactionEvent> {
public async perform(event: CommentReactionEvent) {
const { emoji } = event.data;
if (event.name !== "comments.remove_reaction") {
return;
}
await sequelize.transaction(async (transaction) => {
const user = await User.findByPk(event.actorId, {
rejectOnEmpty: true,
transaction,
});
const notifications = await Notification.findAll({
lock: {
level: transaction.LOCK.UPDATE,
of: Notification,
},
where: {
actorId: event.actorId,
commentId: event.modelId,
viewedAt: {
[Op.eq]: null, // Only target notifications that haven't been viewed
},
event: NotificationEventType.ReactionsCreate,
data: {
emoji,
},
},
});
const ctx = createContext({
user,
transaction,
});
await Promise.all(
notifications.map(async (notification) =>
notification.updateWithCtx(ctx, { archivedAt: new Date() })
)
);
});
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}