2016-11-12 03:02:46 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 08:40:51 +08:00
|
|
|
import Presentations from '/imports/api/2.0/presentations';
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
import addPresentation from '../modifiers/addPresentation';
|
|
|
|
|
|
|
|
const clearCurrentPresentation = (meetingId, presentationId) => {
|
2017-06-03 03:25:02 +08:00
|
|
|
const selector = {
|
2016-11-12 03:02:46 +08:00
|
|
|
meetingId,
|
|
|
|
presentationId: { $ne: presentationId },
|
2017-10-12 08:40:51 +08:00
|
|
|
current: true,
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const modifier = {
|
2017-10-12 08:40:51 +08:00
|
|
|
$set: { current: false },
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const cb = (err, numChanged) => {
|
2016-11-12 03:02:46 +08:00
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Unsetting the current presentation: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChanged) {
|
2017-10-12 08:40:51 +08:00
|
|
|
return Logger.info('Unset as current presentation');
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
2017-10-12 08:40:51 +08:00
|
|
|
|
|
|
|
return Logger.info('None presentation to unset');
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Presentations.update(selector, modifier, cb);
|
|
|
|
};
|
|
|
|
|
2017-10-12 08:40:51 +08:00
|
|
|
export default function handlePresentationChange({ header, body }) {
|
|
|
|
const { meetingId } = header;
|
|
|
|
const { presentation } = body;
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(presentation, Object);
|
|
|
|
|
|
|
|
if (presentation.current) {
|
|
|
|
clearCurrentPresentation(meetingId, presentation.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return addPresentation(meetingId, presentation);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|