Skip to main content

Set do not disturb for channels

  • This document describes how to set do not disturb using Chat SDK.
  • For UI display and state synchronization, combine with Chat UI channel status notifications.

The instant messaging service supports do not disturb settings. Chat UI can set message notification states to "do not disturb" based on channel type and channel ID. When enabled, if the client runs in the background, new messages in the channel won't trigger notifications, though messages are still received. If the client is offline, remote notifications won't be received.

The channel's do not disturb state syncs with the server. The server automatically synchronizes do not disturb state data across devices. Clients can receive sync notifications through listeners or actively fetch the latest data.

Set do not disturb state for a channel

NCBaseChannel provides the setNoDisturbLevel:completion: method to set message notifications to "do not disturb" for a channel. When enabled, clients won't receive notifications for new messages in this channel, whether running in the background or offline. After modifying, you can actively refresh the data source to update the UI.

Objective C
NCBaseChannel *channel = self.currentChannel;
[channel setNoDisturbLevel:NCChannelNoDisturbLevelMuted
completion:^(NCError * _Nullable error) {}];
ParameterTypeDescription
levelNCChannelNoDisturbLevelThe do not disturb level for the channel, e.g. NCChannelNoDisturbLevelMuted.
completionBlockReturns NCError on failure.

Listen for do not disturb state synchronization

The instant messaging service supports channel status synchronization (pinned state and do not disturb state). After setting a channel status sync listener, you'll receive notifications when channel states change.

When channel pinning and do not disturb states synchronize, the SDK dispatches this notification:

Objective C
FOUNDATION_EXPORT NSString *const NCChatUIDispatchConversationStatusChangeNotification;

The notification object is an array of NCConversationStatusInfo objects and userInfo is nil. After receiving it, refresh the relevant channel status data, such as pinned state or do not disturb level.

Register a notification listener:

Objective C
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onConversationStatusChanged:)
name:NCChatUIDispatchConversationStatusChangeNotification
object:nil];

Update your channel states when receiving notifications:

Objective C
- (void)onConversationStatusChanged:(NSNotification *)notification {
// Refresh channel status data, such as noDisturbLevel, from your local channel model or query result.
NCChannelNoDisturbLevel level = self.currentChannel.noDisturbLevel;
}

Get do not disturb state for a channel

Clients can actively fetch the latest do not disturb state data.

Objective C
NCChannelNoDisturbLevel level = self.currentChannel.noDisturbLevel;
ParameterTypeDescription
levelNCChannelNoDisturbLevelThe current channel's do not disturb level.

Get default do not disturb level by channel type

To get the default do not disturb level configured for a specific channel type, call this class method on NCBaseChannel:

Objective C
NCChannelType channelType = NCChannelTypeDirect;
[NCBaseChannel getChannelTypeNoDisturbLevelWithChannelType:channelType
completion:^(NCChannelNoDisturbLevel level, NCError * _Nullable error) {}];
ParameterTypeDescription
channelTypeNCChannelTypeThe channel type.

After successful retrieval, combine with NCChannelsQuery to get the corresponding channel list and filter by noDisturbLevel.