Do not disturb by target ID
This guide describes how to set DND levels for a specific channel (channelId).
The Chat SDK supports multi-dimensional, multi-level DND settings.
- You can configure DND at the App Key level, sub-channel level (Community channels only), and user level. When the server determines whether to trigger a push notification, the priority order is: User-level > Community sub-channel default (Community channels only) > Community channel default (Community channels only) > App Key-level.
- Within user-level settings, multiple dimensions exist. The priority order is: Global DND > DND by sub-channel > DND by channel (channel ID) > DND by channel type. See DND overview.
Supported DND levels
DND levels control notifications based on @mention message types. The following levels are available for per-channel DND:
| Enum value | Value | Description |
|---|---|---|
ChannelNoDisturbLevel.ALL | -1 | Notify for all messages. |
ChannelNoDisturbLevel.DEFAULT | 0 | Not set. This is the initial default state. Note: When not set, if neither the Community channel nor its sub-channels have DND configured, the default behavior is to notify for all messages. |
ChannelNoDisturbLevel.MENTION | 1 | Only notify for @mention messages, including @specific user and @all members. |
ChannelNoDisturbLevel.MENTION_USERS | 2 | Only notify for @specific user messages. Only the mentioned user receives the notification. For example, if "@User_A" is sent, User_A receives a notification. @all does not trigger a notification. |
ChannelNoDisturbLevel.MENTION_ALL | 4 | Only notify for @all members messages. |
ChannelNoDisturbLevel.MUTED | 5 | No notifications at all, even for @mention messages. |
Manage DND by channel
Set DND levels for a specific channel (channelId) for the current user (userId). Supported types: Direct, Group, and Community channels.
Set DND level for a channel
Use channel.setNoDisturbLevel() to set the DND level for a specific channel for the current user.
Parameters
| Parameter | Type | Description |
|---|---|---|
level | ChannelNoDisturbLevel |
|
handler | ErrorHandler? | Callback. error is null on success. |
- Kotlin
- Java
// Get channel instance
val channel = DirectChannel("userId123")
// Or: val channel = GroupChannel("groupId456")
// Or: val channel = CommunityChannel("communityId789")
// Set to notify only for @mentions of me
channel.setNoDisturbLevel(ChannelNoDisturbLevel.MENTION_USERS) { error ->
if (error == null) {
// Successfully set
} else {
// Failed
}
}
// Block all notifications
channel.setNoDisturbLevel(ChannelNoDisturbLevel.MUTED) { error ->
if (error == null) {
// Successfully blocked
}
}
// Get channel instance
DirectChannel channel = new DirectChannel("userId123");
// Or: GroupChannel channel = new GroupChannel("groupId456");
// Or: CommunityChannel channel = new CommunityChannel("communityId789");
// Set to notify only for @mentions of me
channel.setNoDisturbLevel(ChannelNoDisturbLevel.MENTION_USERS, error -> {
if (error == null) {
// Successfully set
} else {
// Failed
}
});
// Block all notifications
channel.setNoDisturbLevel(ChannelNoDisturbLevel.MUTED, error -> {
if (error == null) {
// Successfully blocked
}
});
Community channel type: If you enabled Community channels before 2022.09.01, this API only sets the DND level for messages not belonging to any sub-channel by default. To change this behavior, submit a support ticket.
Open channel type: Not supported, because Open channels do not support push notification reminders.
Remove DND level for a channel
To remove DND for a channel, call the set API and pass ChannelNoDisturbLevel.DEFAULT as the level parameter.
- Kotlin
- Java
channel.setNoDisturbLevel(ChannelNoDisturbLevel.DEFAULT) { error ->
if (error == null) {
// DND removed
}
}
channel.setNoDisturbLevel(ChannelNoDisturbLevel.DEFAULT, error -> {
if (error == null) {
// DND removed
}
});
Get DND level for a channel
Read the channelNoDisturbLevel property from the channel object to get the cached value.
- Kotlin
- Java
// Read cached value
val channel = DirectChannel("userId123")
val cachedLevel = channel.channelNoDisturbLevel
// Read cached value
DirectChannel channel = new DirectChannel("userId123");
ChannelNoDisturbLevel cachedLevel = channel.getChannelNoDisturbLevel();
Multi-device sync
The SDK provides a channel status (pin and DND) sync mechanism. Set a channel status sync listener to receive real-time updates when the channel status changes on another device. See Multi-device channel status sync.
Use NCEngine.addChannelHandler() to listen for channel DND level changes:
- Kotlin
- Java
NCEngine.addChannelHandler("CHANNEL_STATUS", object : ChannelHandler {
override fun onChannelNoDisturbLevelSync(event: ChannelNoDisturbLevelSyncEvent) {
println("Channel ${event.channelIdentifier.channelId} DND level changed to: ${event.level}")
}
})
NCEngine.addChannelHandler("CHANNEL_STATUS", new ChannelHandler() {
@Override
public void onChannelNoDisturbLevelSync(@NonNull ChannelNoDisturbLevelSyncEvent event) {
System.out.println("Channel " + event.getChannelIdentifier().getChannelId() + " DND level changed to: " + event.getLevel());
}
});