bigbluebutton-Github/bigbluebutton-html5/imports/api/breakouts/server/handlers/joinedUsersChanged.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

import Breakouts from '/imports/api/breakouts';
2021-11-22 22:25:21 +08:00
import updateUserBreakoutRoom from '/imports/api/users-persistent-data/server/modifiers/updateUserBreakoutRoom';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
2022-12-14 02:00:13 +08:00
import { lowercaseTrim } from '/imports/utils/string-utils';
export default function joinedUsersChanged({ body }) {
check(body, Object);
const {
parentId,
breakoutId,
users,
} = body;
check(parentId, String);
check(breakoutId, String);
check(users, Array);
const selector = {
parentMeetingId: parentId,
breakoutId,
};
2022-12-14 02:00:13 +08:00
const usersMapped = users.map(user => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
const modifier = {
$set: {
joinedUsers: usersMapped,
},
};
Breakouts.updateAsync(selector, modifier).then((res) => {
if (res.numberAffected) {
updateUserBreakoutRoom(parentId, breakoutId, users);
Logger.info(`Updated joined users in breakout id=${breakoutId}`);
}
}).catch((err) => {
Logger.error(`updating joined users in breakout: ${err}`);
});
}