2019-05-22 03:21:46 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import Captions from '/imports/api/captions';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
|
|
|
const getIndex = (data, length) => {
|
|
|
|
return length - data.length;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function editCaptions(padId, data) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'EditCaptionHistoryPubMsg';
|
|
|
|
|
|
|
|
check(padId, String);
|
|
|
|
check(data, String);
|
|
|
|
|
2019-05-23 22:51:01 +08:00
|
|
|
const pad = Captions.findOne({ padId });
|
2019-05-22 03:21:46 +08:00
|
|
|
|
|
|
|
if (!pad) return Logger.error(`Editing captions history: ${padId}`);
|
|
|
|
|
|
|
|
const {
|
|
|
|
meetingId,
|
|
|
|
ownerId,
|
|
|
|
locale,
|
|
|
|
length,
|
|
|
|
} = pad;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(ownerId, String);
|
|
|
|
check(locale, { locale: String, name: String });
|
|
|
|
check(length, Number);
|
|
|
|
|
|
|
|
const index = getIndex(data, length);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
startIndex: index,
|
|
|
|
localeCode: locale.locale,
|
|
|
|
locale: locale.name,
|
|
|
|
endIndex: index,
|
|
|
|
text: data,
|
|
|
|
};
|
|
|
|
|
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, ownerId, payload);
|
|
|
|
}
|