Skip to content

feat: chat.getMessageByFileId endpoint - #41939

Open
OtavioStasiak wants to merge 5 commits into
developfrom
feat.return-messageid-on-files-endpoint
Open

feat: chat.getMessageByFileId endpoint#41939
OtavioStasiak wants to merge 5 commits into
developfrom
feat.return-messageid-on-files-endpoint

Conversation

@OtavioStasiak

@OtavioStasiak OtavioStasiak commented Aug 25, 2026

Copy link
Copy Markdown

Adds GET /v1/chat.getMessageByFileId, which returns the message a file was sent in, given the file id.

Uploads don't store a reference to their message — the link only exists in the other direction (message.file._id /
message.files[]._id), so there was no way for a client holding a file id to reach its message. The endpoint resolves it
server-side using the existing Messages.getMessageByFileId, the same lookup chat.delete already uses when it receives a fileId.

GET /v1/chat.getMessageByFileId?fileId=

  {
    "message": { "_id": "...", "rid": "...", "msg": "", "files": [{ "_id": "<fileId>", ... }], ... },
    "success": true
  }

Returns 404 when no message references the file and 403 when the caller can't access the message's room (canAccessRoomIdAsync,
the same check chat.getMessage uses). The message goes through normalizeMessagesForUser before being returned, so the payload
matches chat.getMessage.

Covered by end-to-end API tests in apps/meteor/tests/end-to-end/api/chat.ts: happy path, missing/empty fileId, unknown file, no
room access, and unauthenticated.

Proposed changes (including videos or screenshots)

Issue(s)

https://rocketchat.atlassian.net/browse/SUP-1106

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features

    • Added an API endpoint to retrieve a chat message by its associated file ID.
    • Added request validation for missing or empty file IDs.
    • Added appropriate responses for unavailable files, restricted room access, and successful lookups.
  • Tests

    • Added coverage for successful retrievals, invalid requests, unknown files, access restrictions, and unauthenticated requests.

@dionisio-bot

dionisio-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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

changeset-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 69b6688

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

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/rest-typings Minor
@rocket.chat/meteor Minor
@rocket.chat/core-typings Minor

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

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ae88cd7-6dec-40a1-805e-193135a930b3

📥 Commits

Reviewing files that changed from the base of the PR and between c932a10 and 0bd4591.

📒 Files selected for processing (2)
  • .changeset/chat-get-message-by-file-id.md
  • apps/meteor/tests/end-to-end/api/chat.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/tests/end-to-end/api/chat.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (3/5)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (1/4)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (2/4)
🔇 Additional comments (1)
.changeset/chat-get-message-by-file-id.md (1)

1-7: LGTM!


Walkthrough

Changes

File-Based Message Lookup

Layer / File(s) Summary
Endpoint contract and handler
packages/rest-typings/src/v1/chat.ts, apps/meteor/server/api/v1/chat.ts
Adds chat.getMessageByFileId with a required fileId, normalized IMessage response, validation, 404 handling, and room access checks that return 403 when required.
Endpoint validation, coverage, and release metadata
apps/meteor/tests/end-to-end/api/chat.ts, .changeset/chat-get-message-by-file-id.md
Adds end-to-end coverage for successful lookup, invalid or unknown file IDs, unauthorized access, unauthenticated requests, and test cleanup. Adds minor release metadata for the affected packages.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0bd45

This change adds a scoped endpoint for retrieving a message by file ID with documented access and error behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant chat.getMessageByFileId
  participant Messages
  participant Rooms
  Client->>chat.getMessageByFileId: Request with fileId
  chat.getMessageByFileId->>Messages: Find message by fileId
  Messages-->>chat.getMessageByFileId: Message and room reference
  chat.getMessageByFileId->>Rooms: Check requester access
  Rooms-->>chat.getMessageByFileId: Access result
  chat.getMessageByFileId-->>Client: Normalized message or error response
Loading

Suggested labels: type: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the chat.getMessageByFileId endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

Errors were encountered while retrieving linked issues.

Errors (1)
  • SUP-1106: Request failed with status code 401

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.

@OtavioStasiak

Copy link
Copy Markdown
Author

@CodeRabbit review

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.31%. Comparing base (371fce3) to head (69b6688).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41939      +/-   ##
===========================================
- Coverage    69.35%   69.31%   -0.04%     
===========================================
  Files         4254     4254              
  Lines       168675   168682       +7     
  Branches     30046    30105      +59     
===========================================
- Hits        116977   116929      -48     
- Misses       46525    46581      +56     
+ Partials      5173     5172       -1     
Flag Coverage Δ
e2e 58.81% <ø> (-0.02%) ⬇️
e2e-api 45.88% <100.00%> (-0.26%) ⬇️
unit 71.25% <ø> (-0.02%) ⬇️

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.

@OtavioStasiak
OtavioStasiak marked this pull request as ready for review August 25, 2026 22:23
@OtavioStasiak
OtavioStasiak requested review from a team as code owners August 25, 2026 22:23

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants