Skip to content

Commit 6f882b7

Browse files
committed
Updated doc for chat history, added section ordering use-case and default param values
1 parent 01553ed commit 6f882b7

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

src/pages/docs/chat/rooms/history.mdx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,25 @@ The following optional parameters can be passed when retrieving previously sent
7777

7878
| Parameter | Description |
7979
| --------- | ----------- |
80-
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. |
81-
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. |
82-
| orderBy | The order in which to retrieve messages from; either `oldestFirst` or `newestFirst`. |
83-
| limit | Maximum number of messages to be retrieved per page, up to 1,000. |
80+
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. **Defaults to no lower bound (earliest available message).** |
81+
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. **Defaults to current time.** |
82+
| orderBy | The order in which to retrieve messages from; either `oldestFirst` or `newestFirst`. **Defaults to `newestFirst`.** |
83+
| limit | Maximum number of messages to be retrieved per page, up to 1,000. **Defaults to 100.** |
84+
85+
### Understanding message ordering <a id="understanding-message-ordering"/>
86+
87+
The `orderBy` parameter determines both *which* messages are retrieved and their return order:
88+
89+
| Order | Retrieves | Returns | Use case |
90+
| ----- | --------- | ------- | -------- |
91+
| `newestFirst` (default) | Most recent messages | `[newest, ..., oldest]` | Standard chat UIs |
92+
| `oldestFirst` | Oldest messages from room start | `[oldest, ..., newest]` | Archives, exports, admin tools |
93+
94+
**For typical chat applications:** Use `newestFirst` (default) to get recent messages, then reverse the result for chronological display.
8495

8596
## Retrieve messages sent prior to subscribing <a id="subscribe"/>
8697

87-
Users can also retrieve historical messages that were sent to a room before the point that they registered a listener by [subscribing](/docs/chat/rooms/messages#subscribe). The order of messages returned is from most recent, to oldest. This is useful for providing conversational context when a user first joins a room, or when they subsequently rejoin it later on. It also ensures that the message history they see is continuous, without any overlap of messages being returned between their subscription and their history call.
98+
Retrieve historical messages sent before subscribing using [`historyBeforeSubscribe()`](#understanding-message-ordering). Messages are returned in `newestFirst` order. This is useful for providing conversational context when a user joins or rejoins a room, ensuring continuous message history without overlap.
8899

89100
<If lang="javascript,swift,kotlin">
90101
Use the <If lang="javascript">[`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#historyBeforeSubscribe)</If><If lang="swift">[`historyBeforeSubscribe(withParams:)`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messagesubscriptionresponse/historybeforesubscribe%28withparams%3A%29))</If><If lang="kotlin">[`getPreviousMessages()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/get-previous-messages.html)</If> function returned as part of a [message subscription](/docs/chat/rooms/messages#subscribe) response to only retrieve messages that were received before the listener was subscribed to the room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
@@ -169,10 +180,14 @@ println("End of messages")
169180
```
170181
</Code>
171182

172-
The following parameters can be passed when retrieving previously sent messages:
183+
The following optional parameters can be passed when retrieving messages before subscribing:
173184

174185
| Parameter | Description |
175186
| --------- | ----------- |
176-
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. |
177-
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. |
178-
| limit | Maximum number of messages to be retrieved per page, up to 1,000. |
187+
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. **Defaults to no lower bound (earliest available message).** |
188+
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. **Defaults to current time.** |
189+
| limit | Maximum number of messages to be retrieved per page, up to 1,000. **Defaults to 100.** |
190+
191+
<Aside>
192+
The `orderBy` parameter is not available for `historyBeforeSubscribe()`. Messages are always returned in `newestFirst` order.
193+
</Aside>

0 commit comments

Comments
 (0)