2016-05-17 02:05:44 +08:00
|
|
|
import Chat from '/imports/api/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';
|
2016-05-11 02:53:05 +08:00
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
|
|
|
|
2016-10-19 20:18:47 +08:00
|
|
|
Meteor.publish('chat', (credentials) => {
|
|
|
|
if (!isAllowedTo('subscribeChat', credentials)) {
|
2017-03-14 03:15:58 +08:00
|
|
|
throw new Meteor.Error(402, "The user was not authorized to subscribe for 'chats'");
|
2016-05-11 02:53:05 +08:00
|
|
|
}
|
2016-10-19 20:18:47 +08:00
|
|
|
|
2016-10-22 00:54:17 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_TYPE = CHAT_CONFIG.type_public;
|
|
|
|
|
2016-10-19 20:18:47 +08:00
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
|
|
|
Logger.info(`Publishing chat for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
|
|
|
|
|
|
|
return Chat.find({
|
|
|
|
$or: [
|
|
|
|
{
|
2016-10-22 00:54:17 +08:00
|
|
|
'message.chat_type': PUBLIC_CHAT_TYPE,
|
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
}, {
|
|
|
|
'message.from_userid': requesterUserId,
|
2016-10-22 00:54:17 +08:00
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
}, {
|
|
|
|
'message.to_userid': requesterUserId,
|
2016-10-22 00:54:17 +08:00
|
|
|
meetingId,
|
2016-10-19 20:18:47 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2016-05-11 02:53:05 +08:00
|
|
|
});
|