Global Do Not Disturb
The SDK supports setting a global Do Not Disturb period and level for the current user.
- This feature allows setting a Do Not Disturb time window starting from any time point (
HH:MM:SS
). The set Do Not Disturb time window will repeat daily until it is reset or removed. For example, if an App user wants to set permanent all-day Do Not Disturb, they can setstartTime
to00:00:00
andperiod
to1439
. - A single user can only set one time window. Repeated settings will overwrite the previously set time window.
During the global Do Not Disturb period set via the SDK:
- If the client is offline, RC server will not send push notifications.
- The "Global Do Not Disturb Period" is a user-level setting and has the highest priority. When a user sets a "Global Do Not Disturb Period," the Do Not Disturb level will be determined based on this setting.
(Recommended) When the App implements local notification handling, if it detects that the client App has moved to the background, it can use the global Do Not Disturb interface provided by the SDK to decide whether to display local notifications, achieving the effect of global Do Not Disturb.
Supported Do Not Disturb Levels
When setting a Do Not Disturb period for the current user, the following Do Not Disturb levels can be used:
Enum Value | Value | Description |
---|---|---|
none | 0 | Not set. If not set, the SDK will check the user-level Do Not Disturb settings of the message's group and other non-user-level settings to determine whether to send a push notification. |
mentionMessage | 1 | Only notify for @ messages, including @specific user and @all messages. |
blocked | 2 | Do not receive notifications, even for @ messages. |
Setting Do Not Disturb Time
Set the Do Not Disturb time for message notifications. When a message is received during the Do Not Disturb period, the push notification will be determined based on the Do Not Disturb level set by this interface.
Method
Future<int> changeNotificationQuietHours(String startTime, int spanMinutes, RCIMIWPushNotificationQuietHoursLevel level, {IRCIMIWChangeNotificationQuietHoursCallback? callback});
Parameter Description
Parameter Name | Parameter Type | Description |
---|---|---|
startTime | String | Start time for Do Not Disturb, formatted as HH:MM:SS |
spanMinutes | int | Duration of Do Not Disturb in minutes, 0 < spanMinutes < 1440 (e.g., if the start time is 00:00 and the end time is 01:00, spanMinutes is 60 minutes. Setting it to 1439 represents all-day Do Not Disturb (23 * 60 + 59 = 1439)) |
level | RCIMIWPushNotificationQuietHoursLevel | Notification level |
callback | IRCIMIWChangeNotificationQuietHoursCallback | Event callback. The SDK supports callback from version 5.3.1. Other callback methods are deprecated starting from version 5.4.0. If the callback parameter is provided, only the callback will be triggered. |
Return Value
Return Value | Description |
---|---|
Future<int> | Status code of the current operation. 0 indicates success. Specific results need to be implemented in the interface callback. Non-zero indicates failure, and detailed errors can be found in the error codes. |
Code Example
IRCIMIWChangeNotificationQuietHoursCallback? callback = IRCIMIWChangeNotificationQuietHoursCallback(onNotificationQuietHoursChanged: (int? code) {
//...
});
int? ret = await engine?.changeNotificationQuietHours(startTime, spanMinutes, level, callback:callback);
Callback Method
- onConversationNotificationLevelChanged
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, RCIMIWPushNotificationLevel? level)? onConversationNotificationLevelChanged;
Parameter Description
Parameter Name | Parameter Type | Description |
---|---|---|
code | int | Status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
type | RCIMIWConversationType | Conversation type |
targetId | String | Conversation ID |
channelId | String | Channel ID, only supported for ultra groups. For other conversation types, pass null. |
level | RCIMIWPushNotificationLevel | Notification level |
Code Example
engine?.onConversationNotificationLevelChanged = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, RCIMIWPushNotificationLevel? level) {
//...
};
Removing Do Not Disturb Time
You can call the following method, setting level to none
to remove the Do Not Disturb period.
Method
Future<int> removeNotificationQuietHours({IRCIMIWRemoveNotificationQuietHoursCallback? callback});
Return Value
Return Value | Description |
---|---|
Future<int> | Status code of the current operation. 0 indicates success. Specific results need to be implemented in the interface callback. Non-zero indicates failure, and detailed errors can be found in the error codes. |
Code Example
IRCIMIWRemoveNotificationQuietHoursCallback? callback = IRCIMIWRemoveNotificationQuietHoursCallback(onNotificationQuietHoursRemoved: (int? code) {
//...
});
int? ret = await engine?.removeNotificationQuietHours(callback:callback);
Callback Method
- onNotificationQuietHoursRemoved
Function(int? code)? onNotificationQuietHoursRemoved;
Parameter Description
Parameter Name | Parameter Type | Description |
---|---|---|
code | int | Status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
Code Example
engine?.onNotificationQuietHoursRemoved = (int? code) {
//...
};
Getting Do Not Disturb Time
You can use the following method to get the Do Not Disturb period setting. When a message is received during the Do Not Disturb period, the push notification will be determined based on the current Do Not Disturb level.
Method
Future<int> getNotificationQuietHours({IRCIMIWGetNotificationQuietHoursCallback? callback});
Return Value
Return Value | Description |
---|---|
Future<int> | Status code of the current operation. 0 indicates success. Specific results need to be implemented in the interface callback. Non-zero indicates failure, and detailed errors can be found in the error codes. |
Code Example
IRCIMIWGetNotificationQuietHoursCallback? callback = IRCIMIWGetNotificationQuietHoursCallback(onSuccess: (String? startTime, int? spanMinutes, RCIMIWPushNotificationQuietHoursLevel? level) {
//...
}, onError: (int? code) {
//...
});
int? ret = await engine?.getNotificationQuietHours(callback:callback);
Callback Method
- onNotificationQuietHoursLoaded
Function(int? code, String? startTime, int? spanMinutes, RCIMIWPushNotificationQuietHoursLevel? level)? onNotificationQuietHoursLoaded;
Parameter Description
Parameter Name | Parameter Type | Description |
---|---|---|
code | int | Status code of the interface callback. 0 indicates success, non-zero indicates an exception. |
startTime | String | Start time for Do Not Disturb |
spanMinutes | int | Duration of Do Not Disturb in minutes, 0 < spanMinutes < 1440 |
level | RCIMIWPushNotificationQuietHoursLevel | Notification level |
Code Example
engine?.onNotificationQuietHoursLoaded = (int? code, String? startTime, int? spanMinutes, RCIMIWPushNotificationQuietHoursLevel? level) {
//...
};