fix: Email notifications not sent when mention added to edited comment (#5145
* WIP: Need new email template * New emails
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { Event, Comment, User } from "@server/models";
|
||||
import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper";
|
||||
|
||||
type Props = {
|
||||
/** The user updating the comment */
|
||||
@@ -29,6 +30,10 @@ export default async function commentUpdater({
|
||||
ip,
|
||||
transaction,
|
||||
}: Props): Promise<Comment> {
|
||||
const mentionIdsBefore = ProsemirrorHelper.parseMentions(
|
||||
ProsemirrorHelper.toProsemirror(comment.data)
|
||||
).map((mention) => mention.id);
|
||||
|
||||
if (resolvedBy !== undefined) {
|
||||
comment.resolvedBy = resolvedBy;
|
||||
}
|
||||
@@ -36,6 +41,14 @@ export default async function commentUpdater({
|
||||
comment.data = data;
|
||||
}
|
||||
|
||||
const mentionsAfter = ProsemirrorHelper.parseMentions(
|
||||
ProsemirrorHelper.toProsemirror(comment.data)
|
||||
);
|
||||
|
||||
const newMentionIds = mentionsAfter
|
||||
.filter((mention) => !mentionIdsBefore.includes(mention.id))
|
||||
.map((mention) => mention.id);
|
||||
|
||||
await comment.save({ transaction });
|
||||
|
||||
await Event.create(
|
||||
@@ -46,6 +59,9 @@ export default async function commentUpdater({
|
||||
actorId: user.id,
|
||||
documentId: comment.documentId,
|
||||
ip,
|
||||
data: {
|
||||
newMentionIds,
|
||||
},
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user