mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support mention notification
This commit is contained in:
1 parent
d66c161e66
commit
ca00dda575
14 files changed
+67
-24
No files matched your search
@@ -812,6 +812,7 @@ Use admin specificed: 由管理员指定
|
||||
Use algorithm calculated: 使用算法计算
|
||||
Use average of above: 使用上面的平均值
|
||||
User {0} already exists.: 用户 {0} 已存在。
|
||||
User {0} mentioned you in {1:link}: 用户 {0} 在 {1:link} 中提到了你。
|
||||
User {0} not found.: 用户 {0} 不存在。
|
||||
User can join this domain by visiting the following URL: 用户可以访问此链接来加入此域
|
||||
User ID: 用户 ID
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.36.13",
|
||||
"version": "2.36.14",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ const coll = db.collection('message');
|
||||
class MessageModel {
|
||||
static FLAG_UNREAD = 1;
|
||||
static FLAG_ALERT = 2;
|
||||
static FLAG_RICHTEXT = 4;
|
||||
|
||||
@ArgMethod
|
||||
static async send(
|
||||
@@ -33,7 +34,7 @@ class MessageModel {
|
||||
|
||||
@ArgMethod
|
||||
static async getByUser(uid: number): Promise<MessageDoc[]> {
|
||||
return await coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', 1).toArray();
|
||||
return await coll.find({ $or: [{ from: uid }, { to: uid }] }).sort('_id', 1).limit(1000).toArray();
|
||||
}
|
||||
|
||||
static async getMany(query: FilterQuery<MessageDoc>, sort: any, page: number, limit: number): Promise<MessageDoc[]> {
|
||||
|
||||
Reference in new issue
Block a user