Muting Channels
Muting a channel prevents it from triggering push notifications, unhiding, or incrementing the unread count for that user.
By default, mutes remain active indefinitely until removed. You can optionally set an expiration time. The list of muted channels and their expiration times is returned when the user connects.
Mute a Channel
// Channel mutes are per-user, so a server-side call always names the user.
// `channel_cids` accepts several channels in one call.
await client.chat.muteChannel({
channel_cids: ["messaging:general"],
user_id: "john",
});
// mute a channel for 2 weeks (expiration in milliseconds)
await client.chat.muteChannel({
channel_cids: ["messaging:general"],
user_id: "john",
expiration: 14 * 24 * 60 * 60 * 1000,
});
// mute a channel for 10 seconds
await client.chat.muteChannel({
channel_cids: ["messaging:general"],
user_id: "john",
expiration: 10000,
});const channel = serverClient.channel("messaging", "channel-id");
// mute channel for a user
await channel.mute({ user_id: userId });
// mute a channel for 2 weeks
await channel.mute({ user_id: userId, expiration: 14 * 24 * 60 * 60 * 1000 });
// mute a channel for 10 seconds
const response = await channel.mute({ user_id: userId, expiration: 10000 });Info:
Messages added to muted channels do not increase the unread messages count.
Query Muted Channels
Muted channels can be filtered or excluded by using the muted in your query channels filter.
// Mutes are per-user, so pass `user_id` to evaluate the `muted` filter.
// retrieve all channels excluding muted ones
await client.chat.queryChannels({
filter_conditions: { members: { $in: [userId] }, muted: false },
user_id: userId,
});
// retrieve all muted channels
await client.chat.queryChannels({
filter_conditions: { muted: true },
user_id: userId,
});// retrieve all channels excluding muted ones
const notMuted = await serverClient.queryChannels(
{ members: { $in: [userId] }, muted: false },
{},
{ user_id: userId },
);
// retrieve all muted channels
const muted = await serverClient.queryChannels(
{ muted: true },
{},
{ user_id: userId },
);Remove a Channel Mute
Use the unmute method to restore normal notifications and unread behavior for a channel.
await client.chat.unmuteChannel({
channel_cids: ["messaging:general"],
user_id: "john",
});// unmute channel for a user
await channel.unmute({ user_id: userId });