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

66 lines
1.4 KiB
JavaScript
Raw Normal View History

import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
2017-06-29 02:14:29 +08:00
import Users from '/imports/api/2.0/users';
2017-06-29 04:04:41 +08:00
const unassignCurrentPresenter = (meetingId, presenterId) => {
const selector = {
meetingId,
2017-06-29 04:04:41 +08:00
userId: { $ne: presenterId },
'user.presenter': true,
};
const modifier = {
$set: {
2017-06-29 04:04:41 +08:00
'user.presenter': false,
},
2017-07-17 20:00:18 +08:00
$pop: {
'user.roles': 'presenter',
},
};
2017-07-17 20:00:18 +08:00
const cb = (err) => {
if (err) {
2017-06-29 04:04:41 +08:00
return Logger.error(`Unassigning current presenter from collection: ${err}`);
}
2017-07-17 20:00:18 +08:00
return Logger.info(`Unassign current presenter meeting=${meetingId}`);
};
return Users.update(selector, modifier, cb);
2017-06-29 04:04:41 +08:00
};
2017-06-29 21:09:11 +08:00
export default function handlePresenterAssigned({ body }, meetingId) {
2017-06-29 04:04:41 +08:00
const { presenterId } = body;
check(presenterId, String);
const selector = {
meetingId,
2017-06-29 04:04:41 +08:00
userId: presenterId,
};
const modifier = {
$set: {
2017-06-29 04:04:41 +08:00
'user.presenter': true,
},
2017-07-17 20:00:18 +08:00
$push: {
'user.roles': 'presenter',
},
};
2017-07-26 00:21:07 +08:00
const cb = (err, numChange) => {
if (err) {
2017-06-29 04:04:41 +08:00
return Logger.error(`Assigning user as presenter: ${err}`);
}
2017-07-26 00:21:07 +08:00
if (numChange) {
unassignCurrentPresenter(meetingId, presenterId);
return Logger.info(`Assigned user as presenter id=${presenterId} meeting=${meetingId}`);
}
return Logger.info(`User not assigned as presenter id=${presenterId} meeting=${meetingId}`);
};
return Users.update(selector, modifier, cb);
2017-06-29 04:04:41 +08:00
}