Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/languages/languageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
react: '1.1',
swift: '1.0',
kotlin: '1.1',
jetpack: '1.1',
android: '1.1',
},
aiTransport: {
javascript: '2.11',
Expand Down
7 changes: 2 additions & 5 deletions src/data/languages/languageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export default {
},
android: {
label: 'Android',
syntaxHighlighterKey: 'java',
syntaxHighlighterKey: 'kotlin',
alias: 'android-full',
},
flutter: {
label: 'Flutter',
Expand All @@ -86,10 +87,6 @@ export default {
label: 'Kotlin',
syntaxHighlighterKey: 'kotlin',
},
jetpack: {
label: 'Jetpack Compose',
syntaxHighlighterKey: 'kotlin',
},
realtime: {
label: 'Realtime',
syntaxHighlighterKey: 'javascript',
Expand Down
2 changes: 0 additions & 2 deletions src/data/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const languageKeys = [
'rest',
'css',
'laravel',
'typescript',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescript here is a duplicate entry

'jetpack',
] as const;

export type LanguageKey = (typeof languageKeys)[number];
Expand Down
14 changes: 7 additions & 7 deletions src/pages/docs/chat/connect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ A connection can have any of the following statuses:
| `closed` | The connection has been explicitly closed by the client. In the closed state, no reconnection attempts are made automatically. No connection state is preserved by the service or the library. |
| `failed` | This status is entered if the SDK encounters a failure condition that it cannot recover from. This may be a fatal connection error received from the Ably service, such as an attempt to connect with an incorrect API key, or some local terminal error, such as that the token in use has expired and the SDK does not have any way to renew it. |

<If lang="javascript,swift,kotlin,jetpack">
Use the <If lang="javascript">[`status`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Connection.html#status)</If><If lang="swift">[`status`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/connectionstatus)</If><If lang="kotlin,jetpack">[`status`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-connection/status.html)</If> property to check which status a connection is currently in:
<If lang="javascript,swift,kotlin,android">
Use the <If lang="javascript">[`status`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Connection.html#status)</If><If lang="swift">[`status`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/connectionstatus)</If><If lang="kotlin,android">[`status`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-connection/status.html)</If> property to check which status a connection is currently in:
</If>

<If lang="react">
Expand Down Expand Up @@ -57,7 +57,7 @@ let status = chatClient.connection.status
val connectionStatus = chatClient.connection.status
```

```jetpack
```android
val connectionStatus = chatClient.connection.status
```
</Code>
Expand Down Expand Up @@ -88,7 +88,7 @@ Listeners can also be registered to monitor the changes in connection status. An
Use the <If lang="javascript">[`connection.onStatusChange()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Connection.html#onStatusChange)</If><If lang="swift">[`connection.onStatusChange()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/connection/onstatuschange%28%29-76t7)</If><If lang="kotlin">[`connection.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:
</If>

<If lang="jetpack">
<If lang="android">
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:
</If>

Expand Down Expand Up @@ -123,7 +123,7 @@ val (off) = chatClient.connection.onStatusChange { statusChange: ConnectionStatu
}
```

```jetpack
```android
import androidx.compose.material.*
import androidx.compose.runtime.*
import com.ably.chat.ChatClient
Expand Down Expand Up @@ -174,7 +174,7 @@ The Chat SDK provides an `onDiscontinuity()` handler exposed via the Room object
Any hooks that take an optional listener to monitor their events, such as typing indicator events in the `useTyping` hook, can also register a listener to be notified of, and handle, periods of discontinuity.
</If>

<If lang="jetpack">
<If lang="android">
Use the [`discontinuityAsFlow()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/discontinuity-as-flow.html) extension function to observe discontinuity events as a Flow in Jetpack Compose:
</If>

Expand Down Expand Up @@ -215,7 +215,7 @@ val (off) = room.onDiscontinuity { reason: ErrorInfo ->
}
```

```jetpack
```android
import androidx.compose.runtime.*
import com.ably.chat.Room
import com.ably.chat.discontinuityAsFlow
Expand Down
43 changes: 21 additions & 22 deletions src/pages/docs/chat/getting-started/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ Create a new Android project with Jetpack Compose. For detailed instructions, re
6. Add the Ably dependencies to your app-level `build.gradle.kts` file:

<Code>
```kotlin
```android
implementation("com.ably.chat:chat:<latest-version>")
// This package contains extension functions for better Jetpack Compose integration.
// It's experimental for now (safe to use, but the API may change later). You can always use its code as a reference.
// Following package contains extension functions for better Jetpack Compose integration.
implementation("com.ably.chat:chat-extensions-compose:<latest-version>")
```
</Code>
Expand Down Expand Up @@ -71,7 +70,7 @@ Replace the contents of your `MainActivity.kt` file with the following code to s
Note that this is for example purposes only. In production, you should use [token authentication](/docs/auth/token) to avoid exposing your API keys publicly, the [`clientId`](/docs/auth/identified-clients) is used to identify the client:

<Code>
```kotlin
```android
package com.example.chatexample

import android.os.Bundle
Expand Down Expand Up @@ -147,7 +146,7 @@ Clients establish a connection with Ably when they instantiate an SDK. This enab
In your `MainActivity.kt` file, add the following `ConnectionStatusUi` composable component:

<Code>
```kotlin
```android
// This component will display the current connection status
@Composable
fun ConnectionStatusUi(connection: Connection) {
Expand All @@ -164,7 +163,7 @@ fun ConnectionStatusUi(connection: Connection) {
Update the `App` component to display the connection status using the new `ConnectionStatusUi` component:

<Code>
```kotlin
```android
@Composable
fun App(chatClient: ChatClient) {
Scaffold { paddingValues ->
Expand All @@ -190,7 +189,7 @@ Now that you have a connection to Ably, you can create a room. Use rooms to sepa
In your project, open `MainActivity.kt`, and add a new component called `RoomStatusUi`:

<Code>
```kotlin
```android
@Composable
fun RoomStatusUi(roomName: String, room: Room?) {
val roomStatus = room?.collectAsStatus()?.value
Expand All @@ -206,7 +205,7 @@ fun RoomStatusUi(roomName: String, room: Room?) {
Update your main app component to get and attach to the room and nest the `RoomStatusUi` component inside it:

<Code>
```kotlin
```android
@Composable
fun App(chatClient: ChatClient) {
val roomName = "my-first-room"
Expand Down Expand Up @@ -244,7 +243,7 @@ Messages are how your clients interact with one another.
In your project, open `MainActivity.kt`, and add a new component called `ChatBox`:

<Code>
```kotlin
```android
@Composable
fun ChatBox(room: Room?) {
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -368,7 +367,7 @@ fun ChatBox(room: Room?) {
Add the `ChatBox` component to your main app component:

<Code>
```kotlin
```android
@Composable
fun App(chatClient: ChatClient) {
val roomName = "my-first-room"
Expand Down Expand Up @@ -421,7 +420,7 @@ If your client makes a typo, or needs to update their original message then they
1. We will begin by adding this utility function to facilitate message data updates in the UI:

<Code>
```kotlin
```android
inline fun <T> MutableList<T>.replaceFirstWith(replacement: T, predicate: (T) -> Boolean) {
val index = indexOfFirst(predicate)
if (index != -1) set(index, replacement)
Expand All @@ -432,15 +431,15 @@ If your client makes a typo, or needs to update their original message then they
2. Add the edited state variable:

<Code>
```kotlin
```android
var edited: Message? by remember { mutableStateOf(null) }
```
</Code>

3. Update the message subscription to handle edited messages:

<Code>
```kotlin
```android
LaunchedEffect(room) {
room?.messages?.asFlow()?.collect { event ->
when (event.type) {
Expand All @@ -461,7 +460,7 @@ the message content itself, along with the sender's username and the message tim
Once we've identified this `Column`, we will integrate the new edit button alongside these existing elements. Replace the `Column` with the following:

<Code>
```kotlin
```android
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
Expand Down Expand Up @@ -500,7 +499,7 @@ Row(
5. Update the send button to handle both new messages and edits:

<Code>
```kotlin
```android
Button(
onClick = {
sending = true
Expand Down Expand Up @@ -540,7 +539,7 @@ Ably Chat enables you to retrieve previously sent messages in a room. This is us
Extend the `ChatBox` component to include a method to retrieve the last 10 messages when the component mounts. In your `MainActivity.kt` file, add the `DisposableEffect` in your `ChatBox` component:

<Code>
```kotlin
```android
fun ChatBox(room: Room?) {
/* variables declaration */
var subscription by remember { mutableStateOf<MessagesSubscription?>(null) }
Expand Down Expand Up @@ -579,7 +578,7 @@ You also can use `collectAsPagingMessagesState` to automatically subscribe to ne
and lazily load previous messages as you scroll through the message list.

<Code>
```kotlin
```android
@Composable
fun ChatBox(room: Room?) {
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -715,7 +714,7 @@ Display the online status of clients using the presence feature. This enables cl
In your `MainActivity.kt` file, create a new component called `PresenceStatusUi`:

<Code>
```kotlin
```android
@Composable
fun PresenceStatusUi(room: Room?) {
val membersState = room?.collectAsPresenceMembers()
Expand All @@ -737,7 +736,7 @@ fun PresenceStatusUi(room: Room?) {
Add the `PresenceStatusUi` component to your main app component:

<Code>
```kotlin
```android
@Composable
fun App(chatClient: ChatClient) {
val roomName = "my-first-room"
Expand Down Expand Up @@ -787,7 +786,7 @@ Clients can send a reaction to a room to show their sentiment for what is happen
In your `MainActivity.kt` file, add a new component called `ReactionBar`:

<Code>
```kotlin
```android
@Composable
fun ReactionBar(room: Room?) {
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -864,7 +863,7 @@ fun ReactionBar(room: Room?) {
Add the `ReactionBar` component to your main app component:

<Code>
```kotlin
```android
@Composable
fun App(chatClient: ChatClient) {
val roomName = "my-first-room"
Expand Down Expand Up @@ -913,7 +912,7 @@ ably rooms reactions send my-first-room 👍
To gracefully close connection and clean up resources, you can subscribe to activity lifecycle events and close the connection when activity has paused or stopped, and then reconnect when activity resumes. To do this modify `MainActivity` class:

<Code>
```kotlin
```android
class MainActivity : ComponentActivity() {
private lateinit var realtimeClient: AblyRealtime
private lateinit var chatClient: ChatClient
Expand Down
14 changes: 7 additions & 7 deletions src/pages/docs/chat/rooms/history.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ The history feature enables users to retrieve messages that have been previously

## Retrieve previously sent messages <a id="history"/>

<If lang="javascript,swift,kotlin,jetpack">
Use the <If lang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><If lang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><If lang="kotlin,jetpack">[`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.
<If lang="javascript,swift,kotlin,android">
Use the <If lang="javascript">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#history)</If><If lang="swift">[`messages.history()`](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/messages/history(withparams:))</If><If lang="kotlin,android">[`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.
</If>

<If lang="react">
Expand Down Expand Up @@ -72,7 +72,7 @@ while (historicalMessages.hasNext()) {
println("End of messages")
```

```jetpack
```android
var historicalMessages = room.messages.history(orderBy = OrderBy.NewestFirst)
println(historicalMessages.items.toString())

Expand Down Expand Up @@ -103,7 +103,7 @@ Users can also retrieve historical messages that were sent to a room before the
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.
</If>

<If lang="jetpack">
<If lang="android">
Use the [`historyBeforeSubscribe()`](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/chat/com.ably.chat/-messages-subscription/history-before-subscribe.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.
</If>

Expand Down Expand Up @@ -185,7 +185,7 @@ while (historicalMessages.hasNext()) {
println("End of messages")
```

```jetpack
```android
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
Expand Down Expand Up @@ -241,7 +241,7 @@ The following parameters can be passed when retrieving previously sent messages:
| `end` | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. |
| `limit` | Maximum number of messages to be retrieved per page, up to 1,000. |

<If lang="jetpack">
<If lang="android">

## Messages pagination <a id="messages-pagination"/>

Expand Down Expand Up @@ -269,7 +269,7 @@ The returned [`PagingMessagesState`](https://sdk.ably.com/builds/ably/ably-chat-
- `refresh()`: A function to clear the error state and retry loading

<Code>
```jetpack
```android
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Button
Expand Down
Loading