2019-08-03 02:18:33 +08:00
|
|
|
import { GroupChatMsg, UsersTyping } from '/imports/api/group-chat-msg';
|
2018-03-10 02:42:14 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function groupChatMsg(chatsIds) {
|
|
|
|
if (!this.userId) {
|
|
|
|
return GroupChatMsg.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-08-06 20:05:07 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_GROUP_CHAT_ID = CHAT_CONFIG.public_group_id;
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
Logger.debug(`Publishing group-chat-msg for ${meetingId} ${requesterUserId}`);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-08-06 20:05:07 +08:00
|
|
|
return GroupChatMsg.find({
|
|
|
|
$or: [
|
|
|
|
{ meetingId, chatId: { $eq: PUBLIC_GROUP_CHAT_ID } },
|
|
|
|
{ chatId: { $in: chatsIds } },
|
|
|
|
],
|
|
|
|
});
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundGroupChat = groupChatMsg.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundGroupChat(...args);
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('group-chat-msg', publish);
|
2019-08-03 02:18:33 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function usersTyping() {
|
|
|
|
if (!this.userId) {
|
|
|
|
return UsersTyping.find({ meetingId: '' });
|
|
|
|
}
|
2019-08-03 02:18:33 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
const { meetingId } = extractCredentials(this.userId);
|
2019-08-03 02:18:33 +08:00
|
|
|
|
|
|
|
return UsersTyping.find({ meetingId });
|
|
|
|
}
|
|
|
|
|
|
|
|
function pubishUsersTyping(...args) {
|
|
|
|
const boundUsersTyping = usersTyping.bind(this);
|
|
|
|
return boundUsersTyping(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('users-typing', pubishUsersTyping);
|