Set DND by channel
Set DND level for a channel
Set the DND level for a specific channel by calling channel.setNoDisturbLevel(). Supports direct, group, and community channels.
Method
Dart
Future<int> setNoDisturbLevel(ChannelNoDisturbLevel level, ErrorHandler handler)
Parameters
| Parameter | Type | Description |
|---|---|---|
level | ChannelNoDisturbLevel | DND level. See DND overview. |
handler | ErrorHandler | Event callback. |
Code example
Dart
final channel = DirectChannel('<target-user-id>');
await channel.setNoDisturbLevel(
ChannelNoDisturbLevel.blocked,
(error) {
if (error?.isSuccess == true) {
print('DND level set');
}
},
);
Get DND level for a channel
Use channel.reload() to refresh channel data, then read channel.notificationLevel.
Get DND channel list
Use BaseChannel.createChannelsQuery() to page through channels, then filter by notificationLevel.
Dart
final query = BaseChannel.createChannelsQuery(
ChannelsQueryParams(
channelTypes: [ChannelType.direct, ChannelType.group, ChannelType.community],
pageSize: 20,
),
);
await query.loadNextPage((result, error) {
if (error == null) {
final dndChannels = result?.data
.where((channel) => channel.notificationLevel != ChannelNoDisturbLevel.allMessage)
.toList() ??
[];
print('DND channels: ${dndChannels.length}');
}
});