fix: Email notifications not sent when mention added to edited comment (#5145

* WIP: Need new email template

* New emails
This commit is contained in:
Tom Moor
2023-04-02 14:46:47 -04:00
committed by GitHub
parent 40103c9d8f
commit cf3689014b
9 changed files with 298 additions and 27 deletions

View File

@@ -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 }
);