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

54 lines
1.4 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';
2023-03-02 00:38:40 +08:00
export default async 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,
};
2023-03-02 00:38:40 +08:00
const usersMapped = users
.map((user) => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
const modifier = {
$set: {
joinedUsers: usersMapped,
},
};
try {
const numberAffected = await Breakouts.updateAsync(selector, modifier);
if (numberAffected) {
await updateUserBreakoutRoom(parentId, breakoutId, users);
Logger.info(`Updated joined users in breakout id=${breakoutId}`);
}
} catch (err) {
Logger.error(`updating joined users in breakout: ${err}`);
2023-03-02 00:38:40 +08:00
}
// .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}`);
// });
}