Filtering correct the messages
This commit is contained in:
parent
898f7c97e3
commit
e1004b64d3
@ -6,9 +6,6 @@ import Logger from '/imports/startup/server/logger';
|
|||||||
import mapToAcl from '/imports/startup/mapToAcl';
|
import mapToAcl from '/imports/startup/mapToAcl';
|
||||||
|
|
||||||
function chat(credentials) {
|
function chat(credentials) {
|
||||||
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
||||||
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
|
|
||||||
|
|
||||||
const { meetingId, requesterUserId, requesterToken } = credentials;
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
||||||
|
|
||||||
check(meetingId, String);
|
check(meetingId, String);
|
||||||
@ -20,13 +17,13 @@ function chat(credentials) {
|
|||||||
return Chat.find({
|
return Chat.find({
|
||||||
$or: [
|
$or: [
|
||||||
{
|
{
|
||||||
'message.chatType': PUBLIC_CHAT_TYPE,
|
'message.toUsername': 'public_chat_username',
|
||||||
meetingId,
|
meetingId,
|
||||||
}, {
|
}, {
|
||||||
'message.fromUserid': requesterUserId,
|
'message.fromUserId': requesterUserId,
|
||||||
meetingId,
|
meetingId,
|
||||||
}, {
|
}, {
|
||||||
'message.toUserid': requesterUserId,
|
'message.toUserId': requesterUserId,
|
||||||
meetingId,
|
meetingId,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -12,8 +12,6 @@ const CHAT_CONFIG = Meteor.settings.public.chat;
|
|||||||
const GROUPING_MESSAGES_WINDOW = CHAT_CONFIG.grouping_messages_window;
|
const GROUPING_MESSAGES_WINDOW = CHAT_CONFIG.grouping_messages_window;
|
||||||
|
|
||||||
const SYSTEM_CHAT_TYPE = CHAT_CONFIG.type_system;
|
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_ID = CHAT_CONFIG.public_id;
|
||||||
const PUBLIC_CHAT_USERID = CHAT_CONFIG.public_userid;
|
const PUBLIC_CHAT_USERID = CHAT_CONFIG.public_userid;
|
||||||
@ -105,11 +103,10 @@ const reduceMessages = (previous, current) => {
|
|||||||
|
|
||||||
const getPublicMessages = () => {
|
const getPublicMessages = () => {
|
||||||
const publicMessages = Chats.find({
|
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'],
|
sort: ['message.fromTime'],
|
||||||
})
|
}).fetch();
|
||||||
.fetch();
|
|
||||||
|
|
||||||
return publicMessages
|
return publicMessages
|
||||||
.reduce(reduceMessages, [])
|
.reduce(reduceMessages, [])
|
||||||
@ -118,10 +115,10 @@ const getPublicMessages = () => {
|
|||||||
|
|
||||||
const getPrivateMessages = (userID) => {
|
const getPrivateMessages = (userID) => {
|
||||||
const messages = Chats.find({
|
const messages = Chats.find({
|
||||||
'message.chatType': PRIVATE_CHAT_TYPE,
|
'message.toUsername': { $ne: 'public_chat_username' },
|
||||||
$or: [
|
$or: [
|
||||||
{ 'message.toUserid': userID },
|
{ 'message.toUserId': userID },
|
||||||
{ 'message.fromUserid': userID },
|
{ 'message.fromUserId': userID },
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
sort: ['message.fromTime'],
|
sort: ['message.fromTime'],
|
||||||
|
@ -5,7 +5,6 @@ import Auth from '/imports/ui/services/auth';
|
|||||||
import Chats from '/imports/api/2.0/chat';
|
import Chats from '/imports/api/2.0/chat';
|
||||||
|
|
||||||
const CHAT_CONFIG = Meteor.settings.public.chat;
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
||||||
const PUBLIC_CHAT_USERID = CHAT_CONFIG.public_userid;
|
|
||||||
const STORAGE_KEY = CHAT_CONFIG.storage_key;
|
const STORAGE_KEY = CHAT_CONFIG.storage_key;
|
||||||
|
|
||||||
class UnreadMessagesTracker {
|
class UnreadMessagesTracker {
|
||||||
@ -32,18 +31,18 @@ class UnreadMessagesTracker {
|
|||||||
|
|
||||||
count(chatID) {
|
count(chatID) {
|
||||||
const filter = {
|
const filter = {
|
||||||
'message.from_time': {
|
'message.fromTime': {
|
||||||
$gt: this.get(chatID),
|
$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
|
// Minimongo does not support $eq. See https://github.com/meteor/meteor/issues/4142
|
||||||
if (chatID === PUBLIC_CHAT_USERID) {
|
if (chatID === 'public_chat_userid') {
|
||||||
filter['message.to_userid'] = { $not: { $ne: chatID } };
|
filter['message.toUserId'] = { $not: { $ne: chatID } };
|
||||||
} else {
|
} else {
|
||||||
filter['message.to_userid'] = { $not: { $ne: Auth.userID } };
|
filter['message.toUserId'] = { $not: { $ne: Auth.userID } };
|
||||||
filter['message.from_userid'].$not = { $ne: chatID };
|
filter['message.fromUserId'].$not = { $ne: chatID };
|
||||||
}
|
}
|
||||||
|
|
||||||
return Chats.find(filter).count();
|
return Chats.find(filter).count();
|
||||||
|
Loading…
Reference in New Issue
Block a user