Delete channels
Remove a channel permanently or soft-delete it (keeping historical data in App Context storage) with delete() or deleteChannel().
Both methods produce the same result. Call delete() on a Channel object or deleteChannel() on the Chat object with the channel ID.
Requires App Context
Enable App Context for your 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, the Channel object gets the deleted status, and you can still restore/get its data. |
Output
| Type | Description |
|---|---|
PNFuture<Channel> | For hard delete, the method returns the last version of the Channel object before it was permanently deleted. For soft delete, PNFuture containing an updated channel instance with the status field set to deleted. |
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}