Repository navigation
Include moderators when randomly assigning users to breakout rooms if all remaining users are moderators - #25021
ramonlsouza wants to merge 1 commit into
Conversation
WalkthroughThis change extends the breakout room user assignment feature to handle the case where all remaining unassigned users are moderators. The implementation introduces a new Sequence DiagramsequenceDiagram
actor User
participant BreakoutRoomUserAssignment as BreakoutRoomUserAssignment
participant ManageRoomLabel as ManageRoomLabel
participant RoomManagementState as RoomManagementState
Note over User,RoomManagementState: Initial Render - Validation Check
RoomManagementState->>RoomManagementState: Compute allUnassignedAreModerators<br/>(check if all unassigned users are moderators)
RoomManagementState->>BreakoutRoomUserAssignment: Pass randomlyAssignModerators handler<br/>+ validation flags
BreakoutRoomUserAssignment->>ManageRoomLabel: Pass onAssignModeratorsRandomly<br/>+ allUnassignedAreModerators flag
Note over ManageRoomLabel: Conditional Render
alt All unassigned are moderators
ManageRoomLabel->>ManageRoomLabel: Render "Assign moderators randomly" button
else At least one user assigned
ManageRoomLabel->>ManageRoomLabel: Render "Reset assignments" button
else Users exist and can be assigned
ManageRoomLabel->>ManageRoomLabel: Render "Assign viewers randomly" button
end
User->>ManageRoomLabel: Click button
alt Button: Assign moderators randomly
ManageRoomLabel->>RoomManagementState: Trigger onAssignModeratorsRandomly()
RoomManagementState->>RoomManagementState: randomlyAssignModerators()<br/>(filter for moderators,<br/>assign round-robin to rooms,<br/>update state)
else Button: Assign viewers randomly
ManageRoomLabel->>RoomManagementState: Trigger randomlyAssign()
RoomManagementState->>RoomManagementState: randomlyAssign()<br/>(filter for non-moderators,<br/>assign round-robin to rooms,<br/>update state)
end
RoomManagementState->>BreakoutRoomUserAssignment: Update assignment state
BreakoutRoomUserAssignment->>ManageRoomLabel: Re-render with updated validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/breakout-room-user-assignment/component.tsx (1)
361-366: 💤 Low valueConsider renaming
leastOneUserIsValidto reflect its current meaning.The expression
(rooms[0]?.users?.length ?? 0) === 0evaluates totruewhen no users are in the unassigned bucket — i.e., when everyone has been placed. The prop nameleastOneUserIsValidreads as "at least one user is valid", which is roughly the opposite of what it now expresses. This is a downstream prop onManageRoomLabel, so it's a small cross-file rename, but it will save future readers the same double-take.Suggested name:
allUsersAssigned(ornoUnassignedUsers). Not blocking — happy to leave it for a follow-up.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/breakout-room-user-assignment/component.tsx` around lines 361 - 366, The prop leastOneUserIsValid is misnamed because it is true when the unassigned bucket is empty; rename leastOneUserIsValid to a clearer name such as allUsersAssigned (or noUnassignedUsers) in the CreateBreakoutRoom component where it is set ((rooms[0]?.users?.length ?? 0) === 0) and update the downstream prop usage in ManageRoomLabel accordingly so the intent matches the boolean expression across files.bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/component.tsx (1)
171-201: ⚡ Quick winExtract shared assignment logic to remove duplication and clarify intent.
randomlyAssignModeratorsis a near-verbatim copy ofrandomlyAssign(lines 140–169) with two differences: (1) the candidate filter, and (2) whether already-assigned users are re-shuffled.randomlyAssignfilters!user.isModeratorand re-shuffles all viewers regardless of current assignment, whilerandomlyAssignModeratorsfurther restricts to only unassigned moderators. That asymmetry is easy to miss and is not obvious from the code.Consider parameterizing a single helper, e.g.:
♻️ Proposed refactor
- const randomlyAssign = () => { - const updatedUserAssignedRooms = { ...userAssignedRooms }; - const noModerators = users.filter((user) => !user.isModerator); - const userIds = noModerators.sort(() => Math.random() - 0.5).map((user) => user.userId); - const numberOfUsers = noModerators.length; - const assignments = new Array(numberOfUsers); - - // eslint-disable-next-line no-plusplus - for (let i = 0; i < numberOfUsers; i++) { - assignments[i] = (i % numberOfRooms) + 1; - } - - const updatedMovementRegistered = { ...movementRegistered }; - userIds.forEach((userId, index) => { - const roomNumber = assignments[index]; - const runningRoom = runningRooms?.find((r) => r.participants.some((p) => p.user.userId === userId)); - updatedUserAssignedRooms[userId] = [roomNumber]; - updatedMovementRegistered[userId] = { - fromSequence: runningRoom?.sequence ?? 0, - toSequence: roomNumber, - fromRoomId: runningRoom?.breakoutRoomMeetingId, - toRoomId: runningRooms?.find((r) => r.sequence === roomNumber)?.breakoutRoomMeetingId, - }; - }); - setMovementRegistered(updatedMovementRegistered); - setMoveRegisterRef(updatedMovementRegistered); - setUserAssignedRooms(updatedUserAssignedRooms); - }; - - const randomlyAssignModerators = () => { - const updatedUserAssignedRooms = { ...userAssignedRooms }; - const unassignedModerators = users.filter((user) => user.isModerator && ( - (updatedUserAssignedRooms[user.userId] ?? []).length === 0 - || (updatedUserAssignedRooms[user.userId] ?? []).includes(0) - )); - const userIds = unassignedModerators.sort(() => Math.random() - 0.5).map((user) => user.userId); - const numberOfUsers = userIds.length; - const assignments = new Array(numberOfUsers); - - // eslint-disable-next-line no-plusplus - for (let i = 0; i < numberOfUsers; i++) { - assignments[i] = (i % numberOfRooms) + 1; - } - - const updatedMovementRegistered = { ...movementRegistered }; - userIds.forEach((userId, index) => { - const roomNumber = assignments[index]; - const runningRoom = runningRooms?.find((r) => r.participants.some((p) => p.user.userId === userId)); - updatedUserAssignedRooms[userId] = [roomNumber]; - updatedMovementRegistered[userId] = { - fromSequence: runningRoom?.sequence ?? 0, - toSequence: roomNumber, - fromRoomId: runningRoom?.breakoutRoomMeetingId, - toRoomId: runningRooms?.find((r) => r.sequence === roomNumber)?.breakoutRoomMeetingId, - }; - }); - setMovementRegistered(updatedMovementRegistered); - setMoveRegisterRef(updatedMovementRegistered); - setUserAssignedRooms(updatedUserAssignedRooms); - }; + const assignRandomly = (predicate: (user: BreakoutUser, assigned: number[]) => boolean) => { + const updatedUserAssignedRooms = { ...userAssignedRooms }; + const candidates = users.filter((user) => predicate(user, updatedUserAssignedRooms[user.userId] ?? [])); + const userIds = candidates.sort(() => Math.random() - 0.5).map((u) => u.userId); + + const updatedMovementRegistered = { ...movementRegistered }; + userIds.forEach((userId, index) => { + const roomNumber = (index % numberOfRooms) + 1; + const runningRoom = runningRooms?.find((r) => r.participants.some((p) => p.user.userId === userId)); + updatedUserAssignedRooms[userId] = [roomNumber]; + updatedMovementRegistered[userId] = { + fromSequence: runningRoom?.sequence ?? 0, + toSequence: roomNumber, + fromRoomId: runningRoom?.breakoutRoomMeetingId, + toRoomId: runningRooms?.find((r) => r.sequence === roomNumber)?.breakoutRoomMeetingId, + }; + }); + setMovementRegistered(updatedMovementRegistered); + setMoveRegisterRef(updatedMovementRegistered); + setUserAssignedRooms(updatedUserAssignedRooms); + }; + + const randomlyAssign = () => assignRandomly((user) => !user.isModerator); + const randomlyAssignModerators = () => assignRandomly( + (user, assigned) => user.isModerator && (assigned.length === 0 || assigned.includes(0)), + );Beyond DRY, the explicit predicate makes the asymmetric "all viewers vs only unassigned moderators" behavior a deliberate, reviewable decision rather than an accidental copy/paste divergence.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/component.tsx` around lines 171 - 201, randomlyAssignModerators duplicates the core assignment logic in randomlyAssign with only two behavioral differences (candidate filter and whether to reshuffle already-assigned users); extract that common logic into a single helper (e.g., assignUsersToRooms or makeAssignment) that accepts a predicate for selecting candidates (to handle !user.isModerator vs only-unassigned-moderators) and a flag to control reshuffling of already-assigned users, and have both randomlyAssign and randomlyAssignModerators call this helper while preserving existing side-effects (updating userAssignedRooms, movementRegistered, calling setMovementRegistered, setMoveRegisterRef, setUserAssignedRooms) and using the same references (users, userAssignedRooms, runningRooms, movementRegistered) so behavior remains identical except for the intended predicate/reshuffle differences.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bigbluebutton-html5/public/locales/en.json`:
- Line 1372: The locale description "app.createBreakoutRoom.randomlyAssignDesc"
claims it "Assigns unassigned viewers randomly to breakout rooms" but the
function randomlyAssign in room-managment-state/component.tsx actually selects
all non-moderator users (including already-assigned viewers) and reassigns them;
either change randomlyAssign's filter to only include unassigned viewers
(matching the logic used in randomlyAssignModerators) or update the locale
string to accurately describe current behavior (e.g., "Randomly assigns all
viewers to breakout rooms"); reference randomlyAssign
(room-managment-state/component.tsx) and randomlyAssignModerators when making
the choice so the text and implementation stay consistent.
---
Nitpick comments:
In
`@bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/breakout-room-user-assignment/component.tsx`:
- Around line 361-366: The prop leastOneUserIsValid is misnamed because it is
true when the unassigned bucket is empty; rename leastOneUserIsValid to a
clearer name such as allUsersAssigned (or noUnassignedUsers) in the
CreateBreakoutRoom component where it is set ((rooms[0]?.users?.length ?? 0) ===
0) and update the downstream prop usage in ManageRoomLabel accordingly so the
intent matches the boolean expression across files.
In
`@bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/component.tsx`:
- Around line 171-201: randomlyAssignModerators duplicates the core assignment
logic in randomlyAssign with only two behavioral differences (candidate filter
and whether to reshuffle already-assigned users); extract that common logic into
a single helper (e.g., assignUsersToRooms or makeAssignment) that accepts a
predicate for selecting candidates (to handle !user.isModerator vs
only-unassigned-moderators) and a flag to control reshuffling of
already-assigned users, and have both randomlyAssign and
randomlyAssignModerators call this helper while preserving existing side-effects
(updating userAssignedRooms, movementRegistered, calling setMovementRegistered,
setMoveRegisterRef, setUserAssignedRooms) and using the same references (users,
userAssignedRooms, runningRooms, movementRegistered) so behavior remains
identical except for the intended predicate/reshuffle differences.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5fe09e6c-cf7a-4033-b4f2-57448e7a6e04
📒 Files selected for processing (5)
bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/breakout-room-user-assignment/component.tsxbigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/manage-room-label/component.tsxbigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/component.tsxbigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/types.tsbigbluebutton-html5/public/locales/en.json
🚨 Automated tests failed |

What does this PR do?
Implements third state in breakouts randomly assign to randomly assign moderators
Screencast.from.2026-05-06.16-23-08.mp4
Closes Issue(s)
Closes #20402
How to test