bigbluebutton-Github/bigbluebutton-html5/imports/api/users-persistent-data/server/publishers.js
Arthur B. Grossi c7b03ee13d
fix(users-context): phantom user (#20253)
* fix(users-context): add missing logs

* fix(user-persistent-data): collection publication selector for viewers

Fixes the collection's selector when publishing it to viewers.

* fix(users-context): correctly add user persistent data

Changes the logic of the add_user_persistent_data action in users
context, so that the user information already in the context is merged
with the new one. Also, do not flip the logged out status of users added
by user_persisted_data anymore.
2024-09-13 08:49:44 -04:00

58 lines
1.5 KiB
JavaScript

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';
import Users from '/imports/api/users';
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
async function usersPersistentData() {
if (!this.userId) {
return UsersPersistentData.find({ meetingId: '' });
}
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
const selector = {
meetingId,
};
const options = {};
const User = await Users
.findOneAsync({ userId: requesterUserId, meetingId }, { fields: { role: 1 } });
if (!User || User.role !== ROLE_MODERATOR) {
options.fields = {
lastBreakoutRoom: false,
};
// viewers are allowed to see other users' data if:
// user is logged in or user sent a message in chat
const viewerSelector = {
meetingId,
$or: [
{
'shouldPersist.hasMessages.public': true,
},
{
'shouldPersist.hasMessages.private': true,
},
{
loggedOut: false,
},
],
};
return UsersPersistentData.find(viewerSelector, options);
}
return UsersPersistentData.find(selector, options);
}
function publishUsersPersistentData(...args) {
const boundUsers = usersPersistentData.bind(this);
return boundUsers(...args);
}
Meteor.publish('users-persistent-data', publishUsersPersistentData);