Skip to content

feat(chat): add room-type-agnostic chat.history endpoint#40981

Draft
ggazzo wants to merge 3 commits into
developfrom
feat/chat-history-endpoint
Draft

feat(chat): add room-type-agnostic chat.history endpoint#40981
ggazzo wants to merge 3 commits into
developfrom
feat/chat-history-endpoint

Conversation

@ggazzo

@ggazzo ggazzo commented Jun 16, 2026

Copy link
Copy Markdown
Member

Proposed changes

Follow-up to #40711, part of the DDP-removal effort — replacing deprecated DDP methods with room-type-agnostic REST endpoints.

Adds a new GET /api/v1/chat.history REST endpoint that returns a room's message history by roomId regardless of room type (channel, private group or DM), and switches the reconnect hook to use it.

Today, fetching message history over REST requires the caller to know the room type and hit the matching endpoint (channels.history, groups.history, im.history). This endpoint removes that requirement: it accepts only roomId and resolves access through Authorization.canReadRoom, just like the underlying getChannelHistory.

Why

It is a performant REST replacement for the deprecated loadMissedMessages DDP method:

  • Both use the { rid, ts }-indexed range query (ts > oldest) — a single, efficient range scan.
  • Unlike chat.syncMessages (which queries _updatedAt + the trash collection to reconcile edits/reactions/deletions), chat.history returns only messages by creation time.

The loadMissedMessages deprecation notice now points to /v1/chat.history.

Scope: this PR only adds the endpoint and repoints the loadMissedMessages deprecation. The reconnect hook (useLoadMissedMessages) keeps using /v1/chat.syncMessages, since reconnect catch-up still needs to reconcile edits and deletions made while offline.

Usage

GET /api/v1/chat.history?roomId=<rid>&oldest=<ts>&latest=<now>&inclusive=false

Params: roomId (required), latest, oldest, inclusive, count, offset, unreads, showThreadMessages.

How to test

  • chat.history returns the history of a channel and a private group via the same endpoint (room-type agnostic).
  • oldest filters to messages created after the timestamp.
  • count limits the page size.
  • Missing roomId -> 400; inaccessible room -> 403.

E2E tests added under [/chat.history] in apps/meteor/tests/end-to-end/api/chat.ts.

@dionisio-bot

dionisio-bot Bot commented Jun 16, 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

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 992cb21

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/meteor Minor
@rocket.chat/rest-typings 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 Jun 16, 2026

Copy link
Copy Markdown
Contributor

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: 975cc9d7-2eb0-4fc0-baea-ea7fa8c4d787

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

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 force-pushed the feat/chat-history-endpoint branch from c2546e8 to 6247a46 Compare June 16, 2026 19:11
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.08%. Comparing base (fbf3672) to head (daa2272).
⚠️ Report is 9 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #40981   +/-   ##
========================================
  Coverage    70.08%   70.08%           
========================================
  Files         3357     3357           
  Lines       129543   129534    -9     
  Branches     22474    22475    +1     
========================================
+ Hits         90787    90790    +3     
+ Misses       35456    35442   -14     
- Partials      3300     3302    +2     
Flag Coverage Δ
unit 70.03% <ø> (ø)

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 added 2 commits June 16, 2026 16:43
Add a new `GET /v1/chat.history` REST endpoint that returns a room's
message history by `roomId` regardless of room type (channel, private
group or DM), mirroring the behavior of `channels.history`,
`groups.history` and `im.history` without requiring the caller to know
the room type beforehand.

It reuses `getChannelHistory`, which resolves access via
`Authorization.canReadRoom`, so the same `{ rid, ts }`-indexed range
query is used for any room. This provides a performant REST replacement
for the deprecated `loadMissedMessages` DDP method, whose deprecation
notice now points to `/v1/chat.history`.
Replace the `chat.syncMessages` REST call in the reconnect hook with the
new `GET /v1/chat.history` endpoint.

On reconnection the hook now fetches only messages created after the
newest loaded message's timestamp (`ts`) via a single indexed range
query, instead of scanning `_updatedAt` plus the trash collection.
@ggazzo ggazzo force-pushed the feat/chat-history-endpoint branch from 6247a46 to daa2272 Compare June 16, 2026 19:43
@ggazzo ggazzo added this to the 8.6.0 milestone Jun 17, 2026
chat.history replaces the deprecated loadMissedMessages DDP method only.
The reconnect hook must keep chat.syncMessages so it still reconciles
edits and deletions made while offline.
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.

1 participant