core: message: support richtext

This commit is contained in:
undefined committed 2022-01-14 01:19:10 +08:00
1 parent b6910e574b
commit 55a95b97ea
1 file changed
+8 -3
+8 -3
View File
@@ -4,6 +4,7 @@ import * as bus from '../service/bus';
import db from '../service/db';
import { ArgMethod } from '../utils';
import { PRIV } from './builtin';
import * as system from './system';
import user from './user';
const coll = db.collection('message');
@@ -66,9 +67,13 @@ class MessageModel {
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)));
static async sendNotification(message: string, ...args: any[]) {
const targets = await user.getMulti({ priv: { $bitsAllSet: PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION } })
.project({ _id: 1, viewLang: 1 }).toArray();
return Promise.all(targets.map(({ _id, viewLang }) => {
const msg = message.translate(viewLang || system.get('server.language')).format(...args);
return MessageModel.send(1, _id, msg, MessageModel.FLAG_RICHTEXT);
}));
}
}