Skip to content

Commit 533029f

Browse files
committed
Fix review comments:
- put utility function creation at the beginning of "update step" - explain where we add edit button
1 parent eebf156 commit 533029f

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/pages/docs/chat/getting-started/kotlin.mdx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,26 @@ You'll see the message in your app's chat box UI. If you have sent a message via
418418

419419
If your client makes a typo, or needs to update their original message then they can edit it. To do this, you can extend the functionality of the `ChatBox` component to allow updating of messages.
420420

421-
1. Add the edited state variable:
421+
1. We will begin by adding this utility function to facilitate message data updates in the UI:
422+
423+
<Code>
424+
```kotlin
425+
inline fun <T> MutableList<T>.replaceFirstWith(replacement: T, predicate: (T) -> Boolean) {
426+
val index = indexOfFirst(predicate)
427+
if (index != -1) set(index, replacement)
428+
}
429+
```
430+
</Code>
431+
432+
2. Add the edited state variable:
422433

423434
<Code>
424435
```kotlin
425436
var edited: Message? by remember { mutableStateOf(null) }
426437
```
427438
</Code>
428439

429-
2. Update the message subscription to handle edited messages:
440+
3. Update the message subscription to handle edited messages:
430441

431442
<Code>
432443
```kotlin
@@ -448,7 +459,10 @@ DisposableEffect(room) {
448459
```
449460
</Code>
450461

451-
3. Add an edit button to each message:
462+
4. Let's enhance the message display. To add an edit button to each message, we'll first need to locate
463+
the `Row` composable function within your layout. This is the component responsible for rendering
464+
the message content itself, along with the sender's username and the message timestamp.
465+
Once we've identified this `Row`, we will integrate the new edit button alongside these existing elements:
452466

453467
<Code>
454468
```kotlin
@@ -487,7 +501,7 @@ Row(
487501
```
488502
</Code>
489503

490-
4. Update the send button to handle both new messages and edits:
504+
5. Update the send button to handle both new messages and edits:
491505

492506
<Code>
493507
```kotlin
@@ -521,18 +535,6 @@ Button(
521535
</Code>
522536

523537

524-
525-
Add this utility function to help with message updates:
526-
527-
<Code>
528-
```kotlin
529-
inline fun <T> MutableList<T>.replaceFirstWith(replacement: T, predicate: (T) -> Boolean) {
530-
val index = indexOfFirst(predicate)
531-
if (index != -1) set(index, replacement)
532-
}
533-
```
534-
</Code>
535-
536538
When you click on the edit button in the UI, you can modify the text and it will send the updated message contents to the room.
537539

538540
## Step 6: Message history and continuity <a id="step-6"/>

0 commit comments

Comments
 (0)