Delete channels
Chat SDK lets you remove an existing channel (with or without deleting its historical data from the App Context storage) using one of these methods: delete() and deleteChannel().
Both of these methods give the same output. The only difference is that you call a given method either on the Chat (deleteChannel()) or the Channel (delete()) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to delete or not because it's already known.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Method signature
These methods take the following parameters:
- 
delete()1channel.delete(
 2 soft: Boolean = false
 3): PNFuture<Channel>
- 
deleteChannel()1chat.deleteChannel(
 2 id: String,
 3 soft: Boolean = false
 4): PNFuture<Channel>
Input
| Parameter | Required in delete() | Required in deleteChannel() | Description | 
|---|---|---|---|
| idType:  StringDefault: false | No | Yes | Unique channel identifier. | 
| softType:  BooleanDefault: false | No | No | Define if you want to permanently remove channel metadata. The channel metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true, theChannelobject gets thedeletedstatus, and you can still restore/get its data. | 
Output
| Type | Description | 
|---|---|
| PNFuture<Channel> | For hard delete, the method returns the last version of the Channelobject before it was permanently deleted. For soft delete,PNFuturecontaining an updated channel instance with the status field set todeleted. | 
Sample code
Permanently delete the support channel metadata.
- 
delete()1// reference the "channel" object and invoke the "delete()" method
 2chat.getChannel("support").async { result ->
 3 result.onSuccess { channel ->
 4 if (channel != null) {
 5 channel.delete().async { result2 -> ... }
 6 }
 7 }.onFailure {
 8 // handle failure
 9 }
 10}
- 
deleteChannel()1// reference the "chat" object and invoke the "deleteChannel()" method. By default, the "soft" parameter is set to "false" and can be skipped.
 2chat.deleteChannel("support").async { result ->
 3 result.onSuccess {
 4 // handle success
 5 }.onFailure {
 6 // handle failure
 7 }
 8}
Other examples
Archive (soft delete) the channel with the ID of support, keeping its data in the App Context storage.
- 
delete()1// reference the "channel" object and invoke the "delete()" method
 2chat.getChannel("support").async { result ->
 3 result.onSuccess { channel ->
 4 if (channel != null) {
 5 channel.delete(soft = true).async { result2 -> ... }
 6 }
 7 }.onFailure {
 8 // handle failure
 9 }
 10}
- 
deleteChannel()1chat.deleteChannel("support", soft = true).async { result ->
 2 result.onSuccess {
 3 // handle success
 4 }.onFailure {
 5 // handle failure
 6 }
 7}