Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Oct 1, 2025

Co-authored-by: Diego Sampaio chinello@gmail.com

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features
    • Improved federation invites with automatic processing of invite acceptance.
    • Better handling of local vs. remote usernames for cross-server rooms.
  • Bug Fixes
    • Increased reliability when inviting and joining federated users.
    • Avoids duplicate joins by checking existing room membership.
  • Refactor
    • Streamlined “add users to room” flow for consistent behavior across room types.
    • Enhanced federation event handling with richer service context.
  • Chores
    • Updated federation SDK dependencies for compatibility and stability.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 1, 2025

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 Oct 1, 2025

⚠️ No Changeset found

Latest commit: 3707a37

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 Oct 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Removes the federation-specific branch from addUsersToRoom and unregisters the related callback. Updates type signatures accordingly. Extends role methods’ room projections to include federation. Bumps @rocket.chat/federation-sdk to 0.1.13. Refactors federation-matrix invite/join flows, adds acceptInvite, introduces getUsernameServername, and threads HomeserverServices through event handlers.

Changes

Cohort / File(s) Summary
Server method: addUsersToRoom
apps/meteor/app/lib/server/methods/addUsersToRoom.ts
Removes federated handling path and its imports; unifies flow for adding users; adds exported addUsersToRoomMethod and ServerMethods signature.
Federation hook removal
apps/meteor/ee/server/hooks/federation/index.ts
Deletes registration of callbacks.add('federation.onAddUsersToRoom', …).
Callbacks typing cleanup
apps/meteor/lib/callbacks.ts
Removes EventLikeCallbackSignatures entry for 'federation.onAddUsersToRoom'.
Room role methods projection update
apps/meteor/server/methods/addRoomModerator.ts, .../addRoomOwner.ts, .../removeRoomModerator.ts, .../removeRoomOwner.ts
Adds federation field to Rooms.findOne projections; no control-flow changes.
Federation SDK version bump
ee/apps/federation-service/package.json, ee/packages/federation-matrix/package.json
Updates @rocket.chat/federation-sdk from 0.1.11 to 0.1.13.
FederationMatrix core updates
ee/packages/federation-matrix/src/FederationMatrix.ts
Adds getUsernameServername; passes homeserverServices to registerEvents; updates createOrUpdateFederatedUser to handle origin and name defaults; refactors inviteUsersToRoom to handle federated and local usernames and process acceptance.
Matrix invite/join API
ee/packages/federation-matrix/src/api/_matrix/invite.ts
Exports joinRoom; introduces acceptInvite; exposes startJoiningRoom via runWithBackoff wrapper; imports getUsernameServername and isUserNativeFederated; refactors backoff utility.
Events wiring
ee/packages/federation-matrix/src/events/index.ts
registerEvents now accepts HomeserverServices and passes it to member handler.
Member events handling
ee/packages/federation-matrix/src/events/member.ts
member() and membershipJoinAction accept services; uses getUsernameServername; switches to createOrUpdateFederatedUser; checks existing subscriptions; handles local vs federated usernames.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant MeteorServer as Server Method addUsersToRoom
  participant UserService as User/Subscriptions
  participant Notifier

  Client->>MeteorServer: addUsersToRoom({ rid, users })
  Note over MeteorServer: Federated branch removed
  loop for each username
    MeteorServer->>UserService: find user by username
    alt user already member
      MeteorServer->>Notifier: notify already in room
    else user not member
      MeteorServer->>UserService: add user to room
      MeteorServer->>Notifier: notify user added
    end
  end
  MeteorServer-->>Client: boolean result
Loading
sequenceDiagram
  autonumber
  participant App as FederationMatrix
  participant Homeserver as HomeserverServices
  participant Accept as acceptInvite

  App->>Homeserver: inviteUserToRoom(roomId, username)
  Homeserver-->>App: invite sent/ack
  App->>Accept: acceptInvite(inviteEvent, username, services)
  Accept->>Homeserver: validate invite and join room (with backoff)
  Homeserver-->>Accept: joined
  Accept-->>App: done
Loading
sequenceDiagram
  autonumber
  participant HS as Homeserver (Matrix)
  participant Events as registerEvents
  participant Member as member()
  participant Users as createOrUpdateFederatedUser
  participant Rooms as Room/Subscriptions

  HS-->>Events: m.room.member (join)
  Events->>Member: membershipJoinAction(data, services)
  Member->>Member: getUsernameServername(state_key, serverName)
  alt user is local
    Member->>Rooms: check existing subscription
    alt subscription exists
      Member-->>Events: skip add
    else
      Users->>Users: createOrUpdateFederatedUser({ username, origin, name })
      Member->>Rooms: add user to room
    end
  else federated user
    Users->>Users: createOrUpdateFederatedUser({ username (mxid), origin, name })
    Member->>Rooms: add user to room
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ricardogarim
  • sampaiodiego

Poem

Hoppity-hop, I tweak the loom,
Threads of rooms now weave one loom.
Callbacks trimmed, invites aligned,
Homeservers whisper, well-designed.
With gentle paws, I merge the way—
Matrix doors open, come what may. 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fed-join-own-users

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3d3e7fa and 3707a37.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • apps/meteor/app/lib/server/methods/addUsersToRoom.ts (0 hunks)
  • apps/meteor/ee/server/hooks/federation/index.ts (0 hunks)
  • apps/meteor/lib/callbacks.ts (0 hunks)
  • apps/meteor/server/methods/addRoomModerator.ts (1 hunks)
  • apps/meteor/server/methods/addRoomOwner.ts (1 hunks)
  • apps/meteor/server/methods/removeRoomModerator.ts (1 hunks)
  • apps/meteor/server/methods/removeRoomOwner.ts (1 hunks)
  • ee/apps/federation-service/package.json (1 hunks)
  • ee/packages/federation-matrix/package.json (1 hunks)
  • ee/packages/federation-matrix/src/FederationMatrix.ts (6 hunks)
  • ee/packages/federation-matrix/src/api/_matrix/invite.ts (5 hunks)
  • ee/packages/federation-matrix/src/events/index.ts (2 hunks)
  • ee/packages/federation-matrix/src/events/member.ts (2 hunks)

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.

@ggazzo ggazzo marked this pull request as ready for review October 1, 2025 21:45
@ggazzo ggazzo requested a review from a team as a code owner October 1, 2025 21:45
@ggazzo ggazzo merged commit 9e80b74 into fix/old-fed Oct 1, 2025
27 of 30 checks passed
@ggazzo ggazzo deleted the fix/fed-join-own-users branch October 1, 2025 21:46
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.

2 participants