2018-02-07 00:23:51 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import VoiceUsers from '/imports/api/voice-users/';
|
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import addVoiceUser from '../modifiers/addVoiceUser';
|
|
|
|
import removeVoiceUser from '../modifiers/removeVoiceUser';
|
|
|
|
import updateVoiceUser from '../modifiers/updateVoiceUser';
|
|
|
|
|
|
|
|
export default function handleGetVoiceUsers({ body }, meetingId) {
|
|
|
|
const { users } = body;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
2019-08-22 20:05:06 +08:00
|
|
|
const meeting = Meetings.findOne({ meetingId }, { fields: { 'voiceProp.voiceConf': 1 } });
|
2018-02-07 00:23:51 +08:00
|
|
|
const usersIds = users.map(m => m.intId);
|
|
|
|
|
|
|
|
const voiceUsersIdsToUpdate = VoiceUsers.find({
|
|
|
|
meetingId,
|
|
|
|
intId: { $in: usersIds },
|
2019-08-22 20:05:06 +08:00
|
|
|
}, { fields: { intId: 1 } }).fetch().map(m => m.intId);
|
2018-02-07 00:23:51 +08:00
|
|
|
|
2019-08-22 20:05:06 +08:00
|
|
|
const voiceUsersUpdated = [];
|
|
|
|
users.forEach((user) => {
|
|
|
|
if (voiceUsersIdsToUpdate.indexOf(user.intId) >= 0) {
|
2018-02-07 00:23:51 +08:00
|
|
|
// user already exist, then update
|
|
|
|
voiceUsersUpdated.push(updateVoiceUser(meetingId, {
|
|
|
|
intId: user.intId,
|
|
|
|
voiceUserId: user.voiceUserId,
|
|
|
|
talking: user.talking,
|
|
|
|
muted: user.muted,
|
|
|
|
voiceConf: meeting.voiceProp.voiceConf,
|
2019-08-22 20:05:06 +08:00
|
|
|
joined: true,
|
2018-02-07 00:23:51 +08:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
// user doesn't exist yet, then add it
|
|
|
|
addVoiceUser(meetingId, {
|
|
|
|
voiceUserId: user.voiceUserId,
|
|
|
|
intId: user.intId,
|
|
|
|
callerName: user.callerName,
|
|
|
|
callerNum: user.callerNum,
|
|
|
|
muted: user.muted,
|
|
|
|
talking: user.talking,
|
|
|
|
callingWith: user.callingWith,
|
|
|
|
listenOnly: user.listenOnly,
|
|
|
|
voiceConf: meeting.voiceProp.voiceConf,
|
2019-08-22 20:05:06 +08:00
|
|
|
joined: true,
|
2018-02-07 00:23:51 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// removing extra users already existing in Mongo
|
|
|
|
const voiceUsersToRemove = VoiceUsers.find({
|
|
|
|
meetingId,
|
|
|
|
intId: { $nin: usersIds },
|
|
|
|
}).fetch();
|
|
|
|
voiceUsersToRemove.forEach(user => removeVoiceUser(meetingId, {
|
|
|
|
voiceConf: meeting.voiceProp.voiceConf,
|
|
|
|
voiceUserId: user.voiceUserId,
|
2019-08-22 20:05:06 +08:00
|
|
|
intId: user.intId,
|
2018-02-07 00:23:51 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
return voiceUsersUpdated;
|
|
|
|
}
|