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';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|