Skip to content

Conversation

@ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Oct 2, 2025

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Refactor
    • Streamlined federation event retrieval to delegate directly to the underlying service for more consistent behavior.
  • Chores
    • Improved typing and data contracts for federation event payloads to enhance interoperability and validation.

No user-facing changes are expected in this release; these updates improve internal consistency and reliability and prepare the system for future enhancements.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 2, 2025

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

  • This PR is missing the 'stat: QA assured' label

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 2, 2025

⚠️ No Changeset found

Latest commit: 56b0c9b

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 2, 2025

Walkthrough

The FederationMatrix.getEventById method was simplified to directly call the homeserver event service without local guards or logging. The IFederationMatrixService typing for getEventById was changed to return Promise<EventStore | null> and EventStore was imported from @rocket.chat/federation-sdk.

Changes

Cohort / File(s) Summary
FederationMatrix behavior simplification
ee/packages/federation-matrix/src/FederationMatrix.ts
getEventById now directly delegates to this.homeserverServices.event.getEventById(eventId); removed local guards, error logging/handling, and explicit Promise<any | null> annotation.
Core service interface typing update
packages/core-services/src/types/IFederationMatrixService.ts
Added EventStore import from @rocket.chat/federation-sdk; changed getEventById signature to Promise<EventStore | null>.
Message event property access fix
ee/packages/federation-matrix/src/events/message.ts
In redaction handling, checks now read messageEvent.event.type instead of messageEvent.type when determining message event type.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant FederationMatrix
  participant HomeserverEvent as HomeserverServices.event

  rect rgb(240,248,255)
  Note over Caller,FederationMatrix: Simplified delegation flow
  Caller->>FederationMatrix: getEventById(eventId)
  FederationMatrix->>HomeserverEvent: getEventById(eventId)
  HomeserverEvent-->>FederationMatrix: EventStore | null (or throws)
  FederationMatrix-->>Caller: EventStore | null (propagates errors)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I hop to the homeserver, swift and spry,
I fetch the event and pass it by.
No guards to fret, no logs in tow,
Just tidy calls and tidy flow.
Thump! — a rabbit's tidy cry 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 succinctly describes the primary change by indicating the refactor of the getEventBy method to return a specific PduType instead of any, aligning with convention and capturing the main intent of the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/getEventById-types

📜 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 905a9a0 and 56b0c9b.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/src/events/message.ts (1 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/events/message.ts (1)

279-279: All getEventById usages correctly updated to use .event property. Guards in message, reaction, and transaction handlers now align with the EventStore structure.


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.

@ricardogarim ricardogarim force-pushed the refactor/getEventById-types branch from f1772e0 to 583f455 Compare October 2, 2025 21:21
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

📜 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 f1772e0 and 583f455.

📒 Files selected for processing (3)
  • ee/packages/federation-matrix/src/FederationMatrix.ts (1 hunks)
  • packages/core-services/package.json (1 hunks)
  • packages/core-services/src/types/IFederationMatrixService.ts (2 hunks)
🔇 Additional comments (2)
packages/core-services/src/types/IFederationMatrixService.ts (1)

2-2: Confirm compatibility of getEventById callers
Existing guards against null and subsequent type checks on event.type ensure no breaking changes with the new EventStore<PduForType<PduType>> return type.

packages/core-services/package.json (1)

38-38: @rocket.chat/[email protected] is published; no changes needed.

Comment on lines +649 to 734
async getEventById(eventId: EventID) {
return this.homeserverServices.event.getEventById(eventId);
}
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 | 🟠 Major

Add null check for homeserverServices and explicit return type annotation.

The method now directly delegates to this.homeserverServices.event.getEventById(eventId) without checking if homeserverServices is initialized. Other methods in this class (e.g., createRoom at lines 111-114, sendMessage at lines 444-446) guard against missing homeserverServices before use. Additionally, the return type is no longer explicitly annotated, reducing type safety.

If homeserverServices is unavailable (e.g., when the homeserver module fails to initialize at line 106), calling this method will result in a null-pointer exception instead of returning null gracefully.

Apply this diff to add a null check and explicit return type:

-async getEventById(eventId: EventID) {
-  return this.homeserverServices.event.getEventById(eventId);
+async getEventById(eventId: EventID): Promise<EventStore<PduForType<PduType>> | null> {
+  if (!this.homeserverServices) {
+    this.logger.warn('Homeserver services not available, cannot retrieve event');
+    return null;
+  }
+  return this.homeserverServices.event.getEventById(eventId);
}

Additionally, verify that all callers of getEventById handle potential exceptions if you choose not to add the null check:

#!/bin/bash
# Find all calls to getEventById to verify error handling
rg -nP --type=ts -C5 '\.getEventById\s*\('
🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/FederationMatrix.ts around lines 649 to
651, the async getEventById method lacks an explicit return type and does not
check that this.homeserverServices is initialized; add an explicit return type
(e.g., Promise<Event|null> or the appropriate Event type union) and guard the
call with a null-check that returns null if homeserverServices is absent,
otherwise delegate to this.homeserverServices.event.getEventById(eventId);
ensure the method remains async and update any callers only if you decide not to
return null so they still handle the potential null result.

@ggazzo ggazzo force-pushed the refactor/getEventById-types branch from 583f455 to ecaba8b Compare October 8, 2025 19:07
@ggazzo ggazzo force-pushed the refactor/getEventById-types branch from ecaba8b to 905a9a0 Compare October 8, 2025 19:09
@ggazzo ggazzo added this to the 7.11.0 milestone Oct 8, 2025
@codecov
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.44%. Comparing base (3a85856) to head (56b0c9b).
⚠️ Report is 2 commits behind head on release-7.11.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-7.11.0   #37130      +/-   ##
==================================================
- Coverage           67.46%   67.44%   -0.02%     
==================================================
  Files                3329     3329              
  Lines              113381   113381              
  Branches            20579    20579              
==================================================
- Hits                76490    76472      -18     
- Misses              34291    34314      +23     
+ Partials             2600     2595       -5     
Flag Coverage Δ
e2e 57.28% <ø> (+<0.01%) ⬆️
unit 71.22% <100.00%> (-0.04%) ⬇️

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 merged commit df117e7 into release-7.11.0 Oct 8, 2025
20 checks passed
@ggazzo ggazzo deleted the refactor/getEventById-types branch October 8, 2025 20:59
sampaiodiego pushed a commit that referenced this pull request Oct 9, 2025
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