bigbluebutton-Github/bigbluebutton-html5/imports/api/users-settings/server/publishers.js
2020-06-02 09:46:03 -03:00

52 lines
1.5 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import UserSettings from '/imports/api/users-settings';
import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import User from '/imports/api/users';
function userSettings() {
if (!this.userId) {
return UserSettings.find({ meetingId: '' });
}
const { meetingId, requesterUserId } = extractCredentials(this.userId);
const currentUser = User.findOne({ userId: requesterUserId });
if (currentUser && currentUser.breakoutProps.isBreakoutUser) {
const { parentId } = currentUser.breakoutProps;
const [externalId] = currentUser.extId.split('-');
const mainRoomUserSettings = UserSettings.find({ meetingId: parentId, userId: externalId });
mainRoomUserSettings.map(({ setting, value }) => ({
meetingId,
setting,
userId: requesterUserId,
value,
})).forEach((doc) => {
const selector = {
meetingId,
setting: doc.setting,
};
UserSettings.upsert(selector, doc);
});
Logger.debug(`Publishing user settings for user=${requesterUserId}`);
return UserSettings.find({ meetingId, userId: requesterUserId });
}
Logger.debug(`Publishing user settings for user=${requesterUserId}`);
return UserSettings.find({ meetingId, userId: requesterUserId });
}
function publish(...args) {
const boundUserSettings = userSettings.bind(this);
return boundUserSettings(...args);
}
Meteor.publish('users-settings', publish);