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 stringHash from 'string-hash';
|
|
|
|
import flat from 'flat';
|
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
|
|
|
|
|
|
|
const COLOR_LIST = [
|
2018-05-30 00:40:50 +08:00
|
|
|
'#7b1fa2', '#6a1b9a', '#4a148c', '#5e35b1', '#512da8', '#4527a0',
|
2017-10-12 09:02:23 +08:00
|
|
|
'#311b92', '#3949ab', '#303f9f', '#283593', '#1a237e', '#1976d2', '#1565c0',
|
2018-05-30 00:40:50 +08:00
|
|
|
'#0d47a1', '#0277bd', '#01579b',
|
2017-10-12 09:02:23 +08:00
|
|
|
];
|
2017-02-24 01:46:03 +08:00
|
|
|
|
2020-07-17 23:08:02 +08:00
|
|
|
export default function addUser(meetingId, userData) {
|
|
|
|
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,
|
|
|
|
presenter: Boolean,
|
|
|
|
locked: Boolean,
|
|
|
|
avatar: String,
|
2021-11-29 21:44:14 +08:00
|
|
|
pin: Boolean,
|
2018-06-27 03:27:42 +08:00
|
|
|
clientType: String,
|
2017-10-12 09:02:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const userId = user.intId;
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
2018-09-07 06:33:32 +08:00
|
|
|
const Meeting = Meetings.findOne({ meetingId });
|
2017-04-28 04:07:27 +08:00
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
/* While the akka-apps dont generate a color we just pick one
|
|
|
|
from a list based on the userId */
|
|
|
|
const color = COLOR_LIST[stringHash(user.intId) % COLOR_LIST.length];
|
2017-06-05 22:16:19 +08:00
|
|
|
|
2021-08-12 03:46:26 +08:00
|
|
|
const userInfos = {
|
|
|
|
meetingId,
|
|
|
|
sortName: user.name.trim().toLowerCase(),
|
|
|
|
color,
|
|
|
|
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,
|
|
|
|
...flat(user),
|
|
|
|
};
|
2017-02-24 01:46:03 +08:00
|
|
|
|
2021-03-20 04:12:27 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: userInfos,
|
|
|
|
};
|
|
|
|
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
|
|
|
|
if (user.clientType !== 'dial-in-user' && !VoiceUsers.findOne({ meetingId, intId: userId })) {
|
2018-10-25 02:40:38 +08:00
|
|
|
addVoiceUser(meetingId, {
|
|
|
|
voiceUserId: '',
|
|
|
|
intId: userId,
|
|
|
|
callerName: user.name,
|
|
|
|
callerNum: '',
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
const partialUser = Users.findOne(selector);
|
|
|
|
|
|
|
|
if (partialUser?.presenter) {
|
|
|
|
modifier.$set.presenter = true;
|
|
|
|
}
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
|
|
|
const { insertedId } = Users.upsert(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
|
|
|
}
|