2017-06-19 21:13:35 +08:00
|
|
|
import Users from '..';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import mapToAcl from '/imports/startup/mapToAcl';
|
|
|
|
|
|
|
|
import userLeaving from './methods/userLeaving';
|
|
|
|
|
|
|
|
Meteor.publish('current-user2x', (credentials) => {
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
authToken: requesterToken,
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
user: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.find(selector, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
function users(credentials) {
|
2017-06-21 01:17:37 +08:00
|
|
|
console.error('users2x publish');
|
2017-06-19 21:13:35 +08:00
|
|
|
const {
|
|
|
|
meetingId,
|
|
|
|
requesterUserId,
|
|
|
|
requesterToken,
|
|
|
|
} = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
|
|
|
this.onStop(() => {
|
|
|
|
try {
|
|
|
|
userLeaving(credentials, requesterUserId);
|
|
|
|
} catch (e) {
|
|
|
|
Logger.error(`Exception while executing userLeaving: ${e}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
authToken: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Logger.info(`Publishing Users2x for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
|
|
|
|
|
|
|
return Users.find(selector, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundUsers = users.bind(this);
|
|
|
|
return mapToAcl('subscriptions.users', boundUsers)(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('users2x', publish);
|