Skip to main content

Set Do Not Disturb

This document describes how to configure Do Not Disturb for a specified conversation (targetId). When a conversation or certain messages are set to Do Not Disturb, if the mobile client is offline, it will not receive remote notification alerts. For IMKit clients, when the app runs in the background, it will not trigger notification alerts for conversations or messages set to Do Not Disturb, though message content can still be received.

Conversation Do Not Disturb settings will be synchronized to the server. RC automatically synchronizes these settings across devices for users. Clients can receive synchronization notifications through listeners or actively fetch the latest data.

Using Do Not Disturb Levels (SDK ≥ 5.3.0)

tip
  • Starting from SDK 5.3.0, Do Not Disturb level configuration (notificationLevel) is available, enabling apps to implement granular notification control strategies. Android/iOS mobile platforms support Do Not Disturb levels from SDK 5.2.2.
  • If your application is based on the Electron solution, Do Not Disturb levels (notificationLevel) are not currently supported. Please use the Do Not Disturb status configuration (notificationStatus). For details, see Using Do Not Disturb Status.

Due to the inherent characteristics of instant messaging services, apps may require granular notification control strategies. The current Web IMLib SDK supports multi-dimensional, multi-level Do Not Disturb settings.

  • Supports Do Not Disturb configuration at the App Key level, specific business segments (ultra groups only), and user level. When the RC server decides whether to trigger push notifications, the priority across different dimensions is as follows: User-level settings > Default configuration for specified ultra group channels (ultra groups only) > Default configuration for specified ultra group conversations (ultra groups only) > App Key-level settings.

  • User-level settings refer to Do Not Disturb configurations controllable by app users, encompassing multiple dimensions. When the RC server decides whether to trigger push notifications, if user-level configurations exist, the priority across different dimensions is as follows: Global Do Not Disturb > Channel-specific Do Not Disturb > Conversation-specific Do Not Disturb. For details, see Do Not Disturb Overview.

  • Customers using ultra group services should refer to the "Set Group/Channel Default Do Not Disturb" and "Set Specified Group/Channel Do Not Disturb" documentation under Ultra Group Management.

The Do Not Disturb level (notificationLevel) provides control over notifications for different types of @ messages. Starting from SDK 5.3.0, Do Not Disturb configurations support the following levels:

notificationLevel Enum ValueNumeric ValueDescription
NotificationLevel.ALL_MESSAGE-1Receive notifications for all messages (i.e., disable Do Not Disturb)
NotificationLevel.NOT_SET0Not set (default state when user has not configured; all messages trigger notifications. In this state, if ultra group default settings exist, they take precedence)
NotificationLevel.AT_MESSAGE_NOTIFICATION1Notify only for @ messages, including @specific users and @all
NotificationLevel.AT_USER_NOTIFICATION2Notify only for @specific user messages, and only notify the specified user
Example: @张三 will trigger a notification for Zhang San, but @all will not
NotificationLevel.AT_GROUP_ALL_USER_NOTIFICATION4Notify only for @all messages, receiving push notifications only for @all mentions
NotificationLevel.NOT_MESSAGE_NOTIFICATION5No notifications, even for @ messages

Set Do Not Disturb Level

tip

The Web platform supports the setConversationNotificationLevel interface starting from 5.3.0, while deprecating setConversationNotificationStatus. The Electron platform supports the setConversationNotificationLevel interface starting from version 5.8.4.

Call the [setConversationNotificationLevel] method to set the Do Not Disturb level.

Interface

RongIMLib.setConversationNotificationLevel(conversation, notificationLevel)


#### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| conversation | [IConversationOption] | Yes | Target conversation |
| notificationLevel | [NotificationLevel] | Yes | Do Not Disturb level |


#### Example Code

```js
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: 'targetId',
}
const notificationLevel = RongIMLib.NotificationLevel.NOT_MESSAGE_NOTIFICATION;
const res = await RongIMLib.setConversationNotificationLevel(conversation, notificationLevel);
console.info('Set conversation Do Not Disturb result:', res);


### Get Do Not Disturb Level \{#getConversationNotificationLevel}

:::tip
Starting from 5.3.0, `getConversationNotificationLevel` is supported, while `setConversationNotificationStatus` is deprecated.
:::

Call the [getConversationNotificationLevel] method to retrieve the Do Not Disturb level.


#### Interface

```js
RongIMLib.getConversationNotificationLevel(conversation)


#### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| conversation | [IConversationOption] | Yes | Target conversation |


#### Example Code

```js
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: 'targetId',
}
const res = await RongIMLib.getConversationNotificationLevel(conversation);
console.info('Query specified conversation and channel Do Not Disturb result:', res);


## Using Do Not Disturb Status (For Electron)

:::tip
- For Web applications with SDK versions < 5.3.0, use the `notificationStatus` related interfaces. For SDK versions ≥ 5.3.0, it is recommended to use the [Do Not Disturb Level](#level) feature.
- If your application is based on the Electron solution, currently only the following interfaces for setting Do Not Disturb status (`notificationStatus`) are supported. Configuring Do Not Disturb levels is not yet available.
:::


### Set Do Not Disturb Status \{#setConversationNotificationStatus}

Call the [setConversationNotificationStatus] method to set the Do Not Disturb status.


#### Interface

```js
RongIMLib.setConversationNotificationStatus(conversation, notificationStatus)


#### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| conversation | [IConversationOption] | Yes | Target conversation |
| notificationStatus | [NotificationStatus] | Yes | Do Not Disturb status |


#### Example Code

```js
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "targetId"
}
const notificationStatus = NotificationStatus.OPEN

// Set conversation to Do Not Disturb status
const res = RongIMLib.setConversationNotificationStatus(conversation, notificationStatus);
console.info('Set Do Not Disturb status result', res)


### Get Do Not Disturb Status \{#getConversationNotificationStatus}

Call the [getConversationNotificationStatus] method to query the Do Not Disturb status.


#### Interface

```js
RongIMLib.getConversationNotificationStatus(conversation)


#### Parameter Description

| Parameter | Type | Required | Description |
|:--- |:--- |:--- |:--- |
| conversation | [IConversationOption] | Yes | Target conversation |


#### Example Code

```js
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "targetId"
}

// Get conversation Do Not Disturb status
const res = RongIMLib.getConversationNotificationStatus(conversation);
console.info('Get Do Not Disturb status result', res)


## Get Do Not Disturb Conversation List

:::tip
This interface is supported starting from version 5.1.1.
:::

Call the [getBlockedConversationList] method to retrieve all conversations with Do Not Disturb enabled.


#### Interface

```js
RongIMLib.getBlockedConversationList()


#### Parameter Description

None


#### Example Code

```js
RongIMLib.getBlockedConversationList().then(res => {
if (res.code === 0) {
console.log('Get Do Not Disturb conversation list successfully:', res.data);
} else {
console.log('Failed to get Do Not Disturb list:', res.code);
}
});
<!-- links -->
[getBlockedConversationList]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#getBlockedConversationList
[ConversationType]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/enums/ConversationType.html
[setConversationNotificationLevel]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#setConversationNotificationLevel
[getConversationNotificationLevel]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#getConversationNotificationLevel
[setConversationNotificationStatus]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#setConversationNotificationStatus
[getConversationNotificationStatus]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#getConversationNotificationStatus
[IConversationOption]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/modules.html#IConversationOption
[NotificationLevel]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/enums/NotificationLevel.html
[NotificationStatus]: https://doc.rongcloud.cn/apidoc/im-web/latest/zh_CN/enums/NotificationStatus.html