2021-11-11 21:10:31 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-11-22 22:25:21 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2021-11-11 21:10:31 +08:00
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
export default async function updateUserBreakoutRoom(meetingId, breakoutId, users) {
|
2021-11-11 21:10:31 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(breakoutId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
const lastBreakoutRoom = await Breakouts.findOneAsync({ breakoutId }, {
|
2021-11-11 21:10:31 +08:00
|
|
|
fields: {
|
|
|
|
isDefaultName: 1,
|
|
|
|
sequence: 1,
|
|
|
|
shortName: 1,
|
|
|
|
},
|
|
|
|
});
|
2023-03-20 21:21:34 +08:00
|
|
|
await Promise.all(users.map(async (user) => {
|
2021-11-11 21:10:31 +08:00
|
|
|
const userId = user.id.substr(0, user.id.lastIndexOf('-'));
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
userId,
|
|
|
|
meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
lastBreakoutRoom,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2023-03-20 21:21:34 +08:00
|
|
|
await UsersPersistentData.updateAsync(selector, modifier);
|
2021-11-11 21:10:31 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating users persistent data's lastBreakoutRoom to the collection: ${err}`);
|
|
|
|
}
|
2023-03-20 21:21:34 +08:00
|
|
|
}));
|
2021-11-11 21:10:31 +08:00
|
|
|
}
|