The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Rocket.Chat/server/lib/sendMessagesToAdmins.js

46 lines
1.1 KiB

import { Meteor } from 'meteor/meteor';
import { Roles, Users } from '../../app/models/server';
export function sendMessagesToAdmins({
fromId = 'rocket.cat',
checkFrom = true,
msgs = [],
banners = [],
}) {
const fromUser = checkFrom ? Users.findOneById(fromId, { fields: { _id: 1 } }) : true;
Roles.findUsersInRole('admin').forEach((adminUser) => {
if (fromUser) {
try {
Meteor.runAsUser(fromId, () => Meteor.call('createDirectMessage', adminUser.username));
const rid = [adminUser._id, fromId].sort().join('');
if (typeof msgs === 'function') {
msgs = msgs({ adminUser });
}
if (!Array.isArray(msgs)) {
msgs = Array.from(msgs);
}
if (typeof banners === 'function') {
banners = banners({ adminUser });
}
if (!Array.isArray(banners)) {
banners = Array.from(banners);
}
Meteor.runAsUser(fromId, () => {
msgs.forEach((msg) => Meteor.call('sendMessage', Object.assign({ rid }, msg)));
});
} catch (e) {
console.error(e);
}
}
banners.forEach((banner) => Users.addBannerById(adminUser._id, banner));
});
}