2017-02-24 01:46:03 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-09-07 06:33:32 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2018-10-25 02:40:38 +08:00
|
|
|
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';
|
2017-02-24 01:46:03 +08:00
|
|
|
|
2017-10-12 10:00:28 +08:00
|
|
|
import addVoiceUser from '/imports/api/voice-users/server/modifiers/addVoiceUser';
|
2017-10-12 09:02:23 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async function addUser(meetingId, userData) {
|
2020-07-17 23:08:02 +08:00
|
|
|
const user = userData;
|
|
|
|
|
2017-02-24 01:46:03 +08:00
|
|
|
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,
|
2018-08-16 00:45:00 +08:00
|
|
|
waitingForAcceptance: Match.Maybe(Boolean),
|
2018-01-12 04:05:19 +08:00
|
|
|
guestStatus: String,
|
2017-10-12 09:02:23 +08:00
|
|
|
emoji: String,
|
2023-06-08 09:10:07 +08:00
|
|
|
reactionEmoji: String,
|
|
|
|
raiseHand: Boolean,
|
|
|
|
away: Boolean,
|
2017-10-12 09:02:23 +08:00
|
|
|
presenter: Boolean,
|
|
|
|
locked: Boolean,
|
|
|
|
avatar: String,
|
2024-07-09 20:13:11 +08:00
|
|
|
webcamBackground: String,
|
2023-04-07 03:39:05 +08:00
|
|
|
color: String,
|
2021-11-29 21:44:14 +08:00
|
|
|
pin: Boolean,
|
2018-06-27 03:27:42 +08:00
|
|
|
clientType: String,
|
2024-06-26 23:39:39 +08:00
|
|
|
userCustomData: Match.Optional(Match.Any),
|
2017-10-12 09:02:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const userId = user.intId;
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
2023-04-01 04:40:41 +08:00
|
|
|
const Meeting = await Meetings.findOneAsync({ meetingId });
|
2017-04-28 04:07:27 +08:00
|
|
|
|
2024-06-26 23:39:39 +08:00
|
|
|
const { userCustomData, ...restOfUser } = user;
|
|
|
|
|
2021-08-12 03:46:26 +08:00
|
|
|
const userInfos = {
|
|
|
|
meetingId,
|
2022-12-14 02:00:13 +08:00
|
|
|
sortName: lowercaseTrim(user.name),
|
2022-04-14 21:59:54 +08:00
|
|
|
speechLocale: '',
|
2021-08-12 03:46:26 +08:00
|
|
|
mobile: false,
|
|
|
|
breakoutProps: {
|
|
|
|
isBreakoutUser: Meeting.meetingProp.isBreakout,
|
|
|
|
parentId: Meeting.breakoutProps.parentId,
|
2021-03-20 04:12:27 +08:00
|
|
|
},
|
2021-08-12 03:46:26 +08:00
|
|
|
effectiveConnectionType: null,
|
|
|
|
inactivityCheck: false,
|
|
|
|
responseDelay: 0,
|
|
|
|
loggedOut: false,
|
2022-01-07 05:07:22 +08:00
|
|
|
left: false,
|
2024-06-26 23:39:39 +08:00
|
|
|
...flat(restOfUser),
|
2021-08-12 03:46:26 +08:00
|
|
|
};
|
2017-02-24 01:46:03 +08:00
|
|
|
|
2021-03-20 04:12:27 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: userInfos,
|
|
|
|
};
|
2023-04-01 04:40:41 +08:00
|
|
|
await addUserPsersistentData(userInfos);
|
2019-06-14 02:33:11 +08:00
|
|
|
// 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
|
2023-04-01 04:40:41 +08:00
|
|
|
const voiceUser = await VoiceUsers.findOneAsync({ meetingId, intId: userId });
|
|
|
|
if (user.clientType !== 'dial-in-user' && !voiceUser) {
|
|
|
|
await addVoiceUser(meetingId, {
|
2018-10-25 02:40:38 +08:00
|
|
|
voiceUserId: '',
|
|
|
|
intId: userId,
|
|
|
|
callerName: user.name,
|
|
|
|
callerNum: '',
|
2023-04-19 23:16:35 +08:00
|
|
|
color: user.color,
|
2018-10-25 02:40:38 +08:00
|
|
|
muted: false,
|
|
|
|
talking: false,
|
|
|
|
callingWith: '',
|
|
|
|
listenOnly: false,
|
|
|
|
voiceConf: '',
|
|
|
|
joined: false,
|
|
|
|
});
|
|
|
|
}
|
2017-10-12 09:02:23 +08:00
|
|
|
|
2021-08-12 03:46:26 +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
|
|
|
|
*/
|
2023-04-01 04:40:41 +08:00
|
|
|
const partialUser = await Users.findOneAsync(selector);
|
2021-08-12 03:46:26 +08:00
|
|
|
|
|
|
|
if (partialUser?.presenter) {
|
|
|
|
modifier.$set.presenter = true;
|
|
|
|
}
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-04-01 04:40:41 +08:00
|
|
|
const { insertedId } = await Users.upsertAsync(selector, modifier);
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
if (insertedId) {
|
2020-11-23 21:13:46 +08:00
|
|
|
Logger.info(`Added user id=${userId} meeting=${meetingId}`);
|
|
|
|
} else {
|
|
|
|
Logger.info(`Upserted user id=${userId} meeting=${meetingId}`);
|
2017-02-24 01:46:03 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding user to collection: ${err}`);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|