2019-04-06 06:32:21 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import UserInfos from '/imports/api/users-infos';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2019-04-06 06:32:21 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function userInfos() {
|
2020-09-02 00:31:11 +08:00
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing UserInfos was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return UserInfos.find({ meetingId: '' });
|
|
|
|
}
|
2019-04-06 06:32:21 +08:00
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId: requesterUserId } = tokenValidation;
|
|
|
|
|
2020-11-24 23:13:09 +08:00
|
|
|
Logger.debug('Publishing UserInfos requested', { meetingId, requesterUserId });
|
2019-04-06 06:32:21 +08:00
|
|
|
|
|
|
|
return UserInfos.find({ meetingId, requesterUserId });
|
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundUserInfos = userInfos.bind(this);
|
|
|
|
return boundUserInfos(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('users-infos', publish);
|