2016-10-22 00:27:47 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2022-03-31 22:43:58 +08:00
|
|
|
import { Random } from 'meteor/random';
|
2021-05-27 03:09:25 +08:00
|
|
|
import Meetings, {
|
|
|
|
RecordMeetings,
|
|
|
|
MeetingTimeRemaining,
|
2022-01-21 01:50:16 +08:00
|
|
|
LayoutMeetings,
|
2021-05-27 03:09:25 +08:00
|
|
|
} from '/imports/api/meetings';
|
2019-03-08 04:23:42 +08:00
|
|
|
import Users from '/imports/api/users';
|
2016-10-22 00:27:47 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-09-07 04:51:42 +08:00
|
|
|
import { publicationSafeGuard } from '/imports/api/common/server/helpers';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2022-03-11 03:33:25 +08:00
|
|
|
import notificationEmitter from '../notificationEmitter';
|
2016-10-22 00:27:47 +08:00
|
|
|
|
2019-06-29 04:52:19 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
function meetings() {
|
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 Meetings was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return Meetings.find({ meetingId: '' });
|
|
|
|
}
|
2016-10-22 00:27:47 +08:00
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
|
2020-11-24 23:13:09 +08:00
|
|
|
Logger.debug('Publishing meeting', { meetingId, userId });
|
2016-10-22 00:27:47 +08:00
|
|
|
|
2018-09-10 23:34:25 +08:00
|
|
|
const selector = {
|
2018-10-17 01:55:20 +08:00
|
|
|
$or: [
|
|
|
|
{ meetingId },
|
|
|
|
],
|
2018-09-10 23:34:25 +08:00
|
|
|
};
|
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
const User = Users.findOne({ userId, meetingId }, { fields: { userId: 1, role: 1 } });
|
2020-05-21 05:07:36 +08:00
|
|
|
if (!!User && User.role === ROLE_MODERATOR) {
|
|
|
|
selector.$or.push({
|
|
|
|
'meetingProp.isBreakout': true,
|
|
|
|
'breakoutProps.parentId': meetingId,
|
|
|
|
});
|
2021-09-07 04:51:42 +08:00
|
|
|
// Monitor this publication and stop it when user is not a moderator anymore
|
|
|
|
const comparisonFunc = () => {
|
|
|
|
const user = Users.findOne({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
|
|
|
|
const condition = user.role === ROLE_MODERATOR;
|
|
|
|
|
|
|
|
if (!condition) {
|
|
|
|
Logger.info(`conditions aren't filled anymore in publication ${this._name}:
|
|
|
|
user.role === ROLE_MODERATOR :${condition}, user.role: ${user.role} ROLE_MODERATOR: ${ROLE_MODERATOR}`);
|
|
|
|
}
|
2019-03-08 00:33:34 +08:00
|
|
|
|
2021-09-07 04:51:42 +08:00
|
|
|
return condition;
|
|
|
|
};
|
|
|
|
publicationSafeGuard(comparisonFunc, this);
|
|
|
|
}
|
2018-09-10 23:34:25 +08:00
|
|
|
const options = {
|
|
|
|
fields: {
|
|
|
|
password: false,
|
2020-05-21 03:54:08 +08:00
|
|
|
'welcomeProp.modOnlyMessage': false,
|
2018-09-10 23:34:25 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-10-15 01:00:25 +08:00
|
|
|
if (User.role !== ROLE_MODERATOR) {
|
|
|
|
options.fields.learningDashboardAccessToken = false;
|
2021-07-16 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2018-09-10 23:34:25 +08:00
|
|
|
return Meetings.find(selector, options);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundMeetings = meetings.bind(this);
|
2018-11-06 03:30:37 +08:00
|
|
|
return boundMeetings(...args);
|
2017-06-06 03:12:06 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
Meteor.publish('meetings', publish);
|
2019-08-22 01:42:37 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function recordMeetings() {
|
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 RecordMeetings was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return RecordMeetings.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
|
|
|
|
Logger.debug(`Publishing RecordMeetings for ${meetingId} ${userId}`);
|
2019-08-22 01:42:37 +08:00
|
|
|
|
|
|
|
return RecordMeetings.find({ meetingId });
|
|
|
|
}
|
|
|
|
function recordPublish(...args) {
|
2019-09-09 22:29:59 +08:00
|
|
|
const boundRecordMeetings = recordMeetings.bind(this);
|
|
|
|
return boundRecordMeetings(...args);
|
2019-08-22 01:42:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('record-meetings', recordPublish);
|
2019-09-09 22:29:59 +08:00
|
|
|
|
2022-01-21 01:50:16 +08:00
|
|
|
function layoutMeetings() {
|
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing LayoutMeetings was requested by unauth connection ${this.connection.id}`);
|
|
|
|
return LayoutMeetings.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
|
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
|
|
|
|
Logger.debug(`Publishing LayoutMeetings for ${meetingId} ${userId}`);
|
|
|
|
|
|
|
|
return LayoutMeetings.find({ meetingId });
|
|
|
|
}
|
|
|
|
|
|
|
|
function layoutPublish(...args) {
|
|
|
|
const boundLayoutMeetings = layoutMeetings.bind(this);
|
|
|
|
return boundLayoutMeetings(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('layout-meetings', layoutPublish);
|
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
function meetingTimeRemaining() {
|
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 MeetingTimeRemaining was requested by unauth connection ${this.connection.id}`);
|
2020-02-07 04:47:28 +08:00
|
|
|
return MeetingTimeRemaining.find({ meetingId: '' });
|
|
|
|
}
|
2020-09-02 00:31:11 +08:00
|
|
|
|
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
Logger.debug(`Publishing MeetingTimeRemaining for ${meetingId} ${userId}`);
|
2019-09-09 22:29:59 +08:00
|
|
|
|
2019-09-09 22:48:50 +08:00
|
|
|
return MeetingTimeRemaining.find({ meetingId });
|
2019-09-09 22:29:59 +08:00
|
|
|
}
|
|
|
|
function timeRemainingPublish(...args) {
|
|
|
|
const boundtimeRemaining = meetingTimeRemaining.bind(this);
|
|
|
|
return boundtimeRemaining(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('meeting-time-remaining', timeRemainingPublish);
|
2022-03-11 03:33:25 +08:00
|
|
|
|
|
|
|
function notifications() {
|
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
2022-04-13 00:56:54 +08:00
|
|
|
if (tokenValidation && tokenValidation.validationStatus === ValidationStates.VALIDATED) {
|
2022-03-11 03:33:25 +08:00
|
|
|
notificationEmitter.on('notification', (notification) => {
|
|
|
|
const { meetingId, userId } = tokenValidation;
|
|
|
|
switch (notification.type) {
|
|
|
|
case 'notifyAllInMeeting':
|
2022-03-31 22:43:58 +08:00
|
|
|
if (notification.meetingId === meetingId) this.added('notifications', Random.id(), notification);
|
2022-03-11 03:33:25 +08:00
|
|
|
break;
|
|
|
|
case 'NotifyUserInMeeting':
|
2022-03-31 22:43:58 +08:00
|
|
|
if (notification.meetingId === meetingId && notification.userId === userId) this.added('notifications', Random.id(), notification);
|
2022-03-11 03:33:25 +08:00
|
|
|
break;
|
|
|
|
case 'NotifyRoleInMeeting': {
|
|
|
|
const user = Users.findOne({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
|
2022-03-31 22:43:58 +08:00
|
|
|
if (notification.meetingId === meetingId && notification.role === user.role) this.added('notifications', Random.id(), notification);
|
2022-03-11 03:33:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: Logger.warn(`wrong type: ${notification.type} userId: ${userId}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.ready();
|
|
|
|
} else {
|
|
|
|
Logger.warn(`Publishing notification was requested by unauth connection ${this.connection.id}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function notificationsPublish(...args) {
|
|
|
|
const boundNotifications = notifications.bind(this);
|
|
|
|
return boundNotifications(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('notifications', notificationsPublish);
|