Skip to content

fix(federation): register local users on Matrix when self-joining federated rooms#39427

Draft
Aryan-Verma-999 wants to merge 1 commit intoRocketChat:developfrom
Aryan-Verma-999:fix/federation-self-join-matrix-invite
Draft

fix(federation): register local users on Matrix when self-joining federated rooms#39427
Aryan-Verma-999 wants to merge 1 commit intoRocketChat:developfrom
Aryan-Verma-999:fix/federation-self-join-matrix-invite

Conversation

@Aryan-Verma-999
Copy link

Proposed changes

Problem

When a local Rocket.Chat user self-joins a federated room via channels.join (or through the UI "Join" button), they are not registered on the Matrix homeserver. This means:

  • The user cannot send messages that appear on the federated side
  • The user's presence is invisible to Matrix participants
  • The room membership state is inconsistent between RC and Matrix

Root Cause

The existing beforeAddUserToRoom hook at ee/server/hooks/federation/index.ts:105-139 requires an inviter parameter:

// Line 107 — early return when no inviter
if (!user.username || !inviter) {
    return;
}

When a user self-joins via channels.join, addUserToRoom is called without an inviter, so the federation hook silently exits and the Matrix bridge is never notified.

Users who are explicitly invited (via addUserToRoom with an inviter) work correctly because the inviter parameter is present.

Fix

Added an afterJoinRoom callback that catches the self-join case:

  1. Verifies the room is federated (shouldPerformFederationAction
  2. Skips external Matrix users (already handled by incoming federation events)
  3. Calls FederationMatrix.inviteUsersToRoom() to register the local user on the Matrix homeserver
  4. Uses LOW priority to run after all other join hooks
  5. Wrapped in try/catch to avoid breaking the join flow if the Matrix call fails

Note on duplicate invites

For explicitly invited users, both beforeAddUserToRoom (existing) and this new afterJoinRoom hook will fire. The Matrix protocol handles duplicate invite events idempotently (re-inviting an already-joined member is a no-op), so this should be safe. However, I'd appreciate confirmation on this behavior. An alternative approach would be to use a module-scoped flag to track whether beforeAddUserToRoom already handled the invite for this user.

Issue(s)

Fixes #38239 Builds on the failing e2e test from #38669

@ggazzo Would love your feedback on the approach, especially regarding the duplicate invite edge case for explicitly invited users.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 6, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

⚠️ No Changeset found

Latest commit: a8e2547

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcfc68d6-2dc7-4de8-8fb0-c77ad1128425

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

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.

[Feature Request] [Federation] Allow users to self-join federated rooms with proper homeserver registration

1 participant