Skip to content

Include moderators when randomly assigning users to breakout rooms if all remaining users are moderators - #25021

Closed
ramonlsouza wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
ramonlsouza:issue-20402
Closed

ramonlsouza wants to merge 1 commit into
bigbluebutton:v3.0.x-developfrom
ramonlsouza:issue-20402

Conversation

@ramonlsouza

Copy link
Copy Markdown
Member

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

  1. join a meeting with a moderator and a viewer
  2. open the modal to create breakout rooms
  3. click the "Assign viewers randomly"
  4. it should randomly move the viewer to a room and the button label should change to "Assign moderators randomly"
  5. click the "Assign moderators randomly" button
  6. it should randomly move the moderator to a room and the button label should change to "Unassign Users"

@coderabbitai

coderabbitai Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This change extends the breakout room user assignment feature to handle the case where all remaining unassigned users are moderators. The implementation introduces a new randomlyAssignModerators handler function and corresponding UI button that becomes visible when all unassigned users are detected as moderators. The component hierarchy now validates whether unassigned users are moderators and conditionally renders either an "Assign viewers randomly" or "Assign moderators randomly" button accordingly. Localization strings are updated to distinguish between assigning viewers and moderators. The state management layer includes the new assignment function mirroring the existing random assignment logic but filtered for moderators.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: adding moderator inclusion logic to the breakout room random assignment feature when all remaining users are moderators.
Description check ✅ Passed The description is related to the changeset, explaining what the PR does, referencing the closed issue, and providing clear testing steps for validating the new three-state button behavior.
Linked Issues check ✅ Passed The code changes fully implement issue #20402 requirements: three button states for random assignment (viewers only, moderators only, unassign), new UI label and logic in components, moderator-specific assignment function, and updated localization strings.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the three-state random assignment feature for breakout rooms; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026 •

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
28.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 value

Consider renaming leastOneUserIsValid to reflect its current meaning.

The expression (rooms[0]?.users?.length ?? 0) === 0 evaluates to true when no users are in the unassigned bucket — i.e., when everyone has been placed. The prop name leastOneUserIsValid reads as "at least one user is valid", which is roughly the opposite of what it now expresses. This is a downstream prop on ManageRoomLabel, so it's a small cross-file rename, but it will save future readers the same double-take.

Suggested name: allUsersAssigned (or noUnassignedUsers). 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 win

Extract shared assignment logic to remove duplication and clarify intent.

randomlyAssignModerators is a near-verbatim copy of randomlyAssign (lines 140–169) with two differences: (1) the candidate filter, and (2) whether already-assigned users are re-shuffled. randomlyAssign filters !user.isModerator and re-shuffles all viewers regardless of current assignment, while randomlyAssignModerators further 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

📥 Commits

Reviewing files that changed from the base of the PR and between d16d1a9 and 50bad8d.

📒 Files selected for processing (5)
  • bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/breakout-room-user-assignment/component.tsx
  • bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/manage-room-label/component.tsx
  • bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/component.tsx
  • bigbluebutton-html5/imports/ui/components/breakout-room/create-breakout-room/room-managment-state/types.ts
  • bigbluebutton-html5/public/locales/en.json

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

🚨 Automated tests failed

@ramonlsouza
ramonlsouza changed the base branch from v3.0.x-develop to v4.0.x-develop May 8, 2026 18:33
@ramonlsouza
ramonlsouza changed the base branch from v4.0.x-develop to v3.0.x-develop May 8, 2026 18:36
@antobinary antobinary added this to the Release 3.0 milestone May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include moderators when randomly assigning users to breakout rooms if all remaining users are moderators

2 participants