---
source_url: https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/messages/updates
title: Manage message updates
updated_at: 2026-05-22T11:04:16.331Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Manage message updates

Edit messages and receive real-time update events.

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) in the [Admin Portal](https://admin.pubnub.com/).
:::

## Edit messages

`editText()` replaces an existing message's content.

### Method signature

This method takes the following parameters:

```kotlin
message.editText(newText: String): PNFuture<Message>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| newText | String | Yes |  | New/updated text that you want to add in place of the existing message. |

#### Output

| Type | Description |
| --- | --- |
| `PNFuture<Message>` | An updated message instance with an added `edited` action type. |

### Sample code

Correct the number of the support ticket you sent to `78398`.

```kotlin
message.editText("Support ticket number corrected to 78398").async { result ->
    result.onSuccess {
        // handle success
        println("Ticket number successfully updated to 78398.")
    }.onFailure {
        // handle failure
        println("Failed to update the ticket number.")
    }
}
```

## Get message updates

Receive real-time updates when a message is edited, reactions are added or removed, or metadata changes.

### Method signature

```kotlin
message.onUpdated(callback: (message: Message) -> Unit): AutoCloseable
```

#### Input

| Parameter | Description |
| --- | --- |
| `callback` *Type: `(message: Message) -> Unit`Default: n/a | Function that receives the updated `Message` object when changes occur. |

#### Output

| Type | Description |
| --- | --- |
| `AutoCloseable` | Interface that lets you stop receiving message-related updates by invoking the `close()` method. |

### Sample code

Get updates for a specific message on the `support` channel.

```kotlin
val supportChannel: Channel
//...

val timetoken = 16200000000000000L
supportChannel.getMessage(timetoken).async { messageResult ->
    messageResult.onSuccess { message ->
        val subscription = message?.onUpdated { updatedMessage ->
            println("Updated message: $updatedMessage")
        }

        // to stop receiving updates:
        // subscription?.close()
    }.onFailure { error ->
        // handle failure
    }
}
```

## Get message updates (deprecated)

:::warning Deprecated methods
`streamUpdates()` is deprecated. Use [onUpdated()](#get-message-updates) instead. `streamUpdatesOn()` remains supported.
:::

Receive real-time updates when messages or [reactions](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/messages/reactions) change:

* `streamUpdates()` - updates for a single [Message object](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/learn/chat-entities/message)
* `streamUpdatesOn()` - updates for multiple `Message` objects

Both return an unsubscribe function.

:::note Stream update behavior
* `streamUpdates()` returns the entire updated `Message` on each change
* `streamUpdatesOn()` returns the complete list of monitored messages on each change
:::

### Method signature

These methods take the following parameters:

* streamUpdates() 1message.streamUpdates(callback: (message: T) -> Unit): AutoCloseable
* streamUpdatesOn() 1class Message {2 companion object {3 fun streamUpdatesOn(4 messages: Collection<Message>,5 callback: (messages: Collection<Message>) -> Unit6 ): AutoCloseable7 }8}

#### Input

| Parameter | Required in `streamUpdates()` | Required in `streamUpdatesOn()` | Description |
| --- | --- | --- | --- |
| `messages`Type: `Collection<Message>`Default: n/a | No | Yes | A collection of [Message objects](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/learn/chat-entities/message) for which you want to get updates on changed messages or message reactions. |
| `callback`Type: `(message: T) -> Unit`Default: n/a | Yes | No | Function that takes a single `Message` object. It defines the custom behavior to be executed when detecting message or message reaction changes. |
| `callback`Type: `messages: (Collection<Message>) -> Unit`Default: n/a | No | Yes | Function that takes a set of `Message` objects. It defines the custom behavior to be executed when detecting message or message reaction changes. |

#### Output

| Type | Description |
| --- | --- |
| `AutoCloseable` | Interface that lets you stop receiving message-related updates by invoking the `close()` method. |

### Sample code

* streamUpdates() Get message and message reaction-related updates for the message with the timetoken 16200000000000000 published on the support channel. 1val supportChannel: Channel2//...3 4// fetch the message with timetoken5val timetoken = 16200000000000000L6supportChannel.getMessage(timetoken).async { messageResult ->7 messageResult.onSuccess { message ->8 // stream updates for the specific message9 val autoCloseable = message?.streamUpdates { updatedMessage: Message ->10 // The callback receives the entire updated Message object (including all reactions)11 // each time a change occurs.12 println("-=Updated message: $updatedMessage")13 }14 15 // to stop streaming updates at some later point, use:16 // autoCloseable.close()17 }.onFailure { error ->18 // handle failure19 }20}
* streamUpdatesOn() Get message and message reaction-related updates for the first page of messages published on the support channel. 1// get the support channel2val supportChannel: Channel 3// ...4 5// fetch the first page of messages6supportChannel.getHistory(count = 25).async { historyResult ->7 historyResult.onSuccess { historyResponse ->8 val messages = historyResponse.messages9 10 // stream updates for the fetched messages11 val autoCloseable = Message.streamUpdatesOn(messages = messages) { updatedMessages ->12 // The callback receives the complete list of all messages you're monitoring13 // each time any change occurs.14 updatedMessages.forEach { updatedMessage ->15 println("-=Updated message: $updatedMessage")16 }17 }18 19 // to stop streaming updates at some later point, use:20 // autoCloseable.close()21 }.onFailure { error ->22 // handle failure23 println("Failed to fetch history: ${error.message}")24 }25}

### Other examples

* streamUpdates() Stop listening to updates for the message with the timetoken 16200000000000000 published on the support channel. 1// retrieve the support channel2val supportChannel: Channel 3// ...4 5// fetch the message with timetoken6val timetoken = 16200000000000000L7supportChannel.getMessage(timetoken).async { messageResult ->8 messageResult.onSuccess { message ->9 // stream updates for the specific message10 val autoCloseable = message?.streamUpdates<Message> { updatedMessage ->11 // The callback receives the entire updated Message object (including all reactions)12 // each time a change occurs.13 println("-=Updated message: $updatedMessage")14 }15 16 // simulate some processing after which updates are no longer needed17 // this could be based on some condition in a real application18 // for this example, we'll just use a delay to demonstrate stopping updates19 Thread.sleep(5000L) // Wait for 5 seconds before stopping updates20 21 // stop listening to updates22 autoCloseable?.close()23 println("Stopped listening to updates for the message with timetoken $timetoken.")24 }.onFailure { error ->25 // handle failure26 println("Failed to fetch message: ${error.message}")27 }28}
* streamUpdatesOn() Stop listening to updates for the last ten messages published on the support channel. 1// get the support channel2val supportChannel: Channel3// ...4 5// fetch the last ten messages6supportChannel.getHistory(count = 10).async { historyResult ->7 historyResult.onSuccess { historyResponse ->8 val messages = historyResponse.messages9 10 // stream updates for the fetched messages11 val autoCloseable = Message.streamUpdatesOn(messages = messages) { updatedMessages ->12 // The callback receives the complete list of all messages you're monitoring13 // each time any change occurs.14 updatedMessages.forEach { updatedMessage ->15 println("-=Updated message: $updatedMessage")16 }17 }18 19 // simulate some processing after which updates are no longer needed20 // this could be based on some condition in a real application21 // for this example, we'll just use a delay to demonstrate stopping updates22 Thread.sleep(5000L) // wait for 5 seconds before stopping updates23 24 // stop listening to updates25 autoCloseable.close()26 println("Stopped listening to updates for the last ten messages.")27 }.onFailure { error ->28 // handle failure29 println("Failed to fetch history: ${error.message}")30 }31}