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';
|
|
|
|
import RegexWebUrl from '/imports/utils/regex-weburl';
|
|
|
|
|
|
|
|
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(credentials, chatId, message) {
|
|
|
|
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
|
|
|
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
check(message, Object);
|
|
|
|
|
2018-07-26 22:56:26 +08:00
|
|
|
const parsedMessage = parseMessage(message.message);
|
|
|
|
|
2018-07-27 21:44:21 +08:00
|
|
|
message.message = parsedMessage;
|
2018-03-10 02:42:14 +08:00
|
|
|
|
|
|
|
const payload = {
|
2018-07-26 22:56:26 +08:00
|
|
|
msg: message,
|
2018-07-27 21:44:21 +08:00
|
|
|
chatId,
|
2018-03-10 02:42:14 +08:00
|
|
|
};
|
|
|
|
|
2018-07-26 22:56:26 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|