bigbluebutton-Github/bigbluebutton-html5/imports/api/chat/server/modifiers/eventHandlers.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-05-17 03:12:49 +08:00
import { eventEmitter } from '/imports/startup/server';
import { addChatToCollection } from '/imports/api/chat/server/modifiers/addChatToCollection';
2016-05-17 04:26:24 +08:00
import Meetings from '/imports/api/meetings';
2016-05-17 03:12:49 +08:00
eventEmitter.on('get_chat_history_reply', function (arg) {
if (arg.payload.requester_id === 'nodeJSapp') { //TODO extract this check
const meetingId = arg.payload.meeting_id;
if (Meetings.findOne({
meetingId: meetingId,
}) == null) {
const chatHistory = arg.payload.chat_history;
const chatHistoryLength = chatHistory.length;
for (i = 0; i < chatHistoryLength; i++) {
const chatMessage = chatHistory[i];
addChatToCollection(meetingId, chatMessage);
}
}
}
return arg.callback();
});
eventEmitter.on('send_public_chat_message', function (arg) {
handleChatEvent(arg);
});
eventEmitter.on('send_private_chat_message', function (arg) {
handleChatEvent(arg);
});
const handleChatEvent = function (arg) {
const messageObject = arg.payload.message;
const meetingId = arg.payload.meeting_id;
// use current_time instead of message.from_time so that the chats from Flash and HTML5 have uniform times
messageObject.from_time = arg.header.current_time;
addChatToCollection(meetingId, messageObject);
return arg.callback();
};