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()
channel.delete(
soft: Boolean = false
): PNFuture<Channel> -
deleteChannel()
chat.deleteChannel(
id: String,
soft: Boolean = false
): PNFuture<Channel>
Input
Parameter | Type | Required in delete() | Required in deleteChannel() | Default | Description |
---|---|---|---|---|---|
id | String | No | Yes | false | Unique channel identifier. |
soft | Boolean | No | No | false | 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 . |
Basic usage
Permanently delete the support
channel metadata.
-
delete()
// reference the "channel" object and invoke the "delete()" method
chat.getChannel("support").async { result ->
result.onSuccess { channel ->
if (channel != null) {
channel.delete().async { result2 -> ... }
}
}.onFailure {
// handle failure
}
} -
deleteChannel()
// reference the "chat" object and invoke the "deleteChannel()" method. By default, the "soft" parameter is set to "false" and can be skipped.
chat.deleteChannel("support").async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}
Other examples
Archive (soft delete) the channel with the ID of support
, keeping its data in the App Context storage.
-
delete()
// reference the "channel" object and invoke the "delete()" method
chat.getChannel("support").async { result ->
result.onSuccess { channel ->
if (channel != null) {
channel.delete(soft = true).async { result2 -> ... }
}
}.onFailure {
// handle failure
}
} -
deleteChannel()
chat.deleteChannel("support", soft = true).async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}