2017-10-12 05:25:18 +08:00
|
|
|
import Chat from '/imports/api/2.0/chat';
|
2016-10-19 20:18:47 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-06-01 01:54:43 +08:00
|
|
|
import mapToAcl from '/imports/startup/mapToAcl';
|
2016-10-19 20:18:47 +08:00
|
|
|
|
2017-06-01 01:54:43 +08:00
|
|
|
function chat(credentials) {
|
2016-10-19 20:18:47 +08:00
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
2017-10-12 05:25:18 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_USERNAME = CHAT_CONFIG.public_username;
|
|
|
|
|
2016-10-19 20:18:47 +08:00
|
|
|
Logger.info(`Publishing chat for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
|
|
|
|
|
|
|
return Chat.find({
|
|
|
|
$or: [
|
|
|
|
{
|
2017-10-12 05:25:18 +08:00
|
|
|
toUsername: PUBLIC_CHAT_USERNAME,
|
2016-10-22 00:54:17 +08:00
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
}, {
|
2017-10-12 05:25:18 +08:00
|
|
|
fromUserId: requesterUserId,
|
2016-10-22 00:54:17 +08:00
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
}, {
|
2017-10-12 05:25:18 +08:00
|
|
|
toUserId: requesterUserId,
|
2016-10-22 00:54:17 +08:00
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundChat = chat.bind(this);
|
|
|
|
return mapToAcl('subscriptions.chat', boundChat)(args);
|
|
|
|
}
|
|
|
|
|
2017-10-12 05:25:18 +08:00
|
|
|
Meteor.publish('chat2x', publish);
|