Skip to main content

Conversation Do Not Disturb

This document describes how to set Do Not Disturb levels for specified conversations (targetId).

tip

The IM client SDK supports multi-dimensional, multi-level Do Not Disturb settings:

  • You can configure Do Not Disturb functionality across multiple dimensions: App Key, specific business segments (ultra groups only), and user levels. 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 include multiple sub-dimensions. When the RC server decides whether to trigger push notifications (if user-level configurations exist), the priority across different sub-dimensions is as follows: Global Do Not Disturb > Channel-based Do Not Disturb > Conversation-based Do Not Disturb > Conversation type-based Do Not Disturb. For details, see Do Not Disturb Overview.

Supported Do Not Disturb Levels

Do Not Disturb levels provide control over notifications for different types of @ mentions. Starting from SDK 5.2.2, the following levels are supported for conversation-specific Do Not Disturb configurations:

Enum ValueNumeric ValueDescription
PUSH_NOTIFICATION_LEVEL_ALL_MESSAGE-1All messages trigger notifications.
PUSH_NOTIFICATION_LEVEL_DEFAULT0Not set. This is the initial state when no setting is configured.

Note: In this state, if both ultra groups and group channels are unconfigured, the default Do Not Disturb level for ultra groups and channels is considered to notify all messages.
PUSH_NOTIFICATION_LEVEL_MENTION1Only @ mention messages trigger notifications, including @ mentions of specific users and @ mentions of all members.
PUSH_NOTIFICATION_LEVEL_MENTION_USERS2Only @ mentions of specific users trigger notifications, and only the mentioned users receive notifications.

Example: @张三 will trigger a notification for Zhang San, but @所有人 will not trigger any notifications.
PUSH_NOTIFICATION_LEVEL_MENTION_ALL4Only @ mentions of all group members trigger notifications (only @所有人 notifications are received).
PUSH_NOTIFICATION_LEVEL_BLOCKED5No notifications are received, even for @ mention messages.

SDK versions below 5.2.2 only support setting to Do Not Disturb state (no push notifications) or alert state (receive push notifications).

Managing Conversation Do Not Disturb Settings

IM service users (userId) can set Do Not Disturb levels for specified conversations (targetId), supporting one-to-one chats, group chats, and ultra group conversations.

Set Do Not Disturb Level for Specified Conversation (SDK ≥ 5.2.2)

tip

This interface is available in ChannelClient starting from version 5.2.2.

Sets the Do Not Disturb level for a specified conversation (targetId) for the current user.

Interface

ChannelClient.getInstance().setConversationNotificationLevel(conversationType, targetId, lev, callback);

Parameter Description

ParameterTypeDescription
conversationType[ConversationType]Conversation type.Note the following restrictions:
  • Ultra Group Conversation Type: If ultra group service was activated before 2022.09.01, setting Do Not Disturb levels for all messages in a single ultra group conversation ("all messages" refers to messages across all channels and messages not belonging to any channel) is not supported by default. This interface only sets the Do Not Disturb level for messages in the specified ultra group conversation (targetId) that do not belong to any channel. Submit a ticket to modify this.
  • Chatroom Conversation Type: Not supported, as chatroom messages do not support push notifications by default.
targetIdStringConversation ID
levPushNotificationLevel
  • -1: Notify all messages
  • 0: Not set (if unset by user, defaults to group or APP-level default settings; if unset, all messages trigger notifications)
  • 1: Only notify @ mention messages
  • 2: Only notify @ mentions of specific users

    Example: @张三 will trigger a notification for Zhang San, but @所有人 will not trigger any notifications.

  • 4: Only notify @ mentions of all group members (only @所有人 notifications are received)
  • 5: No notifications
callbackOperationCallbackCallback interface

Example Code

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "Conversation ID";

ChannelClient.getInstance().setConversationNotificationLevel(conversationType,targetId,
IRongCoreEnum.PushNotificationLevel.PUSH_NOTIFICATION_LEVEL_DEFAULT,new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {

}

@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {

}
});

Remove Do Not Disturb Level for Specified Conversation (SDK ≥ 5.2.2)

To remove the Do Not Disturb setting for a specified conversation type, call the set interface and pass 0 for the lev parameter.

Query Do Not Disturb Level for Specified Conversation (SDK ≥ 5.2.2)

tip

This interface is available in ChannelClient starting from version 5.2.2.

Queries the Do Not Disturb level set by the current user for a specified conversation (targetId).

Interface

ChannelClient.getInstance().getConversationChannelNotificationLevel(conversationType, targetId, callback);

Parameter Description

ParameterTypeDescription
conversationType[ConversationType]Conversation type
targetIdStringConversation ID
callbackResultCallback<IRongCoreEnum.PushNotificationLevel>Callback interface

Example Code

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "Conversation ID";

ChannelClient.getInstance().getConversationChannelNotificationLevel(conversationType, targetId, new IRongCoreCallback.ResultCallback<
IRongCoreEnum.PushNotificationLevel>() {
@Override
public void onSuccess(IRongCoreEnum.PushNotificationLevel level) {

}
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {

});

Retrieve Do Not Disturb Status List

tip

This interface is in RongIMClient.

Retrieves all conversations with Do Not Disturb enabled. The returned conversation list does not include specific Do Not Disturb level information or channel details.

Interface

RongIMClient.getInstance().getBlockedConversationList(callback,conversationTypes);


#### Parameter Description

| Parameter | Type | Description |
|:------------------|:--------------------------------------|:-----------------------------------------------------------------------------|
| `callback` | `ResultCallback<List<Conversation>>` | Callback interface |
| `conversationTypes` | [`ConversationType`] | Array of conversation types, multiple conversation types can be set (chatrooms not supported). |


##### Example Code

```java
Conversation.ConversationType[] conversationTypes = {ConversationType.PRIVATE, ConversationType.GROUP};

RongIMClient.getInstance().getBlockedConversationList(new RongIMClient.ResultCallback<List<Conversation>>() {

@Override
public void onSuccess(List<Conversation> conversations) {

}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {

}
}, conversationTypes);


## Multi-Device Do Not Disturb Status Synchronization \{#setlistener}

The SDK provides a conversation status (pinned or Do Not Disturb) synchronization mechanism. By setting up a conversation status synchronization listener, when conversation status is modified on other devices, the changes can be monitored in real-time on the current device. For details, see [Multi-Device Do Not Disturb/Pinned Status Synchronization](./share-conversation-status-between-clients.md).

<!--links -->
[`ConversationType`]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/zh_CN/html/-android--i-m-lib-core--s-d-k/io.rong.imlib.model/-conversation/-conversation-type/index.html