Fix bug on the clearChats and addChat modifiers

This commit is contained in:
Oswaldo Acauan 2016-10-21 11:56:03 +00:00
parent b04e071389
commit 6676feb933
7 changed files with 29 additions and 27 deletions

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import { inReplyToHTML5Client } from '/imports/api/common/server/helpers';
import addChatToCollection from '../modifiers/addChatToCollection';
import addChat from '../modifiers/addChat';
export default function handleChatHistory({ payload }) {
if (!inReplyToHTML5Client({ payload })) {
@ -17,7 +17,7 @@ export default function handleChatHistory({ payload }) {
let chatsAdded = [];
chatHistory.forEach(message => {
chatsAdded.push(addChatToCollection(meetingId, message));
chatsAdded.push(addChat(meetingId, message));
});
return chatsAdded;

View File

@ -1,6 +1,6 @@
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import addChatToCollection from '../modifiers/addChatToCollection';
import addChat from '../modifiers/addChat';
export default function handleChatMessage({ payload, header }) {
const message = payload.message;
@ -13,5 +13,5 @@ export default function handleChatMessage({ payload, header }) {
// chats from Flash and HTML5 have uniform times
message.from_time = +(header.current_time);
return addChatToCollection(meetingId, message);
return addChat(meetingId, message);
};

View File

@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import sendChatMessage from './methods/sendChatMessage';
import sendChat from './methods/sendChat';
Meteor.methods({
sendChatMessage,
sendChatMessagetoServer: sendChatMessage, // legacy
sendChat,
sendChatMessagetoServer: sendChat, // legacy
});

View File

@ -32,7 +32,7 @@ const parseMessage = (message) => {
return message;
};
export default function sendChatMessage(credentials, message) {
export default function sendChat(credentials, message) {
const REDIS_CONFIG = Meteor.settings.redis;
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.chat;
@ -56,7 +56,7 @@ export default function sendChatMessage(credentials, message) {
if (!isAllowedTo(actionName, credentials)
&& message.from_userid !== requesterUserId) {
throw new Meteor.Error('not-allowed', `You are not allowed to sendChatMessage`);
throw new Meteor.Error('not-allowed', `You are not allowed to sendChat`);
}
let payload = {

View File

@ -16,7 +16,7 @@ const parseMessage = (message) => {
return message;
};
export default function addChatToCollection(meetingId, message) {
export default function addChat(meetingId, message) {
// manually convert time from 1.408645053653E12 to 1408645053653 if necessary
// (this is the time_from that the Flash client outputs)
message.from_time = +(message.from_time.toString().split('.').join('').split('E')[0]);
@ -38,18 +38,20 @@ export default function addChatToCollection(meetingId, message) {
};
const modifier = {
meetingId: meetingId,
message: {
chat_type: message.chat_type,
message: message.message,
to_username: message.to_username,
from_tz_offset: message.from_tz_offset,
from_color: message.from_color,
to_userid: message.to_userid,
from_userid: message.from_userid,
from_time: message.from_time,
from_username: message.from_username,
from_lang: message.from_lang,
$set: {
meetingId: meetingId,
message: {
chat_type: message.chat_type,
message: message.message,
to_username: message.to_username,
from_tz_offset: message.from_tz_offset,
from_color: message.from_color,
to_userid: message.to_userid,
from_userid: message.from_userid,
from_time: message.from_time,
from_username: message.from_username,
from_lang: message.from_lang,
},
},
};
@ -62,7 +64,7 @@ export default function addChatToCollection(meetingId, message) {
if (insertedId) {
const to = message.to_username || 'PUBLIC';
return Logger.info(`Added chat id=${insertedId} from ${message.from_username} to ${to}`);
return Logger.info(`Added chat id=${insertedId} from=${message.from_username} to=${to}`);
}
};

View File

@ -2,7 +2,7 @@ import Chat from '/imports/api/chat';
import Logger from '/imports/startup/server/logger';
// called on server start and meeting end
export default function clearChatCollection(meetingId) {
export default function clearChats(meetingId) {
if (meetingId) {
return Chat.remove({ meetingId: meetingId, }, Logger.info(`Cleared Chats (${meetingId})`));
} else {

View File

@ -1,5 +1,5 @@
import { clearUsersCollection } from '/imports/api/users/server/modifiers/clearUsersCollection';
import { clearChatCollection} from '/imports/api/chat/server/modifiers/clearChatCollection';
import clearChats from '/imports/api/chat/server/modifiers/clearChats';
import { clearShapesCollection } from '/imports/api/shapes/server/modifiers/clearShapesCollection';
import { clearSlidesCollection } from '/imports/api/slides/server/modifiers/clearSlidesCollection';
import { clearPresentationsCollection }
@ -39,7 +39,7 @@ export function clearCollections() {
const meetingId = arguments[0];
if (meetingId != null) {
clearUsersCollection(meetingId);
clearChatCollection(meetingId);
clearChats(meetingId);
clearMeetingsCollection(meetingId);
clearShapesCollection(meetingId);
clearSlidesCollection(meetingId);
@ -49,7 +49,7 @@ export function clearCollections() {
clearCaptionsCollection(meetingId);
} else {
clearUsersCollection();
clearChatCollection();
clearChats();
clearMeetingsCollection();
clearShapesCollection();
clearSlidesCollection();