2016-11-12 03:02:46 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
2016-11-12 03:02:46 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
export default function setCurrentPresentation(meetingId, podId, presentationId) {
|
2016-11-12 03:02:46 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(presentationId, String);
|
2018-04-10 03:48:37 +08:00
|
|
|
check(podId, String);
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
const oldCurrent = {
|
|
|
|
selector: {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
podId,
|
2017-10-12 08:40:51 +08:00
|
|
|
current: true,
|
2022-02-09 21:37:40 +08:00
|
|
|
id: {
|
|
|
|
$ne: presentationId,
|
|
|
|
},
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
modifier: {
|
2017-10-12 08:40:51 +08:00
|
|
|
$set: { current: false },
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
callback: (err) => {
|
|
|
|
if (err) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.error(`Unsetting the current presentation: ${err}`);
|
|
|
|
return;
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
|
|
|
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info('Unsetted as current presentation');
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newCurrent = {
|
|
|
|
selector: {
|
|
|
|
meetingId,
|
2018-04-10 03:48:37 +08:00
|
|
|
podId,
|
2017-10-12 08:40:51 +08:00
|
|
|
id: presentationId,
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
modifier: {
|
2017-10-12 08:40:51 +08:00
|
|
|
$set: { current: true },
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
callback: (err) => {
|
|
|
|
if (err) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.error(`Setting as current presentation id=${presentationId}: ${err}`);
|
|
|
|
return;
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
|
|
|
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info(`Setted as current presentation id=${presentationId}`);
|
2016-11-12 03:02:46 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const oldPresentation = Presentations.findOne(oldCurrent.selector);
|
|
|
|
const newPresentation = Presentations.findOne(newCurrent.selector);
|
2023-03-04 01:58:41 +08:00
|
|
|
// We update it before unset current to avoid the case where theres no current presentation.
|
|
|
|
if (newPresentation) {
|
2022-02-09 21:37:40 +08:00
|
|
|
try{
|
2023-03-04 01:58:41 +08:00
|
|
|
Presentations.update(newPresentation._id, newCurrent.modifier);
|
2022-02-09 21:37:40 +08:00
|
|
|
} catch(e){
|
2023-03-04 01:58:41 +08:00
|
|
|
newCurrent.callback(e);
|
2022-02-09 21:37:40 +08:00
|
|
|
}
|
2017-10-12 08:40:51 +08:00
|
|
|
}
|
|
|
|
|
2023-03-04 01:58:41 +08:00
|
|
|
if (oldPresentation) {
|
2022-02-09 21:37:40 +08:00
|
|
|
try{
|
2023-03-04 01:58:41 +08:00
|
|
|
Presentations.update(oldCurrent.selector, oldCurrent.modifier, {multi: true});
|
2022-02-09 21:37:40 +08:00
|
|
|
} catch(e){
|
2023-03-04 01:58:41 +08:00
|
|
|
oldCurrent.callback(e);
|
2022-02-09 21:37:40 +08:00
|
|
|
}
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
2023-03-04 01:58:41 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2022-02-09 21:37:40 +08:00
|
|
|
|