Skip to content

fix: Prevent UI from displaying @@ for federation usernames#39460

Merged
dionisio-bot[bot] merged 4 commits intodevelopfrom
fix/normalize-federation-usernames
Mar 12, 2026
Merged

fix: Prevent UI from displaying @@ for federation usernames#39460
dionisio-bot[bot] merged 4 commits intodevelopfrom
fix/normalize-federation-usernames

Conversation

@aleksandernsilva
Copy link
Copy Markdown
Contributor

@aleksandernsilva aleksandernsilva commented Mar 9, 2026

Proposed changes (including videos or screenshots)

This pull request introduces a new utility function, normalizeUsername, to standardize username handling throughout the codebase.

The goal of the PR is to guarantee that usernames from federation are consistently rendered without leading @ symbols, especially for federated users, preventing issues like double @@ in UI elements.

A few examples of the issue:

  • Members list
Screenshot 2026-03-11 at 10 42 12
  • Files list
Screenshot 2026-03-11 at 10 44 44
  • Mentions popup
Screenshot 2026-03-11 at 10 42 47
  • Moderation
Screenshot 2026-03-11 at 10 43 34

Issue(s)

CORE-1946

Steps to test or reproduce

  1. Create a new federated room
  2. Invite external users
  3. Open members list
  4. External usernames will be displayed with @@

Further comments

Summary by CodeRabbit

  • New Features

    • Consistent username normalization applied across the UI for mentions, autocomplete, message headers, reactions, file items, and moderation views.
  • Bug Fixes

    • Fixed federated users showing duplicate @ symbols and inconsistent username rendering.
  • Tests

    • Added unit tests to validate username normalization behavior.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 9, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: dca691c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b0605f52-03b4-4155-9049-40272e855c9c

📥 Commits

Reviewing files that changed from the base of the PR and between 161ab46 and dca691c.

📒 Files selected for processing (1)
  • apps/meteor/client/components/message/MessageHeader.tsx
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 📦 Meteor Build (coverage)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/components/message/MessageHeader.tsx
🧠 Learnings (6)
📓 Common learnings
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38262
File: apps/meteor/client/lib/utils/normalizeMessagePreview/getMessagePreview.ts:24-33
Timestamp: 2026-01-19T18:17:46.433Z
Learning: In the Rocket.Chat repository, usernames (lastMessage.u.username) and display names (lastMessage.u.name) are sanitized/escaped centrally elsewhere in the system, so individual display functions like getMessagePreview do not need to escape these values before interpolating them into strings.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 Learning: 2026-01-19T18:17:46.433Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38262
File: apps/meteor/client/lib/utils/normalizeMessagePreview/getMessagePreview.ts:24-33
Timestamp: 2026-01-19T18:17:46.433Z
Learning: In the Rocket.Chat repository, usernames (lastMessage.u.username) and display names (lastMessage.u.name) are sanitized/escaped centrally elsewhere in the system, so individual display functions like getMessagePreview do not need to escape these values before interpolating them into strings.

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
📚 Learning: 2026-03-11T15:56:13.132Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 39535
File: apps/meteor/client/views/omnichannel/directory/components/ContactField.tsx:40-46
Timestamp: 2026-03-11T15:56:13.132Z
Learning: In `apps/meteor/client/views/omnichannel/directory/components/ContactField.tsx`, `shortName` is intentionally built from the visitor's internal `username` and `phone` (not from `externalIds`). `ContactField` shows the visitor's internal system identifier. Per-channel external identifiers (e.g. WhatsApp usernames from `externalIds[].username`) are only displayed in `ContactInfoChannelsItem`, which serves a different UI context.

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
📚 Learning: 2025-11-19T18:20:37.116Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
🔇 Additional comments (2)
apps/meteor/client/components/message/MessageHeader.tsx (2)

27-27: LGTM! Import and normalization are correctly implemented.

The normalizeUsername utility is properly imported and applied to derive a normalized username. This aligns with the pattern already established in SystemMessage.tsx (context snippet 3).

Also applies to: 46-46


61-70: LGTM! The bug has been fixed and normalized username is correctly used throughout.

Line 63 now correctly uses the normalizedUsername variable (not the normalizeUsername function), addressing the previously flagged issue. The data-username attribute and display text consistently use the normalized value.

E2E tests will continue to work correctly. The federated usernames in tests are formatted as username:domain (no @ prefix) via formatUsernameAndDomainIntoMatrixFormat. When normalizeUsername processes these values, it leaves them unchanged since there's no leading @ to remove. The test selectors will correctly match the component's data-username attribute.


Walkthrough

Adds a new utility normalizeUsername to strip leading '@' and applies it across multiple UI components and utilities to prevent double-@ display for federated users; includes unit tests and a changeset entry for a patch release.

Changes

Cohort / File(s) Summary
Core Utility & Release
apps/meteor/lib/utils/normalizeUsername.ts, apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts, .changeset/honest-shrimps-cough.md
New normalizeUsername export that strips a leading @; unit tests added; changeset added for a patch release describing the fix.
Message & Component Rendering
apps/meteor/client/components/GazzodownText.tsx, apps/meteor/client/components/message/MessageHeader.tsx, apps/meteor/client/components/message/content/reactions/Reaction.tsx, apps/meteor/client/components/message/variants/SystemMessage.tsx
Replaced inline username trimming with calls to normalizeUsername; components now render and compare normalized usernames.
Autocomplete & Avatars
apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsx
Normalize username from label before using in aria-label, avatar, keys, and display text.
Moderation / Admin Views
apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx, apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx, apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx
Apply normalizeUsername to reported/usernames before passing to UserColumn and rendering in moderation/user reports.
Room Views & Composer
apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx, apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
Use normalized username for image props, display labels, and popup item values instead of raw username.
Display Names Utility
apps/meteor/lib/getUserDisplayNames.ts
Return normalized username in display-name tuples so consumers receive consistent values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main objective: preventing @@ display for federation usernames through a normalization utility.
Linked Issues check ✅ Passed All code changes directly address CORE-1946 by implementing normalizeUsername utility and applying it consistently across UI components to prevent @@username display.
Out of Scope Changes check ✅ Passed All changes are in scope: new normalizeUsername utility, unit tests, and targeted application across username rendering locations in federated user contexts.
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.


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.

@aleksandernsilva aleksandernsilva force-pushed the fix/normalize-federation-usernames branch from 43e61c8 to 1dffc08 Compare March 9, 2026 00:31
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.92%. Comparing base (4f43a85) to head (dca691c).
⚠️ Report is 18 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #39460      +/-   ##
===========================================
- Coverage    70.94%   70.92%   -0.02%     
===========================================
  Files         3196     3198       +2     
  Lines       113288   113369      +81     
  Branches     20542    20565      +23     
===========================================
+ Hits         80376    80412      +36     
- Misses       30865    30906      +41     
- Partials      2047     2051       +4     
Flag Coverage Δ
e2e 60.40% <76.92%> (-0.08%) ⬇️
e2e-api 48.19% <ø> (-0.59%) ⬇️
unit 71.62% <83.87%> (-0.01%) ⬇️

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.

Fixes inconsistent username formatting causing '@@username' for federated users
@aleksandernsilva
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/components/message/MessageHeader.tsx`:
- Around line 61-64: The title prop on the MessageName component is using the
function reference normalizeUsername instead of the computed string variable
normalizedUsername; update the JSX so title uses normalizedUsername (respecting
the existing condition involving showUsername and usernameAndRealNameAreSame) —
locate the MessageName element and replace normalizeUsername with
normalizedUsername in the title attribute so the tooltip shows the actual
username string.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e6430a7-1654-45b0-b3c4-45ae2af652df

📥 Commits

Reviewing files that changed from the base of the PR and between 4f43a85 and 161ab46.

📒 Files selected for processing (14)
  • .changeset/honest-shrimps-cough.md
  • apps/meteor/client/components/GazzodownText.tsx
  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsx
  • apps/meteor/client/components/message/MessageHeader.tsx
  • apps/meteor/client/components/message/content/reactions/Reaction.tsx
  • apps/meteor/client/components/message/variants/SystemMessage.tsx
  • apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx
  • apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • apps/meteor/lib/getUserDisplayNames.ts
  • apps/meteor/lib/utils/normalizeUsername.ts
  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: 🚢 Publish Docker Images (ghcr.io)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
  • apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx
  • apps/meteor/client/components/message/MessageHeader.tsx
  • apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx
  • apps/meteor/lib/utils/normalizeUsername.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • apps/meteor/client/components/GazzodownText.tsx
  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx
  • apps/meteor/client/components/message/content/reactions/Reaction.tsx
  • apps/meteor/client/components/message/variants/SystemMessage.tsx
  • apps/meteor/lib/getUserDisplayNames.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
🧠 Learnings (25)
📓 Common learnings
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38262
File: apps/meteor/client/lib/utils/normalizeMessagePreview/getMessagePreview.ts:24-33
Timestamp: 2026-01-19T18:17:46.433Z
Learning: In the Rocket.Chat repository, usernames (lastMessage.u.username) and display names (lastMessage.u.name) are sanitized/escaped centrally elsewhere in the system, so individual display functions like getMessagePreview do not need to escape these values before interpolating them into strings.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : All test files must be created in `apps/meteor/tests/e2e/` directory

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Group related tests in the same file

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to **/*.spec.ts : Use descriptive test names that clearly communicate expected behavior in Playwright tests

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to **/*.spec.ts : Use `.spec.ts` extension for test files (e.g., `login.spec.ts`)

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2026-03-06T18:09:17.867Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/elements/Timestamp/DateTimeFormats.spec.tsx:20-23
Timestamp: 2026-03-06T18:09:17.867Z
Learning: In the RocketChat/Rocket.Chat gazzodown package (`packages/gazzodown`), tests are intended to run under the UTC timezone, but as of PR `#39397` this is NOT yet explicitly enforced in `jest.config.ts` or the `package.json` test scripts (which just run `jest` without `TZ=UTC`). To make timezone-sensitive snapshot tests reliable across all environments, `TZ=UTC` should be added to the test scripts in `package.json` or to `jest.config.ts` via `testEnvironmentOptions.timezone`. Without explicit UTC enforcement, snapshot tests involving date-fns formatted output or `toLocaleString()` will fail for contributors in non-UTC timezones.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
  • apps/meteor/lib/utils/normalizeUsername.ts
  • apps/meteor/lib/getUserDisplayNames.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
  • apps/meteor/lib/utils/normalizeUsername.ts
  • apps/meteor/lib/getUserDisplayNames.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx
  • apps/meteor/client/components/message/MessageHeader.tsx
  • apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx
  • apps/meteor/lib/utils/normalizeUsername.ts
  • .changeset/honest-shrimps-cough.md
  • apps/meteor/client/components/GazzodownText.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx
  • apps/meteor/client/components/message/variants/SystemMessage.tsx
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx
  • apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx
📚 Learning: 2026-01-19T18:17:46.433Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38262
File: apps/meteor/client/lib/utils/normalizeMessagePreview/getMessagePreview.ts:24-33
Timestamp: 2026-01-19T18:17:46.433Z
Learning: In the Rocket.Chat repository, usernames (lastMessage.u.username) and display names (lastMessage.u.name) are sanitized/escaped centrally elsewhere in the system, so individual display functions like getMessagePreview do not need to escape these values before interpolating them into strings.

Applied to files:

  • apps/meteor/client/components/message/MessageHeader.tsx
  • apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • .changeset/honest-shrimps-cough.md
  • apps/meteor/client/components/message/variants/SystemMessage.tsx
  • apps/meteor/lib/getUserDisplayNames.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • .changeset/honest-shrimps-cough.md
📚 Learning: 2025-09-19T15:15:04.642Z
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 36991
File: apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts:219-221
Timestamp: 2025-09-19T15:15:04.642Z
Learning: The Federation_Matrix_homeserver_domain setting in apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts is part of the old federation system and is being deprecated/removed, so configuration issues with this setting should not be flagged for improvement.

Applied to files:

  • .changeset/honest-shrimps-cough.md
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • .changeset/honest-shrimps-cough.md
📚 Learning: 2026-02-24T19:05:56.710Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 0
File: :0-0
Timestamp: 2026-02-24T19:05:56.710Z
Learning: Rocket.Chat repo context: When a workspace manifest on develop already pins a dependency version (e.g., packages/web-ui-registration → "rocket.chat/ui-contexts": "27.0.1"), a lockfile change in a feature PR that upgrades only that dependency’s resolution is considered a manifest-driven sync and can be kept, preferably as a small "chore: sync yarn.lock with manifests" commit.

Applied to files:

  • .changeset/honest-shrimps-cough.md
📚 Learning: 2025-11-19T18:20:07.720Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: packages/i18n/src/locales/en.i18n.json:918-921
Timestamp: 2025-11-19T18:20:07.720Z
Learning: Repo: RocketChat/Rocket.Chat — i18n/formatting
Learning: This repository uses a custom message formatting parser in UI blocks/messages; do not assume standard Markdown rules. For keys like Call_ended_bold, Call_not_answered_bold, Call_failed_bold, and Call_transferred_bold in packages/i18n/src/locales/en.i18n.json, retain the existing single-asterisk emphasis unless maintainers request otherwise.

Applied to files:

  • .changeset/honest-shrimps-cough.md
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.

Applied to files:

  • .changeset/honest-shrimps-cough.md
🔇 Additional comments (14)
.changeset/honest-shrimps-cough.md (1)

1-5: LGTM!

The changeset is well-formatted and accurately describes the fix for the federated username display issue.

apps/meteor/lib/utils/normalizeUsername.ts (1)

1-8: LGTM!

Clean, focused utility with clear documentation. The implementation correctly handles all edge cases including empty strings, double leading @, and @ characters in the middle of usernames.

apps/meteor/client/components/message/content/reactions/Reaction.tsx (1)

9-13: LGTM!

Good refactor replacing the inline lambda with the centralized utility. The point-free style names.map<string>(normalizeUsername) is clean and functionally equivalent to the previous implementation.

apps/meteor/lib/getUserDisplayNames.ts (1)

2-3: LGTM!

The normalization is correctly applied after the username validation, ensuring the utility always receives a valid string. This integrates well with call sites that render @${displayUsername}.

Also applies to: 17-19

apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)

29-29: LGTM!

The getValue change correctly normalizes usernames before insertion. Per context snippet 1, the final inserted text is prefix + getValue(item) + suffix, where prefix defaults to @ for user mentions. This ensures federated usernames like @john:matrix.org are inserted as @john:matrix.org rather than @@john:matrix.org.

Also applies to: 157-157

apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsx (1)

5-5: LGTM!

The conditional handling reportedUser.username ? normalizeUsername(reportedUser.username) : undefined correctly preserves the optional nature of the username while applying normalization when present.

Also applies to: 17-18

apps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsx (1)

20-20: LGTM!

The normalization follows the same pattern as other moderation components. The useMemo dependencies correctly cover report?.user which encompasses the username change.

Also applies to: 51-53

apps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsx (1)

7-7: LGTM!

The normalization is correctly applied for both the ImageItem component and the text display. The guard condition at line 49 appropriately checks the original user?.username to determine visibility, while the display at line 51 uses the normalized value.

Also applies to: 21-21, 26-26, 49-52

apps/meteor/client/components/message/MessageHeader.tsx (1)

46-46: LGTM - Normalization applied correctly for display and data attributes.

The normalizedUsername is correctly computed and used for:

  • data-username attributes (lines 63, 70)
  • Display text in MessageUsername (line 70)

The original message.u.username is correctly preserved for openUserCard (line 39), ensuring API lookups work with the stored username format.

Also applies to: 63-63, 70-70

apps/meteor/client/components/message/variants/SystemMessage.tsx (1)

53-54: LGTM - Consistent normalization for system messages.

The normalization is correctly applied:

  • normalizedUsername used for display and data-username attribute
  • Raw user.username preserved for openUserCard and UserAvatar lookups
  • The comparison on line 54 now correctly handles federated usernames when checking if username equals display name

Also applies to: 87-87

apps/meteor/tests/unit/lib/utils/normalizeUsername.spec.ts (1)

1-21: LGTM - Comprehensive test coverage for username normalization.

The test cases effectively cover:

  • Standard local usernames (no transformation)
  • Federated usernames with leading @ (stripped)
  • Edge cases: double @@, @ in middle of string, empty string

The parameterized approach using testCases.forEach keeps tests DRY while clearly communicating expected behavior.

apps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsx (1)

16-17: LGTM - Proper normalization for moderation console display.

The username is correctly normalized with appropriate handling for the undefined case. This aligns with the PR objective to fix the @@ display issue in the moderation console (as documented in the PR screenshots).

Also applies to: 33-33

apps/meteor/client/components/GazzodownText.tsx (1)

67-70: LGTM - Robust mention matching with normalized comparison.

Normalizing both username and mention ensures the comparison works correctly regardless of whether either value has a leading @. This handles the asymmetry between federated usernames (stored with @) and local usernames (stored without @).

apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsx (1)

17-20: LGTM - Consistent normalization for autocomplete options.

The username normalization is correctly applied for display purposes. For federated users (_federated is true), the avatar is intentionally omitted (showing globe icon instead), so the normalized username for UserAvatar only affects non-federated users where normalization is effectively a no-op.

Also applies to: 34-42

@aleksandernsilva aleksandernsilva marked this pull request as ready for review March 11, 2026 19:28
@aleksandernsilva aleksandernsilva requested a review from a team as a code owner March 11, 2026 19:28
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 14 files

@aleksandernsilva aleksandernsilva added this to the 8.3.0 milestone Mar 11, 2026
@juliajforesti juliajforesti added the stat: QA assured Means it has been tested and approved by a company insider label Mar 12, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 12, 2026
@dionisio-bot dionisio-bot bot added this pull request to the merge queue Mar 12, 2026
Merged via the queue into develop with commit 469107d Mar 12, 2026
77 of 81 checks passed
@dionisio-bot dionisio-bot bot deleted the fix/normalize-federation-usernames branch March 12, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants