-
Notifications
You must be signed in to change notification settings - Fork 5
feat: expose getVersions() via the useMessages React hook #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,40 @@ export interface UseMessagesResponse extends ChatStatusResponse { | |
| */ | ||
| readonly getMessage: (serial: string) => Promise<Message>; | ||
|
|
||
| /** | ||
| * 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>>; | ||
|
|
||
|
Comment on lines
+102
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Public API change follow-up is required. Public API changes detected. Please update the documentation and the Ably CLI. As per coding guidelines, " Also applies to: 700-700 🤖 Prompt for AI Agents |
||
| /** | ||
| * A shortcut to the {@link Messages.update} method. | ||
| * | ||
|
|
@@ -511,6 +545,14 @@ export const useMessages = (params?: UseMessagesParams): UseMessagesResponse => | |
| [context], | ||
| ); | ||
|
|
||
| const getVersions = useCallback( | ||
| async (serial: string) => { | ||
| const room = await context.room; | ||
| return room.messages.getVersions(serial); | ||
| }, | ||
| [context], | ||
| ); | ||
|
Comment on lines
+548
to
+554
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add feature-spec traceability annotation for the new hook method. Line 548 introduces new behavior but lacks a feature tag comment (for example As per coding guidelines, " 🤖 Prompt for AI Agents |
||
|
|
||
| const deleteMessage = useCallback( | ||
| async (serial: string, details?: OperationDetails) => { | ||
| const room = await context.room; | ||
|
|
@@ -655,6 +697,7 @@ export const useMessages = (params?: UseMessagesParams): UseMessagesResponse => | |
| roomError, | ||
| sendMessage, | ||
| getMessage, | ||
| getVersions, | ||
| updateMessage, | ||
| history, | ||
| deleteMessage, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.