c213b88451
this also fixes certain poll type detection for other languages than english, so that the correct poll type is sent in the events (they were being detected as custom)
181 lines
4.6 KiB
JavaScript
Executable File
181 lines
4.6 KiB
JavaScript
Executable File
import PresentationPods from '/imports/api/presentation-pods';
|
|
import Presentations from '/imports/api/presentations';
|
|
import { Slides, SlidePositions } from '/imports/api/slides';
|
|
import Auth from '/imports/ui/services/auth';
|
|
import PollService from '/imports/ui/components/poll/service';
|
|
|
|
const getCurrentPresentation = podId => Presentations.findOne({
|
|
podId,
|
|
current: true,
|
|
});
|
|
|
|
const downloadPresentationUri = (podId) => {
|
|
const currentPresentation = getCurrentPresentation(podId);
|
|
if (!currentPresentation) {
|
|
return null;
|
|
}
|
|
|
|
const presentationFileName = `${currentPresentation.id}.${currentPresentation.name.split('.').pop()}`;
|
|
|
|
const uri = `https://${window.document.location.hostname}/bigbluebutton/presentation/download/`
|
|
+ `${currentPresentation.meetingId}/${currentPresentation.id}`
|
|
+ `?presFilename=${encodeURIComponent(presentationFileName)}`;
|
|
|
|
return uri;
|
|
};
|
|
|
|
const isPresentationDownloadable = (podId) => {
|
|
const currentPresentation = getCurrentPresentation(podId);
|
|
if (!currentPresentation) {
|
|
return null;
|
|
}
|
|
|
|
return currentPresentation.downloadable;
|
|
};
|
|
|
|
const getCurrentSlide = (podId) => {
|
|
const currentPresentation = getCurrentPresentation(podId);
|
|
|
|
if (!currentPresentation) {
|
|
return null;
|
|
}
|
|
|
|
return Slides.findOne({
|
|
podId,
|
|
presentationId: currentPresentation.id,
|
|
current: true,
|
|
}, {
|
|
fields: {
|
|
meetingId: 0,
|
|
thumbUri: 0,
|
|
swfUri: 0,
|
|
txtUri: 0,
|
|
},
|
|
});
|
|
};
|
|
|
|
const getSlidePosition = (podId, presentationId, slideId) => SlidePositions.findOne({
|
|
podId,
|
|
presentationId,
|
|
id: slideId,
|
|
});
|
|
|
|
const currentSlidHasContent = () => {
|
|
const currentSlide = getCurrentSlide('DEFAULT_PRESENTATION_POD');
|
|
if (!currentSlide) return false;
|
|
|
|
const {
|
|
content,
|
|
} = currentSlide;
|
|
|
|
return !!content.length;
|
|
};
|
|
|
|
const parseCurrentSlideContent = (yesValue, noValue, abstentionValue, trueValue, falseValue) => {
|
|
const pollTypes = PollService.pollTypes;
|
|
const currentSlide = getCurrentSlide('DEFAULT_PRESENTATION_POD');
|
|
const quickPollOptions = [];
|
|
if (!currentSlide) return quickPollOptions;
|
|
|
|
let {
|
|
content,
|
|
} = currentSlide;
|
|
|
|
const pollRegex = /[1-6A-Fa-f][.)].*/g;
|
|
let optionsPoll = content.match(pollRegex) || [];
|
|
if (optionsPoll) optionsPoll = optionsPoll.map(opt => `\r${opt[0]}.`);
|
|
|
|
optionsPoll.reduce((acc, currentValue) => {
|
|
const lastElement = acc[acc.length - 1];
|
|
|
|
if (!lastElement) {
|
|
acc.push({
|
|
options: [currentValue],
|
|
});
|
|
return acc;
|
|
}
|
|
|
|
const {
|
|
options,
|
|
} = lastElement;
|
|
|
|
const lastOption = options[options.length - 1];
|
|
|
|
const isLastOptionInteger = !!parseInt(lastOption.charAt(1), 10);
|
|
const isCurrentValueInteger = !!parseInt(currentValue.charAt(1), 10);
|
|
|
|
if (isLastOptionInteger === isCurrentValueInteger) {
|
|
if (currentValue.toLowerCase().charCodeAt(1) > lastOption.toLowerCase().charCodeAt(1)) {
|
|
options.push(currentValue);
|
|
} else {
|
|
acc.push({
|
|
options: [currentValue],
|
|
});
|
|
}
|
|
} else {
|
|
acc.push({
|
|
options: [currentValue],
|
|
});
|
|
}
|
|
return acc;
|
|
}, []).filter(({
|
|
options,
|
|
}) => options.length > 1 && options.length < 7).forEach(poll => quickPollOptions.push({
|
|
type: `${pollTypes.Letter}${poll.options.length}`,
|
|
poll,
|
|
}));
|
|
|
|
if (quickPollOptions.length > 0) {
|
|
content = content.replace(new RegExp(pollRegex), '');
|
|
}
|
|
|
|
const ynPoll = PollService.matchYesNoPoll(yesValue, noValue, content);
|
|
const ynaPoll = PollService.matchYesNoAbstentionPoll(yesValue, noValue, abstentionValue, content);
|
|
const tfPoll = PollService.matchTrueFalsePoll(trueValue, falseValue, content);
|
|
|
|
ynPoll.forEach(poll => quickPollOptions.push({
|
|
type: pollTypes.YesNo,
|
|
poll,
|
|
}));
|
|
|
|
ynaPoll.forEach(poll => quickPollOptions.push({
|
|
type: pollTypes.YesNoAbstention,
|
|
poll,
|
|
}));
|
|
|
|
tfPoll.forEach(poll => quickPollOptions.push({
|
|
type: pollTypes.TrueFalse,
|
|
poll,
|
|
}));
|
|
|
|
return {
|
|
slideId: currentSlide.id,
|
|
quickPollOptions,
|
|
};
|
|
};
|
|
|
|
const isPresenter = (podId) => {
|
|
// a main presenter in the meeting always owns a default pod
|
|
if (podId !== 'DEFAULT_PRESENTATION_POD') {
|
|
// if a pod is not default, then we check whether this user owns a current pod
|
|
const selector = {
|
|
meetingId: Auth.meetingID,
|
|
podId,
|
|
};
|
|
const pod = PresentationPods.findOne(selector);
|
|
return pod.currentPresenterId === Auth.userID;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
export default {
|
|
getCurrentSlide,
|
|
getSlidePosition,
|
|
isPresenter,
|
|
isPresentationDownloadable,
|
|
downloadPresentationUri,
|
|
currentSlidHasContent,
|
|
parseCurrentSlideContent,
|
|
getCurrentPresentation,
|
|
};
|