chat: add react message reactions examples, restructure message reactions page#2653
Conversation
owenpearson
commented
Jun 6, 2025
- adds react code examples for message reactions
- restructures the page so that reaction types and the default type are explained before 'how to actually send a reaction'.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
|
||
| The default reaction type can be configured at room-level using the Room Options. If nothing is set, the default is `Distinct`. | ||
| <If lang="react"> | ||
| Use the [`deleteReaction()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_react.UseMessagesResponse.html#deleteReaction) method available from the response of the `useMessages` hook to remove a reaction from a message. This method takes the following parameters: |
There was a problem hiding this comment.
| Use the [`deleteReaction()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat_react.UseMessagesResponse.html#deleteReaction) method available from the response of the `useMessages` hook to remove a reaction from a message. This method takes the following parameters: | |
| Use the [`deleteReaction()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#deleteReaction) method available from the response of the `useMessages` hook to remove a reaction from a message. This method takes the following parameters: |
|
|
||
| ## Messages and reactions <a id="messages-and-reactions"/> | ||
|
|
||
| The `Message` object contains a `reactions` property which is an object that looks like this: |
There was a problem hiding this comment.
Need to add equivalent language option for React here or it says this feature isn't available in React
There was a problem hiding this comment.
Annoyingly I couldn't find a way to say "This code block should appear for javascript AND react", so have just duplicated the javascript one for now
There was a problem hiding this comment.
Mmm, I didn't add this as a requirement for the move to MDX because I wanted to get away from always duplicating JS and Node. I can't believe it happens that often between React and JS to be an issue though, right?
There was a problem hiding this comment.
well any snippet like this which is just explaining a return type of an API will probably be identical for both, the react APIs are only different from js in terms of how you use them, what they actually return should always be the same. I have no idea how many snippets overall would fit into this category though 🤷
| ``` | ||
| </Code> | ||
|
|
||
| The `annotation-subscribe` capability is required for receiving individual reactions, however it is not required to receive summaries. |
There was a problem hiding this comment.
Ditto above re putting this into a callout box for extra visibility
1b42d5b to
cad7d52
Compare
| | Type | Description | Example | Similar to | | ||
| | ---- | ----------- | ------- | --------- | | ||
| | `Unique` | A user can react to a message only once, with a reaction of their choice. When a user reacts a second time their reaction is changed. | Can 👍 or ❤️ but not both or more than once. | iMessage, WhatsApp, Facebook Messenger | | ||
| | `Distinct` | A user can react to a message with each reaction at most once. | Can 👍 and ❤️ but each reaction only once. No 👍👍. | Slack | |
There was a problem hiding this comment.
| | `Distinct` | A user can react to a message with each reaction at most once. | Can 👍 and ❤️ but each reaction only once. No 👍👍. | Slack | | |
| | `Distinct` | A user can react to a message with each reaction at most once. | Can 👍 and ❤️ but only once per reaction. No 👍👍. | Slack | |
There was a problem hiding this comment.
have improved the wording here 👍
|
|
||
| ### Configure the default reaction type <a id="default-type"/> | ||
|
|
||
| The default reaction type can be configured at room-level using the Room Options. If nothing is set, the default is `Distinct`. |
There was a problem hiding this comment.
RoomOption. Should we also state which option this falls under - though we don't seem to have any reference to MessageOptions in the rooms page, nor in the messages page (or here).
There was a problem hiding this comment.
have also improved the wording here. it's a lot easier to just show how room options are used in an example (which we're doing in the snippet below) than to describe exactly what the API is, but i think what i have now is more clear either way
| <If lang="javascript,swift,kotlin"> | ||
| To add a message reaction use `room.messages.reactions.send(message, params)`. This method takes the following parameters: | ||
| * `message` - The message to add the reaction to. It can also be an object of format `{serial: "message serial"}`. | ||
| * `message` - The message to add the reaction to. This can be a Message object, or just the string serial. |
There was a problem hiding this comment.
Should this be more like 'the serial of a message' rather than 'the string serial'?
There was a problem hiding this comment.
good spot, have updated all descriptions of this argument
| <If lang="javascript,swift,kotlin"> | ||
| Raw individual reactions are published for every reaction, unlike summaries which can be rolled up. Raw reactions are useful for receiving all reaction events, but they are not suitable for the purpose of displaying message reaction counts as their effect on the reactions summary depends on the previous reactions. | ||
|
|
||
| Individual reactions are not received by default to save bandwidth and to reduce the number of messages and cost. If you want to receive them, you can configure them via a room option which, in turn, sets the appropriate channel options to enable receiving individual annotations and reactions: |
There was a problem hiding this comment.
RoomOption.
Also do we need to let them know that it sets the associated ChannelOption? I think it's somewhat irrelevant.
More broadly, I think we should explain what summaries are, and that they are the default behaviour before we start talking about subscribing to them (them being raw events).
As an aside.. Is 'raw event' the correct term? Does 'individual reactions' or something make more sense?
There was a problem hiding this comment.
This was actually already here, my PR just duplicated it for react but i've reverted that change. "raw" events is the correct term because the feature is called rawReactions in the API. And tbh i think the previous section adequately describes how summary reactions work, enough for this section to make sense. I agree that the channel options part is irrelevant so have removed that 👍
a6d7790 to
c7e8c19
Compare
|
|
||
| ### Configure the default reaction type <a id="default-type"/> | ||
|
|
||
| The default reaction type can be configured at room-level by passing `RoomOptions` when calling `rooms.get`. If nothing is set, the default is `Distinct`. |
There was a problem hiding this comment.
This sentence doesn't apply to React - with React it's the options passed to the ChatRoomProvider
There was a problem hiding this comment.
ah good spot, have wrapped in an thingy with a case for react
| import { ChatRoomProvider } from '@ably/chat/react'; | ||
|
|
||
| const MyComponent = () => { | ||
| const roomOptions = { |
There was a problem hiding this comment.
This would need to be outside the component or memoised, as the provide doesn't do that
There was a problem hiding this comment.
have moved it outside the component scope. to be fair, it costs basically nothing to redeclare a static object and i don't think this component would ever re-render anyway but agree it's slightly neater 👍
|
|
||
| return <div>...</div>; | ||
| }; | ||
| ``` |
There was a problem hiding this comment.
Not this PR, but the @ in the timeserial comes out a bit odd in the table below
| import { ChatRoomProvider } from '@ably/chat/react'; | ||
|
|
||
| const MyComponent = () => { | ||
| const roomOptions = { |
There was a problem hiding this comment.
Ditto re room options memoisation
c271ce5 to
ba68805
Compare
ba68805 to
ac8d6b0
Compare