Skip to content

Commit

Permalink
fix: Notify previously mentioned users when new comment is added to a…
Browse files Browse the repository at this point in the history
… thread (#8194)
  • Loading branch information
hmacr authored Jan 6, 2025
1 parent 085785a commit 25f264a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions server/models/helpers/NotificationHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uniq from "lodash/uniq";
import { Op } from "sequelize";
import { NotificationEventType } from "@shared/types";
import Logger from "@server/logging/Logger";
Expand All @@ -10,6 +11,7 @@ import {
View,
} from "@server/models";
import { can } from "@server/policies";
import { ProsemirrorHelper } from "./ProsemirrorHelper";

export default class NotificationHelper {
/**
Expand Down Expand Up @@ -67,7 +69,7 @@ export default class NotificationHelper {

if (recipients.length > 0 && comment.parentCommentId) {
const contextComments = await Comment.findAll({
attributes: ["createdById"],
attributes: ["createdById", "data"],
where: {
[Op.or]: [
{ id: comment.parentCommentId },
Expand All @@ -76,7 +78,19 @@ export default class NotificationHelper {
},
});

const userIdsInThread = contextComments.map((c) => c.createdById);
const createdUserIdsInThread = contextComments.map((c) => c.createdById);
const mentionedUserIdsInThread = contextComments
.flatMap((c) =>
ProsemirrorHelper.parseMentions(
ProsemirrorHelper.toProsemirror(c.data)
)
)
.map((mention) => mention.modelId);

const userIdsInThread = uniq([
...createdUserIdsInThread,
...mentionedUserIdsInThread,
]);
recipients = recipients.filter((r) => userIdsInThread.includes(r.id));
}

Expand Down

0 comments on commit 25f264a

Please sign in to comment.