2016-10-28 01:47:40 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2019-03-08 04:23:42 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-10-12 05:25:18 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2016-10-28 01:47:40 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2020-06-05 21:32:05 +08:00
|
|
|
function breakouts(role) {
|
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 Breakouts was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return Breakouts.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
Logger.debug(`Publishing Breakouts for ${meetingId} ${userId}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const User = Users.findOne({ userId, meetingId }, { fields: { role: 1 } });
|
2020-05-21 05:07:36 +08:00
|
|
|
if (!!User && User.role === ROLE_MODERATOR) {
|
|
|
|
const presenterSelector = {
|
|
|
|
$or: [
|
|
|
|
{ parentMeetingId: meetingId },
|
|
|
|
{ breakoutId: meetingId },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return Breakouts.find(presenterSelector);
|
2018-11-22 00:27:01 +08:00
|
|
|
}
|
2017-10-12 05:25:18 +08:00
|
|
|
|
2018-06-07 05:24:09 +08:00
|
|
|
const selector = {
|
2018-07-07 01:07:08 +08:00
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
parentMeetingId: meetingId,
|
|
|
|
freeJoin: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentMeetingId: meetingId,
|
2020-09-02 00:31:11 +08:00
|
|
|
'users.userId': userId,
|
2018-07-07 01:07:08 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
breakoutId: meetingId,
|
|
|
|
},
|
2018-06-07 06:18:27 +08:00
|
|
|
],
|
2018-06-07 05:24:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Breakouts.find(selector);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundBreakouts = breakouts.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundBreakouts(...args);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Meteor.publish('breakouts', publish);
|