bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/handlers/lockedStatusChange.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import Users from '/imports/api/users';
import muteToggle from '../methods/muteToggle';
export default function handleLockedStatusChange({ payload }) {
const meetingId = payload.meeting_id;
const userId = payload.userid;
2017-05-10 23:14:40 +08:00
const isLocked = payload.locked;
check(meetingId, String);
check(userId, String);
2017-05-10 23:14:40 +08:00
check(isLocked, Boolean);
const selector = {
meetingId,
userId,
};
2017-02-24 04:26:34 +08:00
const User = Users.findOne(selector);
if (!User) {
throw new Meteor.Error(
'user-not-found', `You need a valid user to be able to set presenter`);
}
const modifier = {
$set: {
'user.locked': isLocked,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Assigning user locked status: ${err}`);
}
if (numChanged) {
if (User.user.role === 'VIEWER'
&& !User.user.listenOnly
&& !User.user.voiceUser.muted
&& User.user.voiceUser.joined
&& isLocked) {
const credentials = {
meetingId,
requesterUserId: userId,
};
muteToggle(credentials, userId, true);
}
2017-05-11 05:02:50 +08:00
return Logger.info(`Assigned locked status '${isLocked ? 'locked' : 'unlocked'}' id=${userId} meeting=${meetingId}`);
}
};
return Users.update(selector, modifier, cb);
};