Restore messages

If you delete a message, you can restore its content together with the attached files using the restore() method.

This is possible, however, only if the message you want to restore was soft deleted (the soft parameter was set to true when deleting it). Hard deleted messages cannot be restored as their data is no longer available in Message Persistence.

Requires Message Persistence configuration

To manage messages, you must enable Message Persistence for your app's keyset in the Admin Portal and mark the Enable Delete-From-History option.

Method signature

This method has the following signature:

message.restore(): PNFuture<Message>

Input

This method doesn't take any parameters.

Output

TypeDescription
PNFuture<Message>Object returning the restored Message object.

Basic usage

Restore a previously soft deleted message with the 16200000000000001 timetoken.

val timetoken: Long = 16200000000000001

// fetch the target message from history
channel.getMessage(timetoken).async { result ->
result.onSuccess { messageToTarget: Message? ->
when (messageToTarget?.deleted) {
true -> {
println("Message is deleted")
// restore the deleted message
messageToTarget.restore().async { restoreResult ->
restoreResult.onSuccess { restoredMessage ->
println("Message with timetoken $timetoken restored successfully: $restoredMessage")
}.onFailure { error ->
println("Failed to restore message with timetoken $timetoken: ${error.message}")
}
show all 25 lines
Last updated on