Deleting group channels
Remove one or more group 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 the local record only.
Delete a single group channel
Call channel.delete() to remove a group channel from the channel list. This method does not delete messages within the channel — it only removes the channel entry. After successful deletion, refresh your UI to stop displaying the channel.
- Kotlin
- Java
val channel = GroupChannel("groupId")
channel.delete { success, error ->
if (error == null && success == true) {
// Channel deleted successfully
} else {
// Deletion failed: ${error?.message}
}
}
GroupChannel channel = new GroupChannel("groupId");
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 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. 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 channelIdentifiers = listOf(
ChannelIdentifier(ChannelType.GROUP, "groupId1"),
ChannelIdentifier(ChannelType.GROUP, "groupId2"),
ChannelIdentifier(ChannelType.DIRECT, "userId1")
)
BaseChannel.deleteChannels(channelIdentifiers) { success, error ->
if (error == null && success == true) {
// Deleted successfully
} else {
// Deletion failed: ${error?.message}
}
}
List<ChannelIdentifier> channelIdentifiers = new ArrayList<>();
channelIdentifiers.add(new ChannelIdentifier(ChannelType.GROUP, "groupId1"));
channelIdentifiers.add(new ChannelIdentifier(ChannelType.GROUP, "groupId2"));
channelIdentifiers.add(new ChannelIdentifier(ChannelType.DIRECT, "userId1"));
BaseChannel.deleteChannels(channelIdentifiers, 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, server-side message history is not affected. To also delete server-side 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.