fix(server): send comment mention to comment author by default (#13018)

close AF-2708



#### PR Dependency Tree


* **PR #13018** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added notifications for users when their comment receives a reply,
marking them with a mention.
* **Tests**
* Introduced an end-to-end test to verify that replying to a comment
sends a mention notification to the original comment author.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-07-04 13:38:32 +08:00
committed by GitHub
parent ed6adcf4d9
commit 1b9ed2fb6d
2 changed files with 82 additions and 2 deletions

View File

@@ -687,6 +687,63 @@ e2e(
}
);
e2e(
'should create reply and send comment mention notification to comment author',
async t => {
const docId = randomUUID();
await app.create(Mockers.DocUser, {
workspaceId: teamWorkspace.id,
docId,
userId: owner.id,
type: DocRole.Owner,
});
await app.login(member);
const createResult = await app.gql({
query: createCommentMutation,
variables: {
input: {
workspaceId: teamWorkspace.id,
docId,
docMode: DocMode.page,
docTitle: 'test',
content: {
type: 'paragraph',
content: [{ type: 'text', text: 'test' }],
},
},
},
});
// owner login to create reply and send notification to comment author: member
await app.login(owner);
const count = app.queue.count('notification.sendComment');
const result = await app.gql({
query: createReplyMutation,
variables: {
input: {
commentId: createResult.createComment.id,
docMode: DocMode.page,
docTitle: 'test',
content: {
type: 'paragraph',
content: [{ type: 'text', text: 'test' }],
},
},
},
});
t.truthy(result.createReply.id);
t.is(result.createReply.commentId, createResult.createComment.id);
t.is(app.queue.count('notification.sendComment'), count + 1);
const notification = app.queue.last('notification.sendComment');
t.is(notification.name, 'notification.sendComment');
t.is(notification.payload.userId, member.id);
t.is(notification.payload.body.replyId, result.createReply.id);
t.is(notification.payload.isMention, true);
}
);
e2e('should create reply work when user is Commenter', async t => {
const docId = randomUUID();
await app.create(Mockers.DocUser, {

View File

@@ -396,11 +396,34 @@ export class CommentResolver {
});
}
// send comment mention notification to comment author on reply
if (reply && comment.userId !== sender.id) {
await this.queue.add('notification.sendComment', {
isMention: true,
userId: comment.userId,
body: {
workspaceId: comment.workspaceId,
createdByUserId: sender.id,
commentId: comment.id,
replyId: reply.id,
doc: {
id: comment.docId,
title: docTitle,
mode: docMode,
},
},
});
}
// send comment mention notification to mentioned users
if (mentions) {
for (const mentionUserId of mentions) {
// skip if the mention user is the doc owner
if (mentionUserId === owner?.userId || mentionUserId === sender.id) {
// skip if the mention user is the doc owner or the comment author
if (
mentionUserId === owner?.userId ||
mentionUserId === sender.id ||
mentionUserId === comment.userId
) {
continue;
}