bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/captions/server/handlers/captionOwnerUpdate.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-06-30 04:22:09 +08:00
import Captions from '/imports/api/2.0/captions';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import addCaption from '../modifiers/addCaption';
export default function handleCaptionOwnerUpdate({ body }, meetingId) {
const { ownerId, locale } = body;
check(meetingId, String);
check(locale, String);
check(ownerId, String);
const selector = {
meetingId,
locale,
};
const modifier = {
$set: {
'captionHistory.ownerId': ownerId,
},
};
const Caption = Captions.findOne(selector);
if (!Caption) {
const captionHistory = {
ownerId,
captions: '',
index: 0,
next: null,
};
return addCaption(meetingId, locale, captionHistory);
}
2017-07-07 19:17:49 +08:00
const cb = (err) => {
2017-06-30 04:22:09 +08:00
if (err) {
return Logger.error(`Updating captions owner: ${err}`);
}
2017-07-07 19:17:49 +08:00
return Logger.verbose(`Update caption owner locale=${locale} meeting=${meetingId}`);
2017-06-30 04:22:09 +08:00
};
return Captions.update(selector, modifier, { multi: true }, cb);
}