feat: expose getVersions() via the useMessages React hook#732
Conversation
WalkthroughAdds a stable ChangesgetVersions Hook Integration
Sequence Diagram(s)sequenceDiagram
participant ReactComponent as React component
participant useMessages as useMessages hook
participant Room as Room.messages
participant REST as REST API
ReactComponent->>useMessages: calls getVersions(serial)
useMessages->>Room: room.messages.getVersions(serial)
Room->>REST: HTTP GET /messages/:serial/versions
REST-->>Room: PaginatedResult<Message> (oldest-first)
Room-->>useMessages: PaginatedResult<Message>
useMessages-->>ReactComponent: Promise<PaginatedResult<Message>>
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
Adds a getVersions shortcut to useMessages, mirroring getMessage, that delegates to room.messages.getVersions(serial) and returns the full message version history as a PaginatedResult<Message>. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
561b453 to
e74e8f3
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/react/hooks/use-messages.test.tsx (1)
185-231:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAnnotate this test change with the feature spec point.
Line 185-Line 231 extends coverage for new hook behavior but is missing a feature marker comment (for example
// CHA-M10a) to keep spec-to-test traceability.As per coding guidelines, "
test/**/*.test.{ts,tsx}: Annotate tests with feature spec points like// CHA-M10a"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/react/hooks/use-messages.test.tsx` around lines 185 - 231, This test block for useMessages() (the it('should correctly call the methods exposed by the hook', ...) case) needs the feature spec marker comment added (e.g. // CHA-M10a) to maintain spec-to-test traceability; add the marker comment immediately above the test declaration (or at the top of the test block) so the test file test/react/hooks/use-messages.test.tsx is annotated with the appropriate spec point for the new hook behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/react/hooks/use-messages.ts`:
- Around line 102-135: The public API surface changed (the exported hook method
getVersions in use-messages.ts), so update the public docs and the Ably CLI
bundles: add a review note “Public API changes detected. Please update the
documentation and the Ably CLI.” and update any public docs/README and the CLI
spec that reference Messages.getVersions/getVersions to reflect the new
signature/behavior; ensure changelog/typed API exports and any generated CLI
schema are regenerated to include the new getVersions entry.
- Around line 548-554: Add the feature-spec traceability annotation comment
above the new hook method; specifically, insert a line like "// `@CHA-M10a`"
immediately above the getVersions useCallback declaration (the function named
getVersions in use-messages.ts) following the existing project pattern for
src/**/*.{ts,tsx} so the new behavior is annotated for spec traceability.
- Around line 102-133: Update the JSDoc for the public getVersions function in
use-messages.ts to include explicit `@throws` tags: add two `@throws` entries
referencing {`@link` Ably.ErrorInfo} — one describing the error thrown when the
serial is null, undefined, or empty, and one describing errors from the Ably
Chat REST API (network/authorization/request failures). Ensure the new `@throws`
lines are added to the same JSDoc block that documents getVersions (the
hook-exported getVersions shortcut to Messages.getVersions) and follow the
existing style with {`@link` Type} references.
---
Outside diff comments:
In `@test/react/hooks/use-messages.test.tsx`:
- Around line 185-231: This test block for useMessages() (the it('should
correctly call the methods exposed by the hook', ...) case) needs the feature
spec marker comment added (e.g. // CHA-M10a) to maintain spec-to-test
traceability; add the marker comment immediately above the test declaration (or
at the top of the test block) so the test file
test/react/hooks/use-messages.test.tsx is annotated with the appropriate spec
point for the new hook behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: edec3dfc-a7cf-452b-9c49-7aa890c757d9
📒 Files selected for processing (2)
src/react/hooks/use-messages.tstest/react/hooks/use-messages.test.tsx
| /** | ||
| * A shortcut to the {@link Messages.getVersions} method. | ||
| * | ||
| * Get all versions of a message by its serial, in oldest-first order. | ||
| * | ||
| * Returns the original create event followed by any subsequent update and delete events. | ||
| * | ||
| * **NOTE**: This method uses the Ably Chat REST API and so does not require the room | ||
| * to be attached to be called. | ||
| * | ||
| * This is a stable reference and will not be changed between renders for the same room. | ||
| * @param serial - The unique serial identifier of the message. | ||
| * @returns A Promise that resolves to a {@link PaginatedResult} of {@link Message} objects representing each version, | ||
| * or rejects with: | ||
| * - {@link Ably.ErrorInfo} when the serial is null, undefined, or empty | ||
| * - {@link Ably.ErrorInfo} when the Ably Chat REST API request fails due to network or authorization errors | ||
| * @example | ||
| * ```tsx | ||
| * const { getVersions } = useMessages(); | ||
| * | ||
| * const handleGetVersions = async (messageSerial: string) => { | ||
| * try { | ||
| * const versions = await getVersions(messageSerial); | ||
| * for (const version of versions.items) { | ||
| * console.log(version.action, version.text); | ||
| * } | ||
| * } catch (error) { | ||
| * console.error('Failed to get message versions:', error); | ||
| * } | ||
| * }; | ||
| * ``` | ||
| */ | ||
| readonly getVersions: (serial: string) => Promise<PaginatedResult<Message>>; | ||
|
|
There was a problem hiding this comment.
Public API change follow-up is required.
Public API changes detected. Please update the documentation and the Ably CLI.
As per coding guidelines, "src/**/*.{ts,tsx}: If there are any changes to the public-facing API, add a review comment: 'Public API changes detected. Please update the documentation and the Ably CLI.'"
Also applies to: 700-700
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/react/hooks/use-messages.ts` around lines 102 - 135, The public API
surface changed (the exported hook method getVersions in use-messages.ts), so
update the public docs and the Ably CLI bundles: add a review note “Public API
changes detected. Please update the documentation and the Ably CLI.” and update
any public docs/README and the CLI spec that reference
Messages.getVersions/getVersions to reflect the new signature/behavior; ensure
changelog/typed API exports and any generated CLI schema are regenerated to
include the new getVersions entry.
| const getVersions = useCallback( | ||
| async (serial: string) => { | ||
| const room = await context.room; | ||
| return room.messages.getVersions(serial); | ||
| }, | ||
| [context], | ||
| ); |
There was a problem hiding this comment.
Add feature-spec traceability annotation for the new hook method.
Line 548 introduces new behavior but lacks a feature tag comment (for example // @CHA-M10a``) used for spec traceability.
As per coding guidelines, "src/**/*.{ts,tsx}: Annotate code with feature spec points like // @CHA-M10a``"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/react/hooks/use-messages.ts` around lines 548 - 554, Add the feature-spec
traceability annotation comment above the new hook method; specifically, insert
a line like "// `@CHA-M10a`" immediately above the getVersions useCallback
declaration (the function named getVersions in use-messages.ts) following the
existing project pattern for src/**/*.{ts,tsx} so the new behavior is annotated
for spec traceability.
Summary
Closes the React parity gap for the
getVersions()method shipped in v1.4.0 (#730). The core SDK exposesroom.messages.getVersions(serial), but it was never surfaced through theuseMessageshook.What changed
UseMessagesResponse.getVersions— new shortcut field with JSDoc, mirroring the existinggetMessageshortcutuseMessages—getVersionsuseCallbackdelegating toroom.messages.getVersions(serial), added to the returned objectTests
getVersionsand assert it delegates with the correct serialValidation
npm run test:typescript✅npm run test:react-unit✅ (146 passed)npm run docs:lint✅🤖 Generated with Claude Code
Summary by CodeRabbit