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

65 lines
1.4 KiB
JavaScript
Raw Normal View History

import Breakouts from '/imports/api/breakouts';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
export default function userBreakoutChanged({ body }) {
check(body, Object);
const {
meetingId,
userId,
fromBreakoutId,
toBreakoutId,
redirectToHtml5JoinURL,
} = body;
check(meetingId, String);
check(userId, String);
check(fromBreakoutId, String);
check(toBreakoutId, String);
check(redirectToHtml5JoinURL, String);
const oldBreakoutSelector = {
parentMeetingId: meetingId,
breakoutId: fromBreakoutId,
};
const newBreakoutSelector = {
parentMeetingId: meetingId,
breakoutId: toBreakoutId,
};
const oldModifier = {
$unset: {
[`url_${userId}`]: '',
},
};
const newModifier = {
$set: {
[`url_${userId}`]: {
redirectToHtml5JoinURL,
insertedTime: new Date().getTime(),
},
},
};
try {
2022-04-13 00:56:54 +08:00
let numberAffectedRows = 0;
2022-04-13 00:56:54 +08:00
if (oldBreakoutSelector.breakoutId !== '') {
numberAffectedRows += Breakouts.update(oldBreakoutSelector, oldModifier);
}
if (newBreakoutSelector.breakoutId !== '') {
numberAffectedRows += Breakouts.update(newBreakoutSelector, newModifier);
}
if (numberAffectedRows > 0) {
Logger.info(`Updated user breakout for userId=${userId}`);
}
} catch (err) {
Logger.error(`Updating user breakout: ${err}`);
}
}