You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chat: add Jetpack Compose support to documentation
- Added examples showcasing the use of Jetpack Compose APIs in the chat SDK.
- Updated documentation to include Jetpack Compose methods such as `collectAsPagingMessagesState()`, `collectAsCurrentlyTyping()`, `collectAsStatus()`, and others.
- Extended sections with Jetpack Compose-specific code snippets for message reactions, typing events, room management, and more.
Copy file name to clipboardExpand all lines: src/pages/docs/chat/connect.mdx
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,10 @@ Use the <If lang="javascript">[`status`](https://sdk.ably.com/builds/ably/ably-c
28
28
Use the [`currentStatus`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseChatConnectionResponse.html#currentStatus) property returned in the response of the [`useChatConnection`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.useChatConnection.html) hook to check which status a connection is currently in:
29
29
</If>
30
30
31
+
<Iflang="jetpack">
32
+
Use the [`collectAsStatus()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-status.html) composable function to observe the connection status as a State:
val connectionStatus by chatClient.connection.collectAsStatus()
70
+
71
+
Text("Connection status: $connectionStatus")
72
+
}
73
+
```
59
74
</Code>
60
75
61
76
<Iflang="react">
@@ -84,6 +99,10 @@ Listeners can also be registered to monitor the changes in connection status. An
84
99
Use the <Iflang="javascript">[`connection.onStatusChange()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Connection.html#onStatusChange)</If><Iflang="swift">[`connection.onStatusChange()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/connection/onstatuschange%28%29-76t7)</If><Iflang="kotlin">[`connection.status.onStatusChange()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-connection/on-status-change.html)</If> method to register a listener for status change updates:
85
100
</If>
86
101
102
+
<Iflang="jetpack">
103
+
In Jetpack Compose, you can use [`collectAsStatus()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-status.html) to observe status changes reactively:
104
+
</If>
105
+
87
106
<Code>
88
107
```javascript
89
108
const { off } =chatClient.connection.onStatusChange((change) =>console.log(change));
Copy file name to clipboardExpand all lines: src/pages/docs/chat/rooms/history.mdx
+60-9Lines changed: 60 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,11 @@
1
-
---
2
-
title: Message storage and history
3
-
meta_description: "Retrieve previously sent messages from history."
4
-
---
5
-
6
-
The history feature enables users to retrieve messages that have been previously sent in a room. Ably stores chat messages for 30 days by default. You can extend this up to 365 days by [contacting us](https://ably.com/support).
7
-
8
1
## Retrieve previously sent messages <aid="history"/>
9
2
10
3
<Iflang="javascript,swift,kotlin">
11
-
Use the <Iflang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><Iflang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><Iflang="kotlin">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages/history.html)</If> method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
4
+
Use the <Iflang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><Iflang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><Iflang="kotlin">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages/history.html)</If><Iflang="jetpack">[`collectAsPagingMessagesState()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-paging-messages-state.html)</If> method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
5
+
</If>
6
+
7
+
<Iflang="jetpack">
8
+
Use the [`collectAsPagingMessagesState()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/jetpack/chat-extensions-compose/com.ably.chat.extensions.compose/collect-as-paging-messages-state.html) method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
12
9
</If>
13
10
14
11
<Iflang="react">
@@ -71,6 +68,28 @@ while (historicalMessages.hasNext()) {
val pagingMessagesState by room.messages.collectAsPagingMessagesState(
82
+
orderBy = OrderBy.NewestFirst
83
+
)
84
+
85
+
LazyColumn {
86
+
items(pagingMessagesState.messages.size) { index ->
87
+
val message = pagingMessagesState.messages[index]
88
+
Text("Message: ${message.text}")
89
+
}
90
+
}
91
+
}
92
+
```
74
93
</Code>
75
94
76
95
The following optional parameters can be passed when retrieving previously sent messages:
@@ -90,6 +109,10 @@ Users can also retrieve historical messages that were sent to a room before the
90
109
Use the <Iflang="javascript">[`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.MessageSubscriptionResponse.html#historyBeforeSubscribe)</If><Iflang="swift">[`historyBeforeSubscribe(withParams:)`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messagesubscriptionresponse/historybeforesubscribe%28withparams%3A%29))</If><Iflang="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.
91
110
</If>
92
111
112
+
<Iflang="jetpack">
113
+
Use the [`getPreviousMessages()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/get-previous-messages.html) 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.
114
+
</If>
115
+
93
116
<Iflang="react">
94
117
Use the [`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-react.UseMessagesResponse.html#historyBeforeSubscribe) method available from the response of the `useMessages` hook to only retrieve messages that were received before the listener subscribed to the room. As long as a defined value is provided for the listener, and there are no message discontinuities, `historyBeforeSubscribe()` will return messages from the same point across component renders. If the listener becomes undefined, the subscription to messages will be removed. If you subsequently redefine the listener then `historyBeforeSubscribe()` will return messages from the new point of subscription. This returns a paginated response, which can be queried further to retrieve the next set of messages.
95
118
</If>
@@ -157,7 +180,7 @@ val subscription = room.messages.subscribe {
157
180
println("New message received")
158
181
}
159
182
160
-
var historicalMessages = subscription.historyBeforeSubscribe(limit =50)
183
+
var historicalMessages = subscription.getPreviousMessages(limit =50)
161
184
println(historicalMessages.items.toString())
162
185
163
186
while (historicalMessages.hasNext()) {
@@ -167,6 +190,34 @@ while (historicalMessages.hasNext()) {
0 commit comments