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
|
|
|
|
2023-03-09 21:30:34 +08:00
|
|
|
async function userInfos() {
|
|
|
|
const tokenValidation = await AuthTokenValidation
|
|
|
|
.findOneAsync({ connectionId: this.connection.id });
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
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);
|