bigbluebutton-Github/bigbluebutton-html5/imports/api/guest-users/server/handlers/guestsWaitingForApproval.js
2021-02-17 09:39:36 -03:00

41 lines
1.2 KiB
JavaScript

import stringHash from 'string-hash';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import GuestUsers from '/imports/api/guest-users/';
const COLOR_LIST = [
'#7b1fa2', '#6a1b9a', '#4a148c', '#5e35b1', '#512da8', '#4527a0',
'#311b92', '#3949ab', '#303f9f', '#283593', '#1a237e', '#1976d2', '#1565c0',
'#0d47a1', '#0277bd', '#01579b',
];
export default function handleGuestsWaitingForApproval({ body }, meetingId) {
const { guests } = body;
check(guests, Array);
check(meetingId, String);
return guests.map((guest) => {
try {
const { insertedId, numberAffected } = GuestUsers.upsert({
meetingId,
intId: guest.intId,
}, {
approved: false,
denied: false,
...guest,
meetingId,
loginTime: guest.registeredOn,
color: COLOR_LIST[stringHash(guest.intId) % COLOR_LIST.length],
});
if (insertedId) {
Logger.info(`Added guest user meeting=${meetingId}`);
} else if (numberAffected) {
Logger.info(`Upserted guest user meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Adding guest user to collection: ${err}`);
}
});
}