2018-04-06 03:59:26 +08:00
|
|
|
import { Match, check } from 'meteor/check';
|
|
|
|
import PresentationPods from '/imports/api/presentation-pods';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2018-04-06 06:29:58 +08:00
|
|
|
import addPresentation from '/imports/api/presentations/server/modifiers/addPresentation';
|
2018-04-06 03:59:26 +08:00
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
// 'presentations' is passed down here when we receive a Sync message
|
|
|
|
// and it's not used when we just create a new presentation pod
|
2023-03-15 03:50:35 +08:00
|
|
|
export default async function addPresentationPod(meetingId, pod, presentations = undefined) {
|
2018-04-06 03:59:26 +08:00
|
|
|
check(meetingId, String);
|
2018-04-06 06:29:58 +08:00
|
|
|
check(presentations, Match.Maybe(Array));
|
2018-04-06 03:59:26 +08:00
|
|
|
check(pod, {
|
|
|
|
currentPresenterId: String,
|
|
|
|
podId: String,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { currentPresenterId, podId } = pod;
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
currentPresenterId,
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-03-15 03:50:35 +08:00
|
|
|
const { insertedId } = await PresentationPods.upsertAsync(selector, modifier);
|
2018-04-06 03:59:26 +08:00
|
|
|
|
2018-04-10 03:48:37 +08:00
|
|
|
// if it's a Sync message - continue adding the attached presentations
|
2018-04-06 06:29:58 +08:00
|
|
|
if (presentations) {
|
2023-03-15 03:50:35 +08:00
|
|
|
presentations.forEach(async (presentation) =>
|
|
|
|
addPresentation(meetingId, podId, presentation));
|
2018-04-06 06:29:58 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (insertedId) {
|
|
|
|
Logger.info(`Added presentation pod id=${podId} meeting=${meetingId}`);
|
|
|
|
} else {
|
|
|
|
Logger.info(`Upserted presentation pod id=${podId} meeting=${meetingId}`);
|
2018-04-06 03:59:26 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding presentation pod to the collection: ${err}`);
|
|
|
|
}
|
2018-04-06 03:59:26 +08:00
|
|
|
}
|