Skip to main content

Global do not disturb

The SDK supports setting a global DND time window and DND level for the current user.

  • NCEngine.setNoDisturbTime() sets a DND time window starting at an arbitrary time (HH:MM:SS). The window repeats daily until you update or remove it. For example, to set permanent all-day DND, set startTime to 00:00:00 and spanMinutes to 1439.
  • Each user supports only one quiet hours window. Setting a new window replaces the previous one.
tip

During the SDK-configured global quiet hours:

  • If the client is offline, the server does not send push notifications.
  • Global DND is a user-level setting with the highest priority. When a user has Global DND configured, this setting always takes precedence.

When implementing local notifications in your app, check whether the app has moved to the background. Use the Chat SDK's global DND APIs to decide whether to display a local notification, achieving a global DND effect.

Set quiet hours and DND level

Use the following DND levels when setting quiet hours for the current user:

Enum valueValueDescription
NoDisturbTimeLevel.DEFAULT0Not set. The SDK falls back to checking the channel's user-level DND setting and other non-user-level settings.
NoDisturbTimeLevel.MENTION1Only notify for @mention messages, including @specific user and @all. For Direct channels, this effectively means no notifications.
NoDisturbTimeLevel.MUTED5No notifications at all, even for @mention messages.

Set quiet hours and level

Use NCEngine.setNoDisturbTime() to set a DND time window with NoDisturbTimeParams. When messages arrive during the quiet hours, the SDK uses the configured level to determine whether to send a push notification.

Parameters (NoDisturbTimeParams)

ParameterTypeDescription
startTimeStringStart time, down to the second. Format: HH:MM:SS, e.g., 01:31:17.
spanMinutesIntDuration of the DND window in minutes. Range: [1–1439]. Set to 1439 for all-day DND.
levelNoDisturbTimeLevelDND level: DEFAULT (0), MENTION (1), or MUTED (5).
timezoneStringTime zone. Case-sensitive, e.g., "Asia/Shanghai".
kotlin
val params = NoDisturbTimeParams(
startTime = "00:00:00",
spanMinutes = 1439,
level = NoDisturbTimeLevel.MUTED,
timezone = "Asia/Shanghai"
)

NCEngine.setNoDisturbTime(params) { error ->
if (error == null) {
// Successfully set
} else {
// Failed
}
}

Get quiet hours settings

Use NCEngine.getNoDisturbTime() to retrieve the current global DND settings.

kotlin
NCEngine.getNoDisturbTime { noDisturbTime, error ->
if (error == null && noDisturbTime != null) {
println("Start time: ${noDisturbTime.startTime}")
println("Span minutes: ${noDisturbTime.spanMinutes}")
println("Level: ${noDisturbTime.level}")
} else {
// Failed or not set
}
}

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.