2018-07-27 21:44:21 +08:00
|
|
|
import GroupChat from '/imports/api/group-chat';
|
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 groupChat() {
|
|
|
|
if (!this.userId) {
|
|
|
|
return GroupChat.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-08-01 01:13:36 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
Logger.debug(`Publishing group-chat for ${meetingId} ${requesterUserId}`);
|
2018-03-10 02:42:14 +08:00
|
|
|
|
2018-07-27 21:44:21 +08:00
|
|
|
return GroupChat.find({
|
|
|
|
$or: [
|
2018-08-01 01:13:36 +08:00
|
|
|
{ meetingId, access: PUBLIC_CHAT_TYPE },
|
2018-07-27 21:44:21 +08:00
|
|
|
{ meetingId, users: { $all: [requesterUserId] } },
|
|
|
|
],
|
|
|
|
|
|
|
|
});
|
2018-03-10 02:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundGroupChat = groupChat.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', publish);
|