2017-01-18 20:53:33 +08:00
|
|
|
import _ from 'underscore';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import { inReplyToHTML5Client } from '/imports/api/common/server/helpers';
|
|
|
|
import addCaption from '../modifiers/addCaption';
|
|
|
|
|
2017-02-09 00:02:39 +08:00
|
|
|
export default function handleCaptionHistory({ payload }) {
|
2017-01-18 20:53:33 +08:00
|
|
|
if (!inReplyToHTML5Client({ payload })) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-01 23:37:31 +08:00
|
|
|
const SERVER_CONFIG = Meteor.settings.app;
|
|
|
|
const CAPTION_CHUNK_LENGTH = SERVER_CONFIG.captionsChunkLength || 1000;
|
|
|
|
|
2017-01-18 20:53:33 +08:00
|
|
|
const meetingId = payload.meeting_id;
|
|
|
|
const locale = payload.locale;
|
|
|
|
const captionHistory = payload.caption_history;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(captionHistory, Object);
|
|
|
|
|
|
|
|
let captionsAdded = [];
|
|
|
|
_.each(captionHistory, (caption, locale) => {
|
|
|
|
let ownerId = caption[0];
|
|
|
|
let captions = caption[1].slice(0);
|
|
|
|
let chunks = [];
|
|
|
|
|
2017-02-09 19:27:13 +08:00
|
|
|
if (captions.length === 0) {
|
|
|
|
chunks.push('');
|
|
|
|
} else while (captions.length > 0) {
|
2017-01-18 20:53:33 +08:00
|
|
|
if (captions.length > CAPTION_CHUNK_LENGTH) {
|
|
|
|
chunks.push(captions.slice(0, CAPTION_CHUNK_LENGTH));
|
|
|
|
captions = captions.slice(CAPTION_CHUNK_LENGTH);
|
|
|
|
} else {
|
|
|
|
chunks.push(captions);
|
|
|
|
captions = captions.slice(captions.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks.forEach((captions, index) => {
|
|
|
|
let captionHistoryObject = {
|
|
|
|
locale,
|
|
|
|
ownerId,
|
|
|
|
captions,
|
|
|
|
index,
|
2017-02-09 00:46:14 +08:00
|
|
|
next: (index < chunks.length - 1) ? index + 1 : undefined,
|
2017-01-18 20:53:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
captionsAdded.push(addCaption(meetingId, locale, captionHistoryObject));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return captionsAdded;
|
|
|
|
};
|