2017-02-24 01:46:03 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import { inReplyToHTML5Client } from '/imports/api/common/server/helpers';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
|
|
|
|
import addUser from '../modifiers/addUser';
|
|
|
|
import removeUser from '../modifiers/removeUser';
|
|
|
|
|
|
|
|
export default function handleGetUsers({ payload }) {
|
|
|
|
if (!inReplyToHTML5Client({ payload })) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const meetingId = payload.meeting_id;
|
|
|
|
const users = payload.users;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
2017-02-24 04:26:34 +08:00
|
|
|
const usersIds = users.map(m => m.userid);
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
const usersToRemove = Users.find({
|
|
|
|
meetingId,
|
|
|
|
userId: { $nin: usersIds },
|
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
usersToRemove.forEach(user => removeUser(meetingId, user.userId));
|
|
|
|
|
|
|
|
let usersAdded = [];
|
|
|
|
users.forEach(user => {
|
|
|
|
usersAdded.push(addUser(meetingId, user));
|
|
|
|
});
|
|
|
|
|
|
|
|
return usersAdded;
|
|
|
|
};
|