mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: add system.sendNotification api
This commit is contained in:
1 parent
a718a83cd6
commit
b6910e574b
1 file changed
+6
@@ -3,6 +3,7 @@ import { MessageDoc } from '../interface';
|
||||
import * as bus from '../service/bus';
|
||||
import db from '../service/db';
|
||||
import { ArgMethod } from '../utils';
|
||||
import { PRIV } from './builtin';
|
||||
import user from './user';
|
||||
|
||||
const coll = db.collection('message');
|
||||
@@ -64,6 +65,11 @@ class MessageModel {
|
||||
static getMulti(uid: number) {
|
||||
return coll.find({ $or: [{ from: uid }, { to: uid }] });
|
||||
}
|
||||
|
||||
static async sendNotification(message: string) {
|
||||
const targets = await user.getMulti({ priv: { $bitsAllSet: PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION } }).project({ _id: 1 }).toArray();
|
||||
return Promise.all(targets.map(({ _id }) => MessageModel.send(1, _id, message)));
|
||||
}
|
||||
}
|
||||
|
||||
bus.once('app/started', () => db.ensureIndexes(
|
||||
|
||||
Reference in new issue
Block a user