core: support mention notification

This commit is contained in:
undefined committed 2021-09-20 22:42:24 +08:00
1 parent d66c161e66
commit ca00dda575
14 files changed
+67 -24

No files matched your search

+19 -1
View File
@@ -6,6 +6,7 @@ import paginate from '../lib/paginate';
import { PERM, PRIV } from '../model/builtin';
import * as discussion from '../model/discussion';
import * as document from '../model/document';
import message from '../model/message';
import * as oplog from '../model/oplog';
import * as system from '../model/system';
import user from '../model/user';
@@ -224,7 +225,15 @@ class DiscussionDetailHandler extends DiscussionHandler {
async postReply(domainId: string, did: ObjectID, content: string) {
this.checkPerm(PERM.PERM_REPLY_DISCUSSION);
await this.limitRate('add_discussion', 3600, 60);
// Notify related users
const targets = new Set(Array.from(content.matchAll(/@\[\]\(\/user\/(\d+)\)/g)).map((i) => +i[1]));
const uids = Object.keys(await user.getList(domainId, Array.from(targets))).map((i) => +i);
const msg = JSON.stringify({
message: 'User {0} mentioned you in {1:link}',
params: [this.user.uname, this.request.path],
});
for (const uid of uids) {
message.send(1, uid, msg, message.FLAG_RICHTEXT | message.FLAG_UNREAD);
}
await discussion.addReply(domainId, did, this.user._id, content, this.request.ip);
this.back();
}
@@ -234,6 +243,15 @@ class DiscussionDetailHandler extends DiscussionHandler {
async postTailReply(domainId: string, drid: ObjectID, content: string) {
this.checkPerm(PERM.PERM_REPLY_DISCUSSION);
await this.limitRate('add_discussion', 3600, 60);
const targets = new Set(Array.from(content.matchAll(/@\[\]\(\/user\/(\d+)\)/g)).map((i) => +i[1]));
const uids = Object.keys(await user.getList(domainId, Array.from(targets))).map((i) => +i);
const msg = JSON.stringify({
message: 'User {0} mentioned you in {1:link}',
params: [this.user.uname, this.request.path],
});
for (const uid of uids) {
message.send(1, uid, msg, message.FLAG_RICHTEXT | message.FLAG_UNREAD);
}
await discussion.addTailReply(domainId, drid, this.user._id, content, this.request.ip);
this.back();
}
+1 -5
View File
@@ -368,12 +368,8 @@ class HomeMessagesHandler extends Handler {
}
parsed[target].messages.push(m);
}
const path = [
['Hydro', 'homepage'],
['home_messages', null],
];
await user.setById(this.user._id, { unreadMsg: 0 });
this.response.body = { messages: parsed, path };
this.response.body = { messages: parsed };
this.response.template = 'home_messages.html';
}