const reply = await client.connectUser(user, token);
// reply.me.channel_mutes contains the list of channel mutes
console.log(reply.me.channel_mutes);
const channel = client.channel("messaging", "channel-id");
// mute channel for current user
await channel.mute();
// mute channel for a user (server-side)
await channel.mute({ user_id: userId });
// mute a channel for 2 weeks
await channel.mute({ expiration: moment.duration(2, "weeks") });
// mute a channel for 10 seconds
await channel.mute({ expiration: 10000 });
// check if channel is muted
// { muted: true | false, createdAt: Date | null, expiresAt: Date | null}
channel.muteStatus();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
// Mute a channel
val channelClient = client.channel("messaging", "general")
channelClient.mute().enqueue { result ->
if (result is Result.Success) {
// Channel is muted
} else {
// Handle Result.Failure
}
}
// Get list of muted channels when user is connected
client.connectUser(User("user-id"), "token")
.enqueue { result ->
if (result is Result.Success) {
val user = result.value.user
// Result contains the list of channel mutes
val mutes: List<ChannelMute> = user.channelMutes
}
}
// Get updates about muted channels
client.subscribeFor<NotificationChannelMutesUpdatedEvent> { event ->
val mutes: List<ChannelMute> = event.me.channelMutes
}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.
// Filter for all channels excluding muted ones
val notMutedFilter = Filters.and(
Filters.eq("muted", false),
Filters.`in`("members", listOf(currentUserId)),
)
// Filter for muted channels
val mutedFilter = Filters.eq("muted", true)
// Executing a channels query with either of the filters
client.queryChannels(QueryChannelsRequest(
filter = filter, // Set the correct filter here
offset = 0,
limit = 10,
)).enqueue { result ->
if (result is Result.Success) {
val channels: List<Channel> = result.value
} else {
// Handle Result.Failure
}
}Remove a Channel Mute
Use the unmute method to restore normal notifications and unread behavior for a channel.
// Unmute channel for current user
channelClient.unmute().enqueue { result ->
if (result is Result.Success) {
// Channel is unmuted
} else {
// Handle Result.Failure
}
}