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

62 lines
1.4 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, presentationId, slideId) {
check(meetingId, String);
check(presentationId, String);
check(slideId, String);
const oldCurrent = {
selector: {
meetingId,
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,
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
}