2017-02-24 01:46:03 +08:00
|
|
|
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;
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
2017-05-10 23:14:40 +08:00
|
|
|
check(isLocked, Boolean);
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
2017-02-24 04:26:34 +08:00
|
|
|
const User = Users.findOne(selector);
|
2017-02-24 01:46:03 +08:00
|
|
|
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-16 23:37:17 +08:00
|
|
|
return Logger.info(`Assigned locked status '${isLocked
|
|
|
|
? 'locked' : 'unlocked'}' id=${userId} meeting=${meetingId}`);
|
2017-02-24 01:46:03 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.update(selector, modifier, cb);
|
|
|
|
};
|