Skip to content

Conversation

@debdutdeb
Copy link
Member

@debdutdeb debdutdeb commented Sep 19, 2025

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • More accurate Direct Message detection when accepting invites, preventing rooms from being mislabeled as group chats and ensuring correct notifications and badges.
  • Performance
    • Streamlined DM status evaluation during room joins, reducing processing overhead and potential errors.
  • Reliability
    • Consistent DM identification sourced directly from invite data, improving stability across edge cases.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 19, 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 Sep 19, 2025

🦋 Changeset detected

Latest commit: 1d56b34

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

This PR includes changesets to release 46 packages
Name Type
@rocket.chat/apps-engine Minor
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/web-ui-registration Major
@rocket.chat/storybook-config Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/ui-theming Patch
@rocket.chat/ui-video-conf Major
@rocket.chat/uikit-playground Patch
@rocket.chat/ui-composer Patch
@rocket.chat/gazzodown Major
@rocket.chat/ui-avatar Major
@rocket.chat/ui-client Major
@rocket.chat/ui-voip Major
@rocket.chat/core-typings Minor
@rocket.chat/license Minor
@rocket.chat/i18n Minor
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/api-client Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/mock-providers Patch
@rocket.chat/livechat Patch
@rocket.chat/cron Patch
@rocket.chat/freeswitch Patch
@rocket.chat/model-typings Patch
@rocket.chat/federation-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core 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
Contributor

coderabbitai bot commented Sep 19, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

166 files out of 295 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

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

Walkthrough

Replaces heuristic DM detection in Matrix invite handling by reading is_direct directly from the membership event content. Removes the isDirectMessage helper, updates joinRoom to use inviteEvent.getContent().is_direct, and adds the PduMembershipEventContent import.

Changes

Cohort / File(s) Summary
Invite flow DM detection
ee/packages/federation-matrix/src/api/_matrix/invite.ts
Remove room-state-based DM heuristic; import PduMembershipEventContent; in joinRoom read is_direct from invite event content; delete isDirectMessage helper and related logic.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MatrixAPI
  participant InviteHandler as invite.ts

  Client->>MatrixAPI: Receive m.room.member invite
  MatrixAPI->>InviteHandler: joinRoom(inviteEvent)
  Note over InviteHandler: Previous: inspect room state to infer DM
  InviteHandler->>InviteHandler: content = inviteEvent.getContent<PduMembershipEventContent>()
  InviteHandler->>InviteHandler: isDM = content.is_direct
  alt isDM
    InviteHandler->>MatrixAPI: Proceed with DM-specific join handling
  else not DM
    InviteHandler->>MatrixAPI: Proceed with normal room join
  end
  Note over InviteHandler: Control flow simplified by using is_direct flag
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: DMs #36762 — Also modifies the same invite handler to introduce DM detection heuristics; this PR removes that heuristic in favor of reading is_direct from the event.

Suggested reviewers

  • ricardogarim

Poem

A whisker twitch, a flag so bright,
No maze of rooms to sniff tonight—
I read the invite’s truth outright: is_direct in plain sight.
Hop, hop, join with nimble cheer,
Simpler paths, less code to fear. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: dm check on invite" is concise and directly reflects the primary change — correcting direct-message (DM) detection during invite handling. It uses a clear conventional-commit style and avoids extraneous details, so a teammate scanning history can quickly understand the main intent. The phrasing is focused and related to the changes in the invite DM-check logic.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ee/packages/federation-matrix/src/api/_matrix/invite.ts (1)

134-143: Backoff math uses seconds as milliseconds; delays are wrong.

You square a “seconds” value, log it as ms, pass it to setTimeout as ms, then pass delay*1000 as the next “seconds.” This makes the first retry almost immediate and the next backoff explode.

Use consistent units:

 async function runWithBackoff(fn: () => Promise<void>, delaySec = 5) {
   try {
     await fn();
   } catch (e) {
-    const delay = delaySec === 625 ? 625 : delaySec ** 2;
-    console.log(`error occurred, retrying in ${delay}ms`, e);
-    setTimeout(() => {
-      runWithBackoff(fn, delay * 1000);
-    }, delay);
+    const nextDelaySec = Math.min(625, delaySec ** 2);
+    const delayMs = delaySec * 1000;
+    console.log(`error occurred, retrying in ${delaySec}s`, e);
+    setTimeout(() => {
+      void runWithBackoff(fn, nextDelaySec);
+    }, delayMs);
   }
 }
📜 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 c70e153 and a1869e8.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/src/api/_matrix/invite.ts (2 hunks)
⏰ 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: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (1)
ee/packages/federation-matrix/src/api/_matrix/invite.ts (1)

2-2: Verify PduMembershipEventContent includes is_direct / isDirect in @hs/room

Local search returned no results — confirm the package's type declarations (e.g. node_modules/@hs/room or package source) expose an optional is_direct or isDirect on membership event content. If absent, guard the property access or update the types/package.


// we only understand these two types of rooms, plus direct messages
const isDM = await isDirectMessage(matrixRoom, inviteEvent);
const isDM = inviteEvent.getContent<PduMembershipEventContent>().is_direct;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Don’t rely solely on is_direct; normalize and handle absence.

Some homeservers omit is_direct on invites or use isDirect. Treat it as optional and normalize; otherwise non‑DM rooms may be misclassified, hitting the “neither public, private, nor direct” error path.

Apply:

- const isDM = inviteEvent.getContent<PduMembershipEventContent>().is_direct;
+ const content = inviteEvent.getContent<PduMembershipEventContent & { is_direct?: boolean; isDirect?: boolean }>();
+ const isDM = (content.is_direct ?? content.isDirect) === true;

Optionally keep a lightweight heuristic fallback if the flag is absent (e.g., fall back to previous helper or room state) in a follow-up.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isDM = inviteEvent.getContent<PduMembershipEventContent>().is_direct;
const content = inviteEvent.getContent<PduMembershipEventContent & { is_direct?: boolean; isDirect?: boolean }>();
const isDM = (content.is_direct ?? content.isDirect) === true;
🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/api/_matrix/invite.ts around line 172, the
code currently reads the invite's is_direct directly and may misclassify rooms
when homeservers omit or rename that field; update the logic to treat the field
as optional and normalize both possible names (is_direct and isDirect), coerce
to a boolean (default to false when absent), and ensure downstream branching
uses this normalized value; optionally add a light heuristic fallback (e.g.,
call the existing helper or inspect room state) when no explicit flag is
present, but keep the immediate fix limited to normalization and safe defaulting
so invites aren't incorrectly classified.

@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.09%. Comparing base (c70e153) to head (a1869e8).

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##           feat/federation   #37012      +/-   ##
===================================================
- Coverage            69.09%   69.09%   -0.01%     
===================================================
  Files                 2959     2959              
  Lines               102190   102190              
  Branches             18259    18259              
===================================================
- Hits                 70605    70604       -1     
- Misses               29716    29720       +4     
+ Partials              1869     1866       -3     
Flag Coverage Δ
unit 71.22% <ø> (-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.

@ggazzo ggazzo requested review from a team as code owners September 19, 2025 22:33
@ggazzo ggazzo changed the base branch from feat/federation to chore/federation-backup September 19, 2025 22:40
@ggazzo ggazzo merged commit ffd96af into chore/federation-backup Sep 19, 2025
8 checks passed
@ggazzo ggazzo deleted the fix-dm-check branch September 19, 2025 22:48
ggazzo added a commit that referenced this pull request Sep 23, 2025
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
ggazzo added a commit that referenced this pull request Sep 25, 2025
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
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.

3 participants