bigbluebutton-Github/bigbluebutton-html5/imports/api/slides/server/modifiers/changeCurrentSlide.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-10-21 19:41:17 +08:00
import { check } from 'meteor/check';
import Slides from '/imports/api/slides';
2016-10-21 19:41:17 +08:00
import Logger from '/imports/startup/server/logger';
export default function changeCurrentSlide(meetingId, podId, presentationId, slideId) {
2016-10-21 19:41:17 +08:00
check(meetingId, String);
check(presentationId, String);
check(slideId, String);
check(podId, String);
2016-10-21 19:41:17 +08:00
const oldCurrent = {
selector: {
meetingId,
podId,
2016-10-21 19:41:17 +08:00
presentationId,
2017-10-12 08:59:35 +08:00
current: true,
2016-10-21 19:41:17 +08:00
},
modifier: {
2017-10-12 08:59:35 +08:00
$set: { current: false },
2016-10-21 19:41:17 +08:00
},
callback: (err) => {
if (err) {
return Logger.error(`Unsetting the current slide: ${err}`);
}
2017-06-03 03:25:02 +08:00
return Logger.info('Unsetted the current slide');
2016-10-21 19:41:17 +08:00
},
};
const newCurrent = {
selector: {
meetingId,
podId,
2016-10-21 19:41:17 +08:00
presentationId,
2017-10-12 08:59:35 +08:00
id: slideId,
2016-10-21 19:41:17 +08:00
},
modifier: {
2017-10-12 08:59:35 +08:00
$set: { current: true },
2016-10-21 19:41:17 +08:00
},
callback: (err) => {
if (err) {
return Logger.error(`Setting as current slide id=${slideId}: ${err}`);
}
return Logger.info(`Setted as current slide id=${slideId}`);
},
};
const oldSlide = Slides.findOne(oldCurrent.selector);
const newSlide = Slides.findOne(newCurrent.selector);
2017-10-12 08:59:35 +08:00
// if the oldCurrent and newCurrent have the same ids
if (oldSlide && newSlide && (oldSlide._id === newSlide._id)) {
return;
}
2016-10-21 19:41:17 +08:00
if (newSlide) {
2016-11-12 03:02:46 +08:00
Slides.update(newSlide._id, newCurrent.modifier, newCurrent.callback);
2016-10-21 19:41:17 +08:00
}
if (oldSlide) {
2016-11-12 03:02:46 +08:00
Slides.update(oldSlide._id, oldCurrent.modifier, oldCurrent.callback);
2016-10-21 19:41:17 +08:00
}
2017-06-03 03:25:02 +08:00
}