Skip to main content

Delete a channel

Remove a channel from the channel list without deleting its messages. If a new message arrives in the channel, previous messages remain. To also delete messages, call the delete messages API separately.

This is a BaseChannel instance method.

Method

Dart
Future<int> delete(ErrorHandler handler);

Code example

Dart
BaseChannel channel = ...;

int? ret = await channel.delete((NCError? error) {
if (error?.isSuccess == true) {
print('Channel deleted');
}
});

Delete channels in batch

Delete multiple channels by their identifiers.

Method

Dart
static Future<int> deleteChannels(List<ChannelIdentifier> identifiers, ErrorHandler handler);

Code example

Dart
int? ret = await BaseChannel.deleteChannels(
[
ChannelIdentifier(channelType: ChannelType.direct, channelId: '<target-user-id>'),
ChannelIdentifier(channelType: ChannelType.group, channelId: '<group-id>'),
],
(NCError? error) {
if (error?.isSuccess == true) {
print('Delete succeeded');
}
},
);

Delete all channels

The SDK does not provide a dedicated "delete all" method. Query the channels you want to remove, convert them to ChannelIdentifier values, and then call deleteChannels().

Dart
final identifiers = [
ChannelIdentifier(channelType: ChannelType.direct, channelId: '<target-user-id>'),
ChannelIdentifier(channelType: ChannelType.group, channelId: '<group-id>'),
ChannelIdentifier(channelType: ChannelType.system, channelId: '<system-channel-id>'),
];

await BaseChannel.deleteChannels(
identifiers,
(NCError? error) { },
);