Skip to content

[Feature:Forum] Unique anonymous names#12459

Open
GarvitKhandelwal31 wants to merge 15 commits intoSubmitty:mainfrom
GarvitKhandelwal31:improve-chat-anon-names
Open

[Feature:Forum] Unique anonymous names#12459
GarvitKhandelwal31 wants to merge 15 commits intoSubmitty:mainfrom
GarvitKhandelwal31:improve-chat-anon-names

Conversation

@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor

@GarvitKhandelwal31 GarvitKhandelwal31 commented Feb 22, 2026

Why is this Change Important & Necessary?

Fixes #11999

Live Chat anonymous names were previously deterministic/predictable and could collide.
This PR switches to random anonymous naming with persistence so users keep a stable name during a chat session lifecycle, while still allowing instructors to reshuffle names when needed.

What is the New Behavior?

  • Anonymous names now include a random suffix in the format: Anonymous #XXXX.
  • Anonymous names are persisted per user/chatroom.
  • The same anonymous user keeps the same name across refresh/rejoin until a shuffle occurs.
  • Instructors can click Shuffle Names to regenerate anonymous names.
  • Shuffle Names is visible whenever anonymous mode is enabled.
  • Shuffle Names remains on the same dashboard row as other controls.
  • Shuffle Names uses Submitty utility styling (white/blue).
  • Repeated Shuffle Names clicks work correctly.

Join/Shuffle Message Cases (Exact Text)

  1. On chatroom join (any user):

    • You have successfully joined as <displayName>.
  2. When instructor clicks Shuffle Names (success toast on click action):

    • Anonymous names have been shuffled!
  3. When clients receive shuffle socket event (broadcast/system toast):

    • Anonymous names have been shuffled by the instructor.
  4. For anonymous users after shuffle (personal name update toast):

    • Your anonymous name is now <newName>.

Steps to Test

  1. Create or open a chatroom with Allow Anonymous enabled.
  2. Join as anonymous user and record displayed anonymous name.
  3. Leave/rejoin and confirm name persists.
  4. As instructor, click Shuffle Names once and confirm anonymous names update.
  5. Click Shuffle Names multiple times and confirm names continue updating each time.
  6. Verify dashboard button placement and styling.
  7. Verify join/shuffle message text cases listed above.
  8. Also when anonymous name i disabled the shuffle button disappears.

Automated Testing & Documentation

  • Added basic Cypress coverage for repeated anonymous-name shuffling behavior in live chat.
  • Added/updated PR documentation for join/shuffle message scenarios.
  • Added UI screenshots for dashboard and shuffle behavior.

Screenshots

The below image shows hashing is working correctly.
image

Now if a user leaves and joins again he gets the same name showing persistent naming.
image

When pressed shuffle anonymous names are shuffled correctly.
image

Other Information

  • Non-breaking change.
  • Follow-up suggested: improve instructor visibility of real-name to anonymous-name mapping.

…uffix

- Add chatroom_anonymous_names table for persistent anonymous IDs
- Generate truly random names instead of hashing
- Format: Anonymous [Adjective] [Noun] #XXXX
- Persist across leave/rejoin, logout, cookie clear
- Add Shuffle Names button for instructors
@github-project-automation github-project-automation bot moved this to Seeking Reviewer in Submitty Development Feb 22, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title Fixes #11999 - Improve Live Chat anonymous naming [Feature:Forum] Improve Live Chat anonymous naming Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Feature:Forum] Improve Live Chat anonymous naming [Feature] Improve chat anon naming Feb 23, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 changed the title [Feature] Improve chat anon naming [Feature:Forum] Unique anonymous names Feb 23, 2026
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

Hi @williamschen23, could you please approve the workflows for this PR when you have a moment so the CI checks can initiate? Thank you!

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 0% with 113 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.17%. Comparing base (64774d8) to head (3c28b15).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12459      +/-   ##
============================================
+ Coverage     21.66%   23.17%   +1.51%     
- Complexity     9638     9658      +20     
============================================
  Files           268      247      -21     
  Lines         36223    33625    -2598     
  Branches        486        0     -486     
============================================
- Hits           7847     7792      -55     
+ Misses        27894    25833    -2061     
+ Partials        482        0     -482     
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js ?
migrator 100.00% <ø> (ø)
php 20.62% <0.00%> (-0.07%) ⬇️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Eli-J-Schwartz
Copy link
Copy Markdown
Contributor

Hi @GarvitKhandelwal31, it looks like you're missing a closing curly-bracket on line 200 of chatroom.js, which is causing most of the CI tests to fail. If you fix this I will re-approve the CI workflows to run.

@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

@Eli-J-Schwartz I have added the bracket in the latest commit. Can you please re-run workflows now?
Thanks

…ith persistent storage

- Merge changes from upstream/main for read-only chat feature (PR Submitty#12428)
- Resolve Chatroom.php conflict: combine anonymous name functions with read-only methods
- Fix JavaScript lint errors: remove line continuation after else clause, add parentheses to arrow function
- Fix migration idempotency: check for table/column existence before creating
- All migrations complete successfully
- Ready for PR review
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

@Eli-J-Schwartz Can you please re-run workflows. It should pass now.

Copilot AI review requested due to automatic review settings February 26, 2026 19:50
@automateprojectmangement automateprojectmangement bot moved this from Seeking Reviewer to In Review in Submitty Development Feb 26, 2026
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

I've fixed all the failing workflows:

Database Migrations:

  • Fixed 1st migration (20250222150000): Added check before CREATE TABLE to prevent "DuplicateTable" errors on re-runs
  • Fixed 2nd migration (20250222150100): Replaced buggy ResultProxy checks with proper database.table_has_column() to prevent "DuplicateColumn" errors

Schema Dump Mismatch:

  • Updated course_tables.sql with chatroom_anonymous_names table definition so DB check passes

PHP (PHPCS):

  • Fixed 8 violations: header spacing, trailing whitespace, Stroustrup catch formatting

JavaScript Linting:

  • Fixed 2 violations: separated else statement and added parentheses to arrow function parameter

Cypress Test Failure:

  • Fixed getHostId() return type from int to string (was causing type mismatch in anonymous chat)
  • Corrected typo: "Hack" → "Hawk"

Can you please re-run?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements improved anonymous naming for Live Chat by switching from deterministic/predictable name generation to persistent, randomly generated anonymous display names stored in the course database, plus an instructor action to reshuffle names.

Changes:

  • Adds a chatroom_anonymous_names table (and Doctrine entity) to persist per-(chatroom,user) anonymous display names.
  • Updates chatroom anonymous name generation to read/write the persisted name and include a #XXXX suffix.
  • Adds an instructor-only “Shuffle Names” UI action and socket event handling to regenerate names for a chatroom.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
site/public/templates/chat/ChatroomRow.twig Adds “Shuffle Names” button for active anonymous-enabled chatrooms.
site/app/templates/chat/ChatroomRow.twig Same “Shuffle Names” button addition for server-side twig template.
site/public/js/chatroom.js Adds AJAX call for reshuffling and client handling of the anon_names_regenerated socket event.
site/app/views/ChatroomView.php Uses the new calcAnonName(..., EntityManager) signature so names can persist via DB.
site/app/entities/chat/ChatroomAnonymousName.php New Doctrine entity for persisted anonymous display names.
site/app/entities/chat/Chatroom.php Reworks anonymous name generation to persist and adds bulk regeneration helper.
site/app/controllers/ChatroomController.php Adds instructor-only endpoint to regenerate names and broadcasts socket message.
migration/migrator/migrations/course/20250222150000_chatroom_anonymous_names.py Creates chatroom_anonymous_names table and supporting index.
migration/migrator/migrations/course/20250222150100_chatroom_anonymous_names_display_name.py Migration path for legacy schema to new display_name column.
migration/migrator/data/course_tables.sql Adds chatroom_anonymous_names table + PK + index to baseline schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@JManion32 JManion32 left a comment

Choose a reason for hiding this comment

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

This must've been a lot of work, great job! Please include screenshots of user interface changes, specifically the dashboard where the Shuffle Names button is now located:
Image

A few things regarding the functionality here:

  1. If the chat allows users to join anonymously, the Shuffle Names button should be visible, rather than only being visible when the session has started.
  2. The dashboard for chatrooms is starting to become cluttered. How can we improve the user interface without obscuring features? A solid solution to this should probably be a separate PR, but for now, I think we should start by keeping the Shuffle Names button on the same row as the rest of the buttons on the table
  3. The Shuffle Names button should be white and blue, like all other utility buttons on Submitty.
  4. When a session has started and I click the Shuffle Names button, the functionality works as intended. Any subsequent attempts to click the button does not shuffle the names.

Some other thoughts:

  1. Please add documentation to your description for the different "join messages" that can occur for the user when the instructor clicks Shuffle Names. I noticed it in the code, but if I hadn't, it would've gone untested.
  2. Can we add a basic Cypress test to support this change? I can't imagine it would be too much work especially since live_chat.spec.js is already pretty thorough.
  3. There should be a follow-up to this that allows instructors to more easily view the real names of anonymous chatters.

Overall, great work here! I will likely conduct a more thorough review later, but I think this is a good starting point. Feel free to ping me here if you have any questions.

@github-project-automation github-project-automation bot moved this from In Review to Work in Progress in Submitty Development Feb 26, 2026
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

GarvitKhandelwal31 commented Mar 1, 2026

@JManion32 Addressed requested changes and updated this PR for re-review.

Shuffle Names is now visible whenever anonymous mode is enabled.
Button remains on the same dashboard row and uses standard white/blue utility styling.
Fixed repeated shuffle behavior (multiple clicks now continue to reshuffle names).
Added Cypress coverage in live_chat.spec.js for multiple shuffles.
Updated PR documentation with the join/shuffle message cases and added screenshots.
Removed vagrant from the current PR diff (the earlier file comment was on a previous commit snapshot).
And also when anonymous names is not enabled the shuffle option is not visible.
Please take another look when you have time—thank you!

@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Mar 1, 2026
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

@williamjallen
Quick coordination note: PR #12478 also targets issue #11999 with overlapping anonymous-name logic.

For my PR, the scope currently includes:

persistent anonymous names with DB-backed storage/migration updates
instructor Shuffle Names behavior + requested UI adjustments
repeated-shuffle fix
Cypress coverage for multi-shuffle flow
join/shuffle message documentation and screenshots
Could you please confirm which PR should be the canonical path for #11999?
I can immediately close/rebase/split this PR based on your direction

Copy link
Copy Markdown
Contributor

@JManion32 JManion32 left a comment

Choose a reason for hiding this comment

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

@GarvitKhandelwal31 I am unable to test your changes due to this error:

Image

I even did a vagrant destroy and vagrant up to verify it was your branch causing it. I assume you will experience this same error on the site, so please resolve before I review any further. Thank you!

@github-project-automation github-project-automation bot moved this from In Review to Work in Progress in Submitty Development Mar 13, 2026
@GarvitKhandelwal31
Copy link
Copy Markdown
Contributor Author

GarvitKhandelwal31 commented Mar 14, 2026

Hi @JManion32, thanks for reporting this. I reproduced the issue and confirmed it was an environment sync problem (missing course migration in s26 sample + runtime site not fully refreshed), not the anonymous naming logic itself.

Run these in vagrant ssh
I fixed it locally with:

cd /usr/local/submitty/GIT_CHECKOUT/Submitty/migration
sudo python3 run_migrator.py -c /usr/local/submitty/config -e course --course s26 sample migrate

cd /usr/local/submitty/GIT_CHECKOUT/Submitty
sudo bash INSTALL_SUBMITTY_HELPER_SITE.sh config=/usr/local/submitty/config
sudo systemctl restart apache2

After that, the chat page loads correctly and the anonymous-name behavior works as expected (including suffix and shuffle flow).

@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Improve Live Chat Anonymous Naming

4 participants