Filtering correct the messages

This commit is contained in:
Klaus 2017-07-12 10:54:54 -03:00
parent 898f7c97e3
commit e1004b64d3
3 changed files with 14 additions and 21 deletions

View File

@ -6,9 +6,6 @@ import Logger from '/imports/startup/server/logger';
import mapToAcl from '/imports/startup/mapToAcl';
function chat(credentials) {
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
@ -20,13 +17,13 @@ function chat(credentials) {
return Chat.find({
$or: [
{
'message.chatType': PUBLIC_CHAT_TYPE,
'message.toUsername': 'public_chat_username',
meetingId,
}, {
'message.fromUserid': requesterUserId,
'message.fromUserId': requesterUserId,
meetingId,
}, {
'message.toUserid': requesterUserId,
'message.toUserId': requesterUserId,
meetingId,
},
],

View File

@ -12,8 +12,6 @@ const CHAT_CONFIG = Meteor.settings.public.chat;
const GROUPING_MESSAGES_WINDOW = CHAT_CONFIG.grouping_messages_window;
const SYSTEM_CHAT_TYPE = CHAT_CONFIG.type_system;
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
const PRIVATE_CHAT_TYPE = CHAT_CONFIG.type_private;
const PUBLIC_CHAT_ID = CHAT_CONFIG.public_id;
const PUBLIC_CHAT_USERID = CHAT_CONFIG.public_userid;
@ -105,11 +103,10 @@ const reduceMessages = (previous, current) => {
const getPublicMessages = () => {
const publicMessages = Chats.find({
'message.chatType': { $in: [PUBLIC_CHAT_TYPE, SYSTEM_CHAT_TYPE] },
'message.toUsername': { $in: ['public_chat_username', SYSTEM_CHAT_TYPE] },
}, {
sort: ['message.fromTime'],
})
.fetch();
}).fetch();
return publicMessages
.reduce(reduceMessages, [])
@ -118,10 +115,10 @@ const getPublicMessages = () => {
const getPrivateMessages = (userID) => {
const messages = Chats.find({
'message.chatType': PRIVATE_CHAT_TYPE,
'message.toUsername': { $ne: 'public_chat_username' },
$or: [
{ 'message.toUserid': userID },
{ 'message.fromUserid': userID },
{ 'message.toUserId': userID },
{ 'message.fromUserId': userID },
],
}, {
sort: ['message.fromTime'],

View File

@ -5,7 +5,6 @@ import Auth from '/imports/ui/services/auth';
import Chats from '/imports/api/2.0/chat';
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_USERID = CHAT_CONFIG.public_userid;
const STORAGE_KEY = CHAT_CONFIG.storage_key;
class UnreadMessagesTracker {
@ -32,18 +31,18 @@ class UnreadMessagesTracker {
count(chatID) {
const filter = {
'message.from_time': {
'message.fromTime': {
$gt: this.get(chatID),
},
'message.from_userid': { $ne: Auth.userID },
'message.fromUserId': { $ne: Auth.userID },
};
// Minimongo does not support $eq. See https://github.com/meteor/meteor/issues/4142
if (chatID === PUBLIC_CHAT_USERID) {
filter['message.to_userid'] = { $not: { $ne: chatID } };
if (chatID === 'public_chat_userid') {
filter['message.toUserId'] = { $not: { $ne: chatID } };
} else {
filter['message.to_userid'] = { $not: { $ne: Auth.userID } };
filter['message.from_userid'].$not = { $ne: chatID };
filter['message.toUserId'] = { $not: { $ne: Auth.userID } };
filter['message.fromUserId'].$not = { $ne: chatID };
}
return Chats.find(filter).count();