Change to fetch from chat system id, issue #3792 HTML5

This commit is contained in:
Klaus Klein 2017-04-10 11:04:27 -03:00
parent 6727f14ab7
commit b432ffd68b
4 changed files with 29 additions and 34 deletions

View File

@ -54,7 +54,7 @@ export default function sendChat(credentials, message) {
}
if (!isAllowedTo(actionName, credentials)
&& message.from_userid !== requesterUserId) {
&& message.from_userid !== requesterUserId) {
throw new Meteor.Error('not-allowed', `You are not allowed to sendChat`);
}

View File

@ -0,0 +1,26 @@
import Chat from '/imports/api/chat';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import { BREAK_LINE } from '/imports/utils/lineEndings.js';
/**
* Remove any system message from the user with userId.
*
* @param {string} meetingId
* @param {string} userId
*/
export default function clearUserSystemMessages(meetingId, userId) {
check(meetingId, String);
check(userId, String);
const CHAT_CONFIG = Meteor.settings.public.chat;
const selector = {
meetingId,
"message.from_userid": CHAT_CONFIG.type_system,
"message.to_userid": userId,
}
return Chat.remove(selector, Logger.info(`Removing system messages from: (${userId})`));
};

View File

@ -1,20 +0,0 @@
import Chat from '/imports/api/chat';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import { BREAK_LINE } from '/imports/utils/lineEndings.js';
/**
* Remove from chat a message that match the regex 'message' param.
*
* @param {string} meetingId
* @param {string} userId
* @param {string} message
*/
export default function removeChat(meetingId, userId, message) {
if (meetingId && userId && message) {
const modifiers = { meetingId: meetingId, "message.to_userid": userId ,"message.message":{ '$regex': message, '$options': 'i' }};
return Chat.remove(modifiers
, Logger.info(`Removing messages that match: (${message}) `));
}
};

View File

@ -4,7 +4,7 @@ import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
import addChat from '/imports/api/chat/server/modifiers/addChat';
import removeChat from '/imports/api/chat/server/modifiers/removeChat';
import clearUserSystemMessages from '/imports/api/chat/server/modifiers/clearUserSystemMessages';
export default function handleValidateAuthToken({ payload }) {
const meetingId = payload.meeting_id;
@ -41,7 +41,7 @@ export default function handleValidateAuthToken({ payload }) {
if (numChanged) {
if (validStatus) {
clearPastWelcomeMessage(meetingId, userId);
clearUserSystemMessages(meetingId, userId);
addWelcomeChatMessage(meetingId, userId);
}
@ -52,17 +52,6 @@ export default function handleValidateAuthToken({ payload }) {
return Users.update(selector, modifier, cb);
};
/**
* Prevent the chat message having multiple welcome message showing to user, removing the past ones.
* @param {string} meetingId
* @param {string} userId
*/
const clearPastWelcomeMessage = (meetingId, userId) => {
const APP_CONFIG = Meteor.settings.public.app;
return removeChat(meetingId, userId,APP_CONFIG.defaultWelcomeMessageFooter);
};
const addWelcomeChatMessage = (meetingId, userId) => {
const APP_CONFIG = Meteor.settings.public.app;
const CHAT_CONFIG = Meteor.settings.public.chat;