bigbluebutton-Github/bigbluebutton-html5/imports/api/chat/server/modifiers/eventHandlers.js
Oleksandr Zhurbenko 331ad1e3c4 Fixed a bug when we couldn't retrieve the initial Chat history
Happened when meeting and chat messages appeared before the Meteor joined
2016-07-18 10:42:53 -07:00

42 lines
1.3 KiB
JavaScript
Executable File

import { eventEmitter } from '/imports/startup/server';
import { addChatToCollection } from '/imports/api/chat/server/modifiers/addChatToCollection';
import { inReplyToHTML5Client } from '/imports/api/common/server/helpers';
import Chat from '/imports/api/chat';
eventEmitter.on('get_chat_history_reply', function (arg) {
if (inReplyToHTML5Client(arg)) {
const meetingId = arg.payload.meeting_id;
if (Chat.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();
};