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';
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async function handleGetVoiceUsers({ body }, meetingId) {
|
2018-02-07 00:23:51 +08:00
|
|
|
const { users } = body;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const meeting = await Meetings.findOneAsync({ meetingId }, { fields: { 'voiceProp.voiceConf': 1 } });
|
|
|
|
const usersIds = users.map((m) => m.intId);
|
2018-02-07 00:23:51 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const voiceUsersFetch = await VoiceUsers.find({
|
2018-02-07 00:23:51 +08:00
|
|
|
meetingId,
|
|
|
|
intId: { $in: usersIds },
|
2023-04-01 04:40:41 +08:00
|
|
|
}, { fields: { intId: 1 } }).fetchAsync();
|
2018-02-07 00:23:51 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const voiceUsersIdsToUpdate = voiceUsersFetch.map((m) => m.intId);
|
|
|
|
|
|
|
|
await Promise.all(users.map(async (user) => {
|
2019-08-22 20:05:06 +08:00
|
|
|
if (voiceUsersIdsToUpdate.indexOf(user.intId) >= 0) {
|
2018-02-07 00:23:51 +08:00
|
|
|
// user already exist, then update
|
2023-04-01 04:40:41 +08:00
|
|
|
await updateVoiceUser(meetingId, {
|
2018-02-07 00:23:51 +08:00
|
|
|
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,
|
2021-04-09 21:08:59 +08:00
|
|
|
});
|
2018-02-07 00:23:51 +08:00
|
|
|
} else {
|
|
|
|
// user doesn't exist yet, then add it
|
2023-04-01 04:40:41 +08:00
|
|
|
await addVoiceUser(meetingId, {
|
2018-02-07 00:23:51 +08:00
|
|
|
voiceUserId: user.voiceUserId,
|
|
|
|
intId: user.intId,
|
|
|
|
callerName: user.callerName,
|
|
|
|
callerNum: user.callerNum,
|
|
|
|
muted: user.muted,
|
2023-04-19 23:16:35 +08:00
|
|
|
color: user.color,
|
2018-02-07 00:23:51 +08:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
2023-04-01 04:40:41 +08:00
|
|
|
}));
|
2018-02-07 00:23:51 +08:00
|
|
|
// removing extra users already existing in Mongo
|
2023-04-01 04:40:41 +08:00
|
|
|
const voiceUsersToRemove = await VoiceUsers.find({
|
2018-02-07 00:23:51 +08:00
|
|
|
meetingId,
|
|
|
|
intId: { $nin: usersIds },
|
2023-04-01 04:40:41 +08:00
|
|
|
}).fetchAsync();
|
|
|
|
await Promise.all(voiceUsersToRemove.map(async (user) => {
|
|
|
|
await removeVoiceUser(meetingId, {
|
|
|
|
voiceConf: meeting.voiceProp.voiceConf,
|
|
|
|
voiceUserId: user.voiceUserId,
|
|
|
|
intId: user.intId,
|
|
|
|
});
|
2018-02-07 00:23:51 +08:00
|
|
|
}));
|
|
|
|
}
|