Set channel DND
Set do-not-disturb (DND) for a specific channel. When DND is enabled, the user does not receive push notifications for new messages in that channel.
Set DND for a channel
TypeScript
import { DirectChannel, ChannelNoDisturbLevel } from '@nexconn/chat';
const channel = new DirectChannel('<target-user-id>');
const { code } = await channel.setNoDisturbLevel(ChannelNoDisturbLevel.MUTED);
if (code === 0) {
console.log('DND set successfully');
}
DND levels
| Enum value | Numeric value | Description |
|---|---|---|
ChannelNoDisturbLevel.ALL_MESSAGE | -1 | Receive notifications for all messages |
ChannelNoDisturbLevel.DEFAULT | 0 | Follow the global or app-level DND configuration |
ChannelNoDisturbLevel.MENTION | 1 | Only notify for @mention messages (all mention types) |
ChannelNoDisturbLevel.MENTION_USERS | 2 | Only notify when specific users are @mentioned |
ChannelNoDisturbLevel.MENTION_ALL | 4 | Only notify when @all is used |
ChannelNoDisturbLevel.MUTED | 5 | Mute all notifications |
Get the DND setting for a channel
The current DND level is available as the noDisturbLevel property on the channel object (populated after the channel list is fetched):
TypeScript
import { DirectChannel, BaseChannel } from '@nexconn/chat';
const query = BaseChannel.createChannelsQuery({ pageSize: 20 });
const { data: channels } = await query.loadNextPage();
const channel = channels?.find(ch => ch.channelId === '<target-user-id>') as DirectChannel | undefined;
if (channel) {
console.log('Current DND level:', channel.noDisturbLevel);
}
Remove DND for a channel
Reset to the default level:
TypeScript
import { DirectChannel, ChannelNoDisturbLevel } from '@nexconn/chat';
const channel = new DirectChannel('<target-user-id>');
const { code } = await channel.setNoDisturbLevel(ChannelNoDisturbLevel.DEFAULT);
if (code === 0) {
console.log('DND removed');
}
tip
- DND settings are synced across devices when multi-device sync is enabled.
- For community channels, you can also set DND at the subchannel level. See [Set community subchannel DND](../community channel/do-not-disturb.md).