Deleting channels
Remove one or more channels from the channel list using the SDK's delete feature. The channel list on the client is generated from local messages, so deleting a channel removes its local record only.
Delete a single channel
Call channel.delete() to remove a specific channel from the channel list. This method does not delete messages within the channel — it only removes the channel from the SDK's channel list. After successful deletion, refresh your UI to stop displaying the channel.
- Kotlin
- Java
val channel = DirectChannel("userId")
channel.delete { success, error ->
if (error == null && success == true) {
// Channel deleted successfully
} else {
// Deletion failed: ${error?.message}
}
}
DirectChannel channel = new DirectChannel("userId");
channel.delete(new OperationHandler<Boolean>() {
@Override
public void onResult(Boolean success, NCError error) {
if (error == null && success != null && success) {
// Channel deleted successfully
} else {
// Deletion failed
}
}
});
If a new message arrives in a deleted channel, the channel reappears in the channel list. The user can then view the channel's message history and the latest message.
The SDK does not provide a single API to delete both a channel and its message history. To also delete messages, call the message deletion API separately when deleting the channel. See Deleting Messages for details.
Delete multiple channels
Call BaseChannel.deleteChannels() to delete multiple channels at once. Supported channel types: direct, group, system, and community channels.
- Kotlin
- Java
val identifiers = listOf(
ChannelIdentifier(ChannelType.DIRECT, "userId1"),
ChannelIdentifier(ChannelType.GROUP, "groupId1")
)
BaseChannel.deleteChannels(identifiers) { success, error ->
if (error == null && success == true) {
// Deleted successfully
} else {
// Deletion failed: ${error?.message}
}
}
List<ChannelIdentifier> identifiers = new ArrayList<>();
identifiers.add(new ChannelIdentifier(ChannelType.DIRECT, "userId1"));
identifiers.add(new ChannelIdentifier(ChannelType.GROUP, "groupId1"));
BaseChannel.deleteChannels(identifiers, new OperationHandler<Boolean>() {
@Override
public void onResult(Boolean success, NCError error) {
if (error == null && success != null && success) {
// Batch deletion succeeded
} else {
// Deletion failed
}
}
});
Parameters
| Parameter | Type | Description |
|---|---|---|
identifiers | List<ChannelIdentifier> | List of channel identifiers. Maximum 20 items. Each ChannelIdentifier requires a ChannelType and a channel ID. |
handler | OperationHandler<Boolean> | Callback for the operation result. |
This API only deletes channel records from the current user's local database. If your app has enabled cloud message storage, the user's server-side message history is not affected. To also delete server-side message history, see Deleting Messages.
Delete all channels
The SDK does not provide a method to delete all channels at once. To achieve this, retrieve the channel list first and then delete each channel individually.