Delete messages
delete() either permanently removes a historical message from Message Persistence or marks it as deleted (if you remove the message with the soft option).
Requires Message Persistence configuration
To manage messages, you must enable Message Persistence for your app's keyset in the Admin Portal. To delete messages from PubNub storage, you must also mark the Enable Delete-From-History option.
Method signature
This method takes the following parameters:
1message.delete(soft: Boolean = false, preserveFiles: Boolean = false): PNFuture<Message?>
Input
*  required
| Parameter | Description | 
|---|---|
| softType:  BooleanDefault: false | Define if you want to permanently remove message data. By default, the message data gets permanently deleted from Message Persistence. If you set this parameter to true, theMessageobject gets thedeletedstatus and you can still restore/get its data. | 
| preserveFilesType:  BooleanDefault: false | Define if you want to keep the files attached to the message or remove them. | 
Output
| Type | Description | 
|---|---|
| PNFuture<Message?> | For hard delete, the method returns the last version of the Messageobject before it was permanently deleted. For soft delete, an updated message instance with an addeddeletedaction type. | 
Sample code
Permanently delete the message with the 16200000000000001 timetoken from the support channel.
1val channel: Channel
2// ...
3
4// define the timetoken of the message to archive (soft delete)
5val messageTimetoken: Long = 16200000000000001
6
7channel.getMessage(messageTimetoken).async { messageResult ->
8    messageResult.onSuccess { message ->
9        // handle success
10        message?.delete()?.async { deleteResult ->
11            deleteResult.onSuccess {
12                // handle success
13                println("Message successfully deleted: ${it?.timetoken}")
14            }.onFailure {
15                // handle failure
Other examples
Archive (soft delete) the message with the 16200000000000001 timetoken from the support channel, keeping its data in Message Persistence.
1val channel: Channel
2// ...
3
4// define the timetoken of the message to archive (soft delete)
5val messageTimetoken: Long = 16200000000000001
6
7channel.getMessage(messageTimetoken).async { messageResult ->
8    messageResult.onSuccess { message ->
9        // handle success
10        message?.delete(soft = true)?.async { deleteResult ->
11            deleteResult.onSuccess {
12                // handle success
13                println("Message successfully soft deleted: ${it?.timetoken}")
14            }.onFailure {
15                // handle failure