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';
|
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const getIndex = (data, length) => length - data.length;
|
2019-05-22 03:21:46 +08:00
|
|
|
|
|
|
|
export default function editCaptions(padId, data) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'EditCaptionHistoryPubMsg';
|
|
|
|
|
2021-05-05 01:34:31 +08:00
|
|
|
try {
|
|
|
|
check(padId, String);
|
|
|
|
check(data, String);
|
|
|
|
|
2021-05-16 21:08:24 +08:00
|
|
|
const pad = Captions.findOne({ padId });
|
2021-05-05 01:34:31 +08:00
|
|
|
|
|
|
|
if (!pad) {
|
|
|
|
Logger.error(`Editing captions history: ${padId}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
2021-05-16 21:08:24 +08:00
|
|
|
meetingId,
|
2021-05-05 01:34:31 +08:00
|
|
|
ownerId,
|
|
|
|
locale,
|
|
|
|
length,
|
|
|
|
} = pad;
|
|
|
|
|
2021-05-16 21:08:24 +08:00
|
|
|
check(meetingId, String);
|
2021-05-05 01:34:31 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, ownerId, payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method editCaptions ${err.stack}`);
|
2020-12-01 04:01:41 +08:00
|
|
|
}
|
2019-05-22 03:21:46 +08:00
|
|
|
}
|