bigbluebutton-Github/bigbluebutton-html5/imports/api/group-chat-msg/server/methods/sendGroupChatMsg.js
2018-03-09 15:42:14 -03:00

56 lines
1.5 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import RegexWebUrl from '/imports/utils/regex-weburl';
const HTML_SAFE_MAP = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};
const parseMessage = (message) => {
let parsedMessage = message || '';
parsedMessage = parsedMessage.trim();
// Replace <br/> with \n\r
parsedMessage = parsedMessage.replace(/<br\s*[\\/]?>/gi, '\n\r');
// Sanitize. See: http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/
parsedMessage = parsedMessage.replace(/[<>'"]/g, c => HTML_SAFE_MAP[c]);
// Replace flash links to flash valid ones
parsedMessage = parsedMessage.replace(RegexWebUrl, "<a href='event:$&'><u>$&</u></a>");
return parsedMessage;
};
export default function sendGroupChatMsg(credentials, chatId, message) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
check(message, Object);
const eventName = 'SendGroupChatMessageMsg';
const parsedMessage = parseMessage(message);
const payload = {
chatId,
// correlationId: `${Date.now()}`,
sender: {
id: requesterUserId,
name: '',
},
// color: '1',
message: parsedMessage,
};
return RedisPubSub.publishUserMessage(CHANNEL, eventName, meetingId, requesterUserId, payload);
}