Restore messages
restore() recovers soft-deleted messages and their attached files. Hard-deleted messages cannot be restored.
Requires Message Persistence
Enable Message Persistence and Enable Delete-From-History in the Admin Portal.
Method signature
This method has the following signature:
1message.restore(): PNFuture<Message>
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
PNFuture<Message> | Object returning the restored Message object. |
Sample code
Restore a previously soft deleted message with the 16200000000000001 timetoken.
1val timetoken: Long = 16200000000000001
2
3// fetch the target message from history
4channel.getMessage(timetoken).async { result ->
5 result.onSuccess { messageToTarget: Message? ->
6 when (messageToTarget?.deleted) {
7 true -> {
8 println("Message is deleted")
9 // restore the deleted message
10 messageToTarget.restore().async { restoreResult ->
11 restoreResult.onSuccess { restoredMessage ->
12 println("Message with timetoken $timetoken restored successfully: $restoredMessage")
13 }.onFailure { error ->
14 println("Failed to restore message with timetoken $timetoken: ${error.message}")
15 }
show all 25 lines