2021-03-20 04:12:27 +08:00
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
import { check } from 'meteor/check';
|
2021-11-22 22:27:30 +08:00
|
|
|
import Users from '/imports/api/users';
|
2021-11-11 21:10:31 +08:00
|
|
|
|
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
2021-03-20 04:12:27 +08:00
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
async function usersPersistentData() {
|
2021-03-20 04:12:27 +08:00
|
|
|
if (!this.userId) {
|
|
|
|
return UsersPersistentData.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
};
|
|
|
|
|
2021-11-11 21:10:31 +08:00
|
|
|
const options = {};
|
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
const User = await Users
|
|
|
|
.findOneAsync({ userId: requesterUserId, meetingId }, { fields: { role: 1 } });
|
2021-11-11 21:10:31 +08:00
|
|
|
if (!User || User.role !== ROLE_MODERATOR) {
|
|
|
|
options.fields = {
|
|
|
|
lastBreakoutRoom: false,
|
|
|
|
};
|
|
|
|
|
2022-01-28 02:45:04 +08:00
|
|
|
// viewers are allowed to see other users' data if:
|
|
|
|
// user is logged in or user sent a message in chat
|
|
|
|
const viewerSelector = {
|
|
|
|
meetingId,
|
|
|
|
$or: [
|
|
|
|
{
|
2022-02-02 21:53:23 +08:00
|
|
|
'shouldPersist.hasMessages': true,
|
2022-01-28 02:45:04 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loggedOut: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-02-09 23:52:42 +08:00
|
|
|
return UsersPersistentData.find(viewerSelector, options);
|
2022-01-28 02:45:04 +08:00
|
|
|
}
|
2021-11-11 21:10:31 +08:00
|
|
|
return UsersPersistentData.find(selector, options);
|
2021-03-20 04:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function publishUsersPersistentData(...args) {
|
|
|
|
const boundUsers = usersPersistentData.bind(this);
|
|
|
|
return boundUsers(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('users-persistent-data', publishUsersPersistentData);
|