50 lines
1.4 KiB
JavaScript
50 lines
1.4 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';
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
const HTML_SAFE_MAP = {
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": ''',
|
|
};
|
|
|
|
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(chatId, message) {
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
const EVENT_NAME = 'SendGroupChatMessageMsg';
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
check(message, Object);
|
|
|
|
const parsedMessage = parseMessage(message.message);
|
|
|
|
message.message = parsedMessage;
|
|
|
|
const payload = {
|
|
msg: message,
|
|
chatId,
|
|
};
|
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
}
|