Skip to content

Commit fea3179

Browse files
committed
Updated doc for chat history, added section ordering use-case and default param values
1 parent 5e26b51 commit fea3179

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
@@ -90,14 +90,25 @@ The following optional parameters can be passed when retrieving previously sent
9090

9191
| Parameter | Description |
9292
| --------- | ----------- |
93-
| 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. |
94-
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. |
95-
| orderBy | The order in which to retrieve messages from; either `oldestFirst` or `newestFirst`. |
96-
| limit | Maximum number of messages to be retrieved per page, up to 1,000. |
93+
| 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).** |
94+
| 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.** |
95+
| orderBy | The order in which to retrieve messages from; either `oldestFirst` or `newestFirst`. **Defaults to `newestFirst`.** |
96+
| limit | Maximum number of messages to be retrieved per page, up to 1,000. **Defaults to 100.** |
97+
98+
### Understanding message ordering <a id="understanding-message-ordering"/>
99+
100+
The `orderBy` parameter determines both *which* messages are retrieved and their return order:
101+
102+
| Order | Retrieves | Returns | Use case |
103+
| ----- | --------- | ------- | -------- |
104+
| `newestFirst` (default) | Most recent messages | `[newest, ..., oldest]` | Standard chat UIs |
105+
| `oldestFirst` | Oldest messages from room start | `[oldest, ..., newest]` | Archives, exports, admin tools |
106+
107+
**For typical chat applications:** Use `newestFirst` (default) to get recent messages, then reverse the result for chronological display.
97108

98109
## Retrieve messages sent prior to subscribing <a id="subscribe"/>
99110

100-
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.
111+
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.
101112

102113
<If lang="javascript,swift,kotlin">
103114
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">[`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/history-before-subscribe.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.
@@ -233,13 +244,17 @@ fun HistoryBeforeSubscribeComponent(room: Room) {
233244
```
234245
</Code>
235246

236-
The following parameters can be passed when retrieving previously sent messages:
247+
The following optional parameters can be passed when retrieving messages before subscribing:
237248

238249
| Parameter | Description |
239250
| --------- | ----------- |
240-
| 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. |
241-
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. |
242-
| limit | Maximum number of messages to be retrieved per page, up to 1,000. |
251+
| 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).** |
252+
| 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.** |
253+
| limit | Maximum number of messages to be retrieved per page, up to 1,000. **Defaults to 100.** |
254+
255+
<Aside>
256+
The `orderBy` parameter is not available for `historyBeforeSubscribe()`. Messages are always returned in `newestFirst` order.
257+
</Aside>
243258

244259
<If lang="jetpack">
245260

0 commit comments

Comments
 (0)