bigbluebutton-Github/bigbluebutton-html5/imports/api/shapes/server/methods/undoAnnotation.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-04-20 02:27:00 +08:00
import RedisPubSub from '/imports/startup/server/redis';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
import Presentations from '/imports/api/presentations';
import Slides from '/imports/api/slides';
export default function undoAnnotation(credentials) {
const REDIS_CONFIG = Meteor.settings.redis;
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.whiteboard;
const EVENT_NAME = 'undo_whiteboard_request';
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
if (!isAllowedTo('undoAnnotation', credentials)) {
throw new Meteor.Error('not-allowed', `You are not allowed to undo the annotation`);
}
const presentationSelector = {
meetingId,
'presentation.current': true,
};
const presentationOptions = {
fields: {
'presentation.id': 1,
_id: 0,
},
};
const presentation = Presentations.findOne(presentationSelector, presentationOptions);
if (!presentation) {
throw new Meteor.Error(
'presentation-not-found', `You need an active presentation to be able to undo the annotation`);
}
const presentationId = presentation.presentation.id;
const slideSelector = {
meetingId,
presentationId: presentationId,
'slide.current': true,
};
const slideOptions = {
fields: {
'slide.id': 1,
_id: 0,
},
};
const slide = Slides.findOne(slideSelector, slideOptions);
if (!slide) {
throw new Meteor.Error(
'slide-not-found', `You need an active slide to be able to undo the annotation`);
}
const whiteboardId = slide.slide.id;
let payload = {
requester_id: requesterUserId,
meeting_id: meetingId,
whiteboard_id: whiteboardId,
};
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
}