Do not disturb by channel ID
This guide describes how to set DND levels for a specific sub-channel (channelId) in a Community channel.
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 (target 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 sub-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 sub-channel
Community channels support independent sub-channels that segregate message data (channels, messages, unread counts) and group members. The SDK allows users to set DND levels for specific sub-channels within Community channels.
Set DND level for a sub-channel
Use subChannel.setNoDisturbLevel() to set the DND level for a specific sub-channel. Obtain the sub-channel instance from CommunityChannel.getSubChannels() or construct it directly with CommunitySubChannel(subChannelId, channelId).
Parameters
| Parameter | Type | Description |
|---|---|---|
level | ChannelNoDisturbLevel | DND level. |
handler | ErrorHandler? | Callback. error is null on success. |
- Kotlin
- Java
// Obtain a sub-channel instance
val subChannel = CommunitySubChannel("subChannelId", "communityId")
// Set DND to notify only for @mentions of me
subChannel.setNoDisturbLevel(ChannelNoDisturbLevel.MENTION_USERS) { error ->
if (error == null) {
// Successfully set
} else {
// Failed
}
}
// Block all notifications
subChannel.setNoDisturbLevel(ChannelNoDisturbLevel.MUTED) { error ->
if (error == null) {
// Successfully blocked
}
}
CommunitySubChannel subChannel = new CommunitySubChannel("subChannelId", "communityId");
subChannel.setNoDisturbLevel(ChannelNoDisturbLevel.MENTION_USERS, error -> {
if (error == null) {
// Successfully set
} else {
// Failed
}
});
Remove DND level for a sub-channel
To remove DND for a sub-channel, call the set API and pass ChannelNoDisturbLevel.DEFAULT as the level.
- Kotlin
- Java
subChannel.setNoDisturbLevel(ChannelNoDisturbLevel.DEFAULT) { error ->
if (error == null) {
// DND removed
}
}
subChannel.setNoDisturbLevel(ChannelNoDisturbLevel.DEFAULT, error -> {
if (error == null) {
// DND removed
}
});
Get DND level for a sub-channel
CommunitySubChannel inherits the channelNoDisturbLevel property from BaseChannel.
- Kotlin
- Java
val subChannel = CommunitySubChannel("subChannelId", "communityId")
val level = subChannel.channelNoDisturbLevel
CommunitySubChannel subChannel = new CommunitySubChannel("subChannelId", "communityId");
ChannelNoDisturbLevel level = subChannel.getChannelNoDisturbLevel();
The value returned here is the current DND level cached on the channel object. To keep local state in sync across devices, also listen to the channel status sync callbacks documented in Multi-device channel status sync.
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.