fix: Prevent UI from displaying @@ for federation usernames#39460
fix: Prevent UI from displaying @@ for federation usernames#39460dionisio-bot[bot] merged 4 commits intodevelopfrom
Conversation
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: dca691c The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 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)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2026-01-19T18:17:46.433ZApplied to files:
📚 Learning: 2026-01-17T01:51:47.764ZApplied to files:
📚 Learning: 2026-03-11T15:56:13.132ZApplied to files:
📚 Learning: 2026-02-24T19:36:55.089ZApplied to files:
📚 Learning: 2025-11-19T18:20:37.116ZApplied to files:
🔇 Additional comments (2)
WalkthroughAdds a new utility Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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. Comment |
43e61c8 to
1dffc08
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Fixes inconsistent username formatting causing '@@username' for federated users
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (14)
.changeset/honest-shrimps-cough.mdapps/meteor/client/components/GazzodownText.tsxapps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsxapps/meteor/client/components/message/MessageHeader.tsxapps/meteor/client/components/message/content/reactions/Reaction.tsxapps/meteor/client/components/message/variants/SystemMessage.tsxapps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsxapps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsxapps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsxapps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsxapps/meteor/client/views/room/providers/ComposerPopupProvider.tsxapps/meteor/lib/getUserDisplayNames.tsapps/meteor/lib/utils/normalizeUsername.tsapps/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.tsapps/meteor/client/views/admin/moderation/ModerationConsoleTableRow.tsxapps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsxapps/meteor/client/components/message/MessageHeader.tsxapps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsxapps/meteor/lib/utils/normalizeUsername.tsapps/meteor/client/views/room/providers/ComposerPopupProvider.tsxapps/meteor/client/components/GazzodownText.tsxapps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultipleOption.tsxapps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsxapps/meteor/client/components/message/content/reactions/Reaction.tsxapps/meteor/client/components/message/variants/SystemMessage.tsxapps/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.tsextension 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.tsapps/meteor/lib/utils/normalizeUsername.tsapps/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.tsapps/meteor/lib/utils/normalizeUsername.tsapps/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.tsxapps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsxapps/meteor/client/components/message/MessageHeader.tsxapps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsxapps/meteor/lib/utils/normalizeUsername.ts.changeset/honest-shrimps-cough.mdapps/meteor/client/components/GazzodownText.tsxapps/meteor/client/views/admin/moderation/UserReports/UserReportInfo.tsxapps/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.tsxapps/meteor/client/views/admin/moderation/UserReports/ModConsoleUserTableRow.tsxapps/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.tsxapps/meteor/client/views/room/contextualBar/RoomFiles/components/FileItem.tsxapps/meteor/client/views/room/providers/ComposerPopupProvider.tsx.changeset/honest-shrimps-cough.mdapps/meteor/client/components/message/variants/SystemMessage.tsxapps/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
getValuechange correctly normalizes usernames before insertion. Per context snippet 1, the final inserted text isprefix + getValue(item) + suffix, where prefix defaults to@for user mentions. This ensures federated usernames like@john:matrix.orgare inserted as@john:matrix.orgrather 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) : undefinedcorrectly 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
useMemodependencies correctly coverreport?.userwhich 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
ImageItemcomponent and the text display. The guard condition at line 49 appropriately checks the originaluser?.usernameto 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
normalizedUsernameis correctly computed and used for:
data-usernameattributes (lines 63, 70)- Display text in
MessageUsername(line 70)The original
message.u.usernameis correctly preserved foropenUserCard(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:
normalizedUsernameused for display anddata-usernameattribute- Raw
user.usernamepreserved foropenUserCardandUserAvatarlookups- 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 stringThe parameterized approach using
testCases.forEachkeeps 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
usernameandmentionensures 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 (
_federatedis true), the avatar is intentionally omitted (showing globe icon instead), so the normalized username forUserAvataronly affects non-federated users where normalization is effectively a no-op.Also applies to: 34-42
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:
Issue(s)
CORE-1946
Steps to test or reproduce
Further comments
Summary by CodeRabbit
New Features
Bug Fixes
Tests