2017-02-07 21:08:06 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-06 23:56:09 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
|
|
|
|
2017-02-07 23:29:27 +08:00
|
|
|
import userLeaving from './methods/userLeaving';
|
2017-03-11 02:33:46 +08:00
|
|
|
|
|
|
|
Meteor.publish('current-user', function (credentials) {
|
2017-02-06 23:56:09 +08:00
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
authToken: requesterToken,
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
user: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return Users.find(selector, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.publish('users', function (credentials) {
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
if (!isAllowedTo('subscribeUsers', credentials)) {
|
|
|
|
this.error(new Meteor.Error(402, "The user was not authorized to subscribe for 'Users'"));
|
|
|
|
}
|
2017-02-06 23:56:09 +08:00
|
|
|
|
|
|
|
this.onStop(() => {
|
2017-02-07 23:29:27 +08:00
|
|
|
userLeaving(credentials, requesterUserId);
|
2017-02-06 23:56:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
'user.connection_status': {
|
|
|
|
$in: ['online', ''],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
authToken: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Logger.info(`Publishing Users for ${meetingId} ${requesterUserId} ${requesterToken}`);
|
|
|
|
|
|
|
|
return Users.find(selector, options);
|
|
|
|
});
|