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
import StreamChat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
// Controllers
// mute channel
controller.muteChannel { error in
if let error = error {
// handle error
print(error)
}
}
// mute channel for 2 weeks (expiration in milliseconds)
controller.muteChannel(expiration: 14 * 24 * 60 * 60 * 1000) { error in
if let error = error {
// handle error
print(error)
}
}
// State layer (async-await)
// mute channel
try await chat.mute()
// mute channel for 2 weeks (expiration in milliseconds)
try await chat.mute(expiration: 14 * 24 * 60 * 60 * 1000)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.
// Controllers
let controller = chatClient.channelListController(
query: .init(
filter: .equal(.muted, to: true)
)
)
controller.synchronize { error in
print(error ?? controller.channels)
}
// State layer (async-await)
let channelList = chatClient.makeChannelList(
with: ChannelListQuery(
filter: .equal(.muted, to: true)
)
)
try await channelList.get()
let mutedChannels = channelList.state.channelsRemove a Channel Mute
Use the unmute method to restore normal notifications and unread behavior for a channel.
import StreamChat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
// Controllers
// unmute channel
controller.unmuteChannel { error in
if let error = error {
// handle error
print(error)
}
}
// State layer (async-await)
// unmute channel
try await chat.unmute()