bigbluebutton-Github/bigbluebutton-html5/imports/api/breakouts/server/handlers/userBreakoutChanged.js
2022-04-13 14:22:02 -03:00

66 lines
1.4 KiB
JavaScript

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,
freeJoin: false,
};
const newBreakoutSelector = {
parentMeetingId: meetingId,
breakoutId: toBreakoutId,
};
const oldModifier = {
$unset: {
[`url_${userId}`]: '',
},
};
const newModifier = {
$set: {
[`url_${userId}`]: {
redirectToHtml5JoinURL,
insertedTime: new Date().getTime(),
},
},
};
try {
let numberAffectedRows = 0;
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}`);
}
}