bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/addUser.js

109 lines
2.9 KiB
JavaScript
Raw Normal View History

import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import VoiceUsers from '/imports/api/voice-users/';
2021-03-20 04:12:27 +08:00
import addUserPsersistentData from '/imports/api/users-persistent-data/server/modifiers/addUserPersistentData';
2017-10-12 09:02:23 +08:00
import flat from 'flat';
2022-12-14 02:00:13 +08:00
import { lowercaseTrim } from '/imports/utils/string-utils';
import addVoiceUser from '/imports/api/voice-users/server/modifiers/addVoiceUser';
2017-10-12 09:02:23 +08:00
export default async function addUser(meetingId, userData) {
2020-07-17 23:08:02 +08:00
const user = userData;
check(meetingId, String);
2017-02-24 01:59:56 +08:00
2017-10-12 09:02:23 +08:00
check(user, {
intId: String,
extId: String,
name: String,
role: String,
guest: Boolean,
authed: Boolean,
waitingForAcceptance: Match.Maybe(Boolean),
guestStatus: String,
2017-10-12 09:02:23 +08:00
emoji: String,
reactionEmoji: String,
raiseHand: Boolean,
away: Boolean,
2017-10-12 09:02:23 +08:00
presenter: Boolean,
locked: Boolean,
avatar: String,
color: String,
pin: Boolean,
clientType: String,
2017-10-12 09:02:23 +08:00
});
const userId = user.intId;
const selector = {
meetingId,
userId,
};
const Meeting = await Meetings.findOneAsync({ meetingId });
const userInfos = {
meetingId,
2022-12-14 02:00:13 +08:00
sortName: lowercaseTrim(user.name),
speechLocale: '',
mobile: false,
breakoutProps: {
isBreakoutUser: Meeting.meetingProp.isBreakout,
parentId: Meeting.breakoutProps.parentId,
2021-03-20 04:12:27 +08:00
},
effectiveConnectionType: null,
inactivityCheck: false,
responseDelay: 0,
loggedOut: false,
2022-01-07 05:07:22 +08:00
left: false,
...flat(user),
};
2021-03-20 04:12:27 +08:00
const modifier = {
$set: userInfos,
};
await addUserPsersistentData(userInfos);
// Only add an empty VoiceUser if there isn't one already and if the user coming in isn't a
// dial-in user. We want to avoid overwriting good data
const voiceUser = await VoiceUsers.findOneAsync({ meetingId, intId: userId });
if (user.clientType !== 'dial-in-user' && !voiceUser) {
await addVoiceUser(meetingId, {
voiceUserId: '',
intId: userId,
callerName: user.name,
callerNum: '',
color: user.color,
muted: false,
talking: false,
callingWith: '',
listenOnly: false,
voiceConf: '',
joined: false,
});
}
2017-10-12 09:02:23 +08:00
/**
* Add a verification to check if the user was set as presenter.
* In some cases the user information is set after the presenter is set
* causing the first moderator to join a meeting be marked as presenter: false
*/
const partialUser = await Users.findOneAsync(selector);
if (partialUser?.presenter) {
modifier.$set.presenter = true;
}
try {
const { insertedId } = await Users.upsertAsync(selector, modifier);
if (insertedId) {
Logger.info(`Added user id=${userId} meeting=${meetingId}`);
} else {
Logger.info(`Upserted user id=${userId} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Adding user to collection: ${err}`);
}
2017-06-03 03:25:02 +08:00
}