Do not disturb by channel type
This guide describes how to set DND levels for a specified channel type.
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 channel type 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 type
The SDK allows a user to set DND levels for a specified channel type. Supported types: Direct, Group, and Community channels.
Set DND level for a channel type
Use BaseChannel.setChannelTypeNoDisturbLevel() with a ChannelTypeNoDisturbLevelParams to set the DND level for a channel type. Open channels are not supported because they do not receive message notifications by default.
Parameters (ChannelTypeNoDisturbLevelParams)
| Parameter | Type | Description |
|---|---|---|
channelType | ChannelType | Channel type: ChannelType.DIRECT, ChannelType.GROUP, or ChannelType.COMMUNITY. Open channels are not supported. |
level | ChannelNoDisturbLevel | DND level. |
- Kotlin
- Java
// Set DND for all Direct channels
val params = ChannelTypeNoDisturbLevelParams(
channelType = ChannelType.DIRECT,
level = ChannelNoDisturbLevel.MUTED
)
BaseChannel.setChannelTypeNoDisturbLevel(params) { error ->
if (error == null) {
// Successfully set
} else {
// Failed
}
}
// Set DND for all Group channels
val groupParams = ChannelTypeNoDisturbLevelParams(
channelType = ChannelType.GROUP,
level = ChannelNoDisturbLevel.MENTION_USERS
)
BaseChannel.setChannelTypeNoDisturbLevel(groupParams) { error ->
if (error == null) {
// Successfully set
}
}
// Set DND for all Direct channels
ChannelTypeNoDisturbLevelParams params = new ChannelTypeNoDisturbLevelParams(
ChannelType.DIRECT,
ChannelNoDisturbLevel.MUTED
);
BaseChannel.setChannelTypeNoDisturbLevel(params, error -> {
if (error == null) {
// Successfully set
} else {
// Failed
}
});
Remove DND level for a channel type
To remove DND for a channel type, call the set API and pass ChannelNoDisturbLevel.DEFAULT as the level.
- Kotlin
- Java
val params = ChannelTypeNoDisturbLevelParams(
channelType = ChannelType.DIRECT,
level = ChannelNoDisturbLevel.DEFAULT
)
BaseChannel.setChannelTypeNoDisturbLevel(params) { error ->
if (error == null) {
// DND removed
}
}
ChannelTypeNoDisturbLevelParams params = new ChannelTypeNoDisturbLevelParams(
ChannelType.DIRECT, ChannelNoDisturbLevel.DEFAULT
);
BaseChannel.setChannelTypeNoDisturbLevel(params, error -> {
if (error == null) {
// DND removed
}
});
Get DND level for a channel type
Use BaseChannel.getChannelTypeNoDisturbLevel() to retrieve the DND level for a specific channel type.
- Kotlin
- Java
BaseChannel.getChannelTypeNoDisturbLevel(ChannelType.DIRECT) { level, error ->
if (error == null && level != null) {
println("DND level for Direct channels: $level")
} else {
// Failed
}
}
BaseChannel.getChannelTypeNoDisturbLevel(ChannelType.DIRECT, (level, error) -> {
if (error == null && level != null) {
System.out.println("DND level for Direct channels: " + level);
} else {
// Failed
}
});
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.