Conversation Do Not Disturb
This document describes how to set Do Not Disturb levels for specified conversations (targetId).
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 Value | Numeric Value | Description |
|---|---|---|
PUSH_NOTIFICATION_LEVEL_ALL_MESSAGE | -1 | All messages trigger notifications. |
PUSH_NOTIFICATION_LEVEL_DEFAULT | 0 | Not 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_MENTION | 1 | Only @ mention messages trigger notifications, including @ mentions of specific users and @ mentions of all members. |
PUSH_NOTIFICATION_LEVEL_MENTION_USERS | 2 | Only @ 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_ALL | 4 | Only @ mentions of all group members trigger notifications (only @所有人 notifications are received). |
PUSH_NOTIFICATION_LEVEL_BLOCKED | 5 | No 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)
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
| Parameter | Type | Description |
|---|---|---|
conversationType | [ConversationType] | Conversation type.Note the following restrictions:
|
targetId | String | Conversation ID |
lev | PushNotificationLevel |
|
callback | OperationCallback | Callback 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)
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
| Parameter | Type | Description |
|---|---|---|
conversationType | [ConversationType] | Conversation type |
targetId | String | Conversation ID |
callback | ResultCallback<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
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