2018-03-10 02:42:14 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
|
2023-07-26 21:38:10 +08:00
|
|
|
import { extractCredentials, parseMessage } from '/imports/api/common/server/helpers';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
export default function sendGroupChatMsg(chatId, message) {
|
2018-03-10 02:42:14 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
2018-07-26 22:56:26 +08:00
|
|
|
const EVENT_NAME = 'SendGroupChatMessageMsg';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2021-05-05 20:13:48 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2021-05-05 20:13:48 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(chatId, String);
|
|
|
|
check(message, Object);
|
|
|
|
const parsedMessage = parseMessage(message.message);
|
|
|
|
message.message = parsedMessage;
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2021-05-05 20:13:48 +08:00
|
|
|
const payload = {
|
|
|
|
msg: message,
|
|
|
|
chatId,
|
|
|
|
};
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2021-05-05 20:13:48 +08:00
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method sendGroupChatMsg ${err.stack}`);
|
|
|
|
}
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|