2016-05-05 04:25:34 +08:00
|
|
|
import { publish } from '/imports/startup/server/helpers';
|
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
2016-05-05 02:29:43 +08:00
|
|
|
import { appendMessageHeader } from '/imports/startup/server/helpers';
|
2016-05-13 01:43:59 +08:00
|
|
|
import { translateHTML5ToFlash } from '/imports/startup/server/helpers';
|
2016-05-05 02:29:43 +08:00
|
|
|
import { logger } from '/imports/startup/server/logger';
|
2016-04-29 06:01:43 +08:00
|
|
|
import { redisConfig } from '/config';
|
2016-04-28 05:04:15 +08:00
|
|
|
|
2016-06-03 02:40:27 +08:00
|
|
|
import RegexWebUrl from '/imports/utils/regex-weburl';
|
|
|
|
|
2016-04-20 01:43:31 +08:00
|
|
|
Meteor.methods({
|
2016-05-05 05:49:01 +08:00
|
|
|
// meetingId: the id of the meeting
|
2016-04-20 01:43:31 +08:00
|
|
|
// chatObject: the object including info on the chat message, including the text
|
|
|
|
// requesterUserId: the userId of the user sending chat
|
|
|
|
// requesterToken: the authToken of the requester
|
2016-05-17 02:12:27 +08:00
|
|
|
sendChatMessagetoServer(credentials, chatObject) {
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
2016-05-17 03:54:51 +08:00
|
|
|
let message;
|
2016-05-16 22:35:59 +08:00
|
|
|
const chatType = chatObject.chat_type;
|
|
|
|
const recipient = chatObject.to_userid;
|
|
|
|
let eventName = null;
|
|
|
|
const action = function () {
|
2016-04-20 01:43:31 +08:00
|
|
|
if (chatType === 'PUBLIC_CHAT') {
|
|
|
|
eventName = 'send_public_chat_message';
|
|
|
|
return 'chatPublic';
|
|
|
|
} else {
|
|
|
|
eventName = 'send_private_chat_message';
|
|
|
|
if (recipient === requesterUserId) {
|
|
|
|
return 'chatSelf'; //not allowed
|
|
|
|
} else {
|
|
|
|
return 'chatPrivate';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-17 02:12:27 +08:00
|
|
|
if (isAllowedTo(action(), credentials) && chatObject.from_userid === requesterUserId) {
|
2016-06-03 02:40:27 +08:00
|
|
|
chatObject.message = parseMessage(chatObject.message);
|
2016-05-16 22:35:59 +08:00
|
|
|
let message = {
|
2016-04-20 01:43:31 +08:00
|
|
|
payload: {
|
|
|
|
message: chatObject,
|
|
|
|
meeting_id: meetingId,
|
|
|
|
requester_id: chatObject.from_userid,
|
|
|
|
},
|
|
|
|
};
|
2016-04-20 05:16:32 +08:00
|
|
|
message = appendMessageHeader(eventName, message);
|
2016-04-29 05:37:15 +08:00
|
|
|
logger.info('publishing chat to redis');
|
2016-04-29 06:01:43 +08:00
|
|
|
publish(redisConfig.channels.toBBBApps.chat, message);
|
2016-04-20 01:43:31 +08:00
|
|
|
}
|
2016-05-05 05:49:01 +08:00
|
|
|
},
|
2016-04-20 01:43:31 +08:00
|
|
|
});
|
2016-06-03 02:40:27 +08:00
|
|
|
|
|
|
|
const parseMessage = (message) => {
|
|
|
|
message = message || '';
|
|
|
|
|
|
|
|
// Replace flash links to flash valid ones
|
|
|
|
message.replace(RegexWebUrl, "<a href='event:$&'><u>$&</u></a>");
|
|
|
|
|
|
|
|
return message;
|
|
|
|
};
|