core: add system.sendNotification api

pull/293/head
undefined 3 years ago
parent a718a83cd6
commit b6910e574b

@ -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(

Loading…
Cancel
Save