2016-10-21 19:41:17 +08:00
|
|
|
import { check } from 'meteor/check';
|
2019-08-01 03:10:41 +08:00
|
|
|
import { Slides } from '/imports/api/slides';
|
2016-10-21 19:41:17 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2023-03-16 01:35:25 +08:00
|
|
|
export default async function changeCurrentSlide(meetingId, podId, presentationId, slideId) {
|
2016-10-21 19:41:17 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(presentationId, String);
|
|
|
|
check(slideId, String);
|
2018-04-10 03:48:37 +08:00
|
|
|
check(podId, String);
|
2016-10-21 19:41:17 +08:00
|
|
|
|
|
|
|
const oldCurrent = {
|
|
|
|
selector: {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
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) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.error(`Unsetting the current slide: ${err}`);
|
|
|
|
return;
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
|
|
|
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info('Unsetted the current slide');
|
2016-10-21 19:41:17 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newCurrent = {
|
|
|
|
selector: {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
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) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.error(`Setting as current slide id=${slideId}: ${err}`);
|
|
|
|
return;
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
|
|
|
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info(`Setted as current slide id=${slideId}`);
|
2016-10-21 19:41:17 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-03-16 01:35:25 +08:00
|
|
|
const oldSlide = await Slides.findOneAsync(oldCurrent.selector);
|
|
|
|
const newSlide = await Slides.findOneAsync(newCurrent.selector);
|
2016-10-21 19:41:17 +08:00
|
|
|
|
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) {
|
2023-03-16 01:35:25 +08:00
|
|
|
await Slides.updateAsync(newSlide._id, newCurrent.modifier, newCurrent.callback);
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oldSlide) {
|
2023-03-16 01:35:25 +08:00
|
|
|
await Slides.updateAsync(oldSlide._id, oldCurrent.modifier, oldCurrent.callback);
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|