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';
|
2017-02-24 01:46:03 +08:00
|
|
|
|
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-26 01:29:03 +08:00
|
|
|
import changeRole from '/imports/api/users/server/modifiers/changeRole';
|
2018-08-11 03:30:17 +08:00
|
|
|
import setApprovedStatus from '/imports/api/users/server/modifiers/setApprovedStatus';
|
2017-10-12 09:02:23 +08:00
|
|
|
|
2018-07-03 23:13:38 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import addChat from '/imports/api/chat/server/modifiers/addChat';
|
2018-07-03 23:45:44 +08:00
|
|
|
import clearUserSystemMessages from '/imports/api/chat/server/modifiers/clearUserSystemMessages';
|
2018-07-03 23:13:38 +08:00
|
|
|
|
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
|
|
|
|
2018-07-03 23:13:38 +08:00
|
|
|
// add some default welcoming message to the chat (welcome / mod only)
|
|
|
|
const addWelcomingChatMessage = (messageText, meetingId, userId) => {
|
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
|
|
|
|
const message = {
|
|
|
|
message: messageText,
|
|
|
|
fromColor: '0x3399FF',
|
|
|
|
toUserId: userId,
|
|
|
|
toUsername: CHAT_CONFIG.type_system,
|
|
|
|
fromUserId: CHAT_CONFIG.type_system,
|
|
|
|
fromUsername: '',
|
|
|
|
fromTime: (new Date()).getTime(),
|
|
|
|
};
|
|
|
|
|
|
|
|
addChat(meetingId, message);
|
|
|
|
};
|
|
|
|
|
2017-02-24 01:46:03 +08:00
|
|
|
export default function addUser(meetingId, user) {
|
|
|
|
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: Boolean,
|
|
|
|
emoji: String,
|
|
|
|
presenter: Boolean,
|
|
|
|
locked: Boolean,
|
|
|
|
avatar: String,
|
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
|
|
|
check(userId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
2017-04-28 04:07:27 +08:00
|
|
|
const USER_CONFIG = Meteor.settings.public.user;
|
2017-10-26 01:29:03 +08:00
|
|
|
const ROLE_PRESENTER = USER_CONFIG.role_presenter;
|
2017-04-28 04:07:27 +08:00
|
|
|
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
|
|
|
|
const ROLE_VIEWER = USER_CONFIG.role_viewer;
|
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const ALLOW_HTML5_MODERATOR = APP_CONFIG.allowHTML5Moderator;
|
2018-08-11 03:30:17 +08:00
|
|
|
const GUEST_ALWAYS_ACCEPT = "ALWAYS_ACCEPT";
|
2017-04-28 04:07:27 +08:00
|
|
|
|
2018-06-27 03:27:42 +08:00
|
|
|
// override moderator status of html5 client users, depending on a system flag
|
2017-06-03 03:25:02 +08:00
|
|
|
const dummyUser = Users.findOne(selector);
|
2017-10-12 09:02:23 +08:00
|
|
|
let userRole = user.role;
|
|
|
|
|
|
|
|
if (
|
|
|
|
dummyUser &&
|
2018-06-27 03:27:42 +08:00
|
|
|
dummyUser.clientType === 'HTML5' &&
|
|
|
|
userRole === ROLE_MODERATOR &&
|
|
|
|
!ALLOW_HTML5_MODERATOR
|
|
|
|
) {
|
|
|
|
userRole = ROLE_VIEWER;
|
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
|
|
|
|
2017-02-24 01:46:03 +08:00
|
|
|
const modifier = {
|
2017-10-12 09:02:23 +08:00
|
|
|
$set: Object.assign(
|
|
|
|
{
|
|
|
|
meetingId,
|
|
|
|
connectionStatus: 'online',
|
2017-10-26 01:29:03 +08:00
|
|
|
roles: [ROLE_VIEWER.toLowerCase()],
|
2017-10-12 09:02:23 +08:00
|
|
|
sortName: user.name.trim().toLowerCase(),
|
|
|
|
color,
|
|
|
|
},
|
|
|
|
flat(user),
|
|
|
|
),
|
2017-02-24 01:46:03 +08:00
|
|
|
};
|
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
addVoiceUser(meetingId, {
|
|
|
|
voiceUserId: '',
|
|
|
|
intId: userId,
|
|
|
|
callerName: user.name,
|
|
|
|
callerNum: '',
|
|
|
|
muted: false,
|
|
|
|
talking: false,
|
|
|
|
callingWith: '',
|
|
|
|
listenOnly: false,
|
|
|
|
voiceConf: '',
|
|
|
|
joined: false,
|
|
|
|
});
|
|
|
|
|
2017-02-24 01:46:03 +08:00
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Adding user to collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
2018-07-03 23:45:44 +08:00
|
|
|
clearUserSystemMessages(meetingId, userId);
|
|
|
|
|
2018-07-03 23:13:38 +08:00
|
|
|
const Meeting = Meetings.findOne({ meetingId });
|
2018-07-03 23:31:00 +08:00
|
|
|
addWelcomingChatMessage(
|
|
|
|
Meeting.welcomeProp.welcomeMsg,
|
|
|
|
meetingId, userId,
|
|
|
|
);
|
2018-07-03 23:13:38 +08:00
|
|
|
|
2017-10-26 01:29:03 +08:00
|
|
|
if (user.presenter) {
|
|
|
|
changeRole(ROLE_PRESENTER, true, userId, meetingId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userRole === ROLE_MODERATOR) {
|
|
|
|
changeRole(ROLE_MODERATOR, true, userId, meetingId);
|
2018-07-03 23:31:00 +08:00
|
|
|
if (Meeting.welcomeProp.modOnlyMessage) {
|
|
|
|
addWelcomingChatMessage(
|
|
|
|
Meeting.welcomeProp.modOnlyMessage,
|
|
|
|
meetingId, userId,
|
|
|
|
);
|
2018-07-03 23:13:38 +08:00
|
|
|
}
|
2017-10-26 01:29:03 +08:00
|
|
|
}
|
|
|
|
|
2018-08-11 03:30:17 +08:00
|
|
|
if (Meeting.usersProp.guestPolicy === GUEST_ALWAYS_ACCEPT) {
|
|
|
|
setApprovedStatus(meetingId, userId, true);
|
|
|
|
}
|
|
|
|
|
2017-02-24 01:46:03 +08:00
|
|
|
const { insertedId } = numChanged;
|
|
|
|
if (insertedId) {
|
|
|
|
return Logger.info(`Added user id=${userId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
return Logger.info(`Upserted user id=${userId} meeting=${meetingId}`);
|
2017-02-24 01:46:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Users.upsert(selector, modifier, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|