// Mute a channel
val channelClient = client.channel("messaging", "general")
channelClient.mute().enqueue { result ->
if (result.isSuccess) {
// Channel is muted
} else {
// Handle result.error()
}
}
// Get list of muted channels when user is connected
client.connectUser(User("user-id"), "token")
.enqueue { result ->
if (result.isSuccess) {
val user = result.data().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.channelsMute
}
Muting or Hiding Channels
Muting Channels
Messages added to a channel will not trigger push notifications, unhide a channel, nor change the unread count for the users that muted it. By default, mutes stay in place indefinitely until the user removes it; however, you can optionally set an expiration time. The list of muted channels and their expiration time is returned when the user connects.
const reply = await client.setUser(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();
import Stream Chat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
// mute channel
controller.muteChannel { error in
if let error = error {
// handle error
print(error)
}
}
// mute channel for current user
await channel.mute();
// mute a channel for 2 weeks
await channel.mute(expiration: Duration(days: 15));
// mute a channel for 10 seconds
await channel.mute(expiration: Duration(seconds: 10));
// check if channel is muted
channel.isMuted;
// mute channel for current user
Channel->Mute();
// mute a channel for 2 weeks
Channel->Mute({FTimespan::FromDays(15.)});
// mute a channel for 10 seconds
Channel->Mute({FTimespan::FromSeconds(10.)});
// check if channel is muted
Channel->IsMuted();
$channel->mute("john");
// With expiration
$channel->mute("john", expirationInMilliSeconds: 1000);
channel.mute("john")
# With expiration
channel.mute("john", expiration=30000)
channel.mute("john")
# With expiration
channel.mute("john", 1000)
await channelClient.MuteChannelAsync(new ChannelMuteRequest
{
ChannelCids = new[] { "<channel-cid-here>" },
UserId = "john",
});
// With expiration
await channelClient.MuteChannelAsync(new ChannelMuteRequest
{
ChannelCids = new[] { "<channel-cid-here>" },
UserId = "john",
Expiration = 1000,
});
channel.Mute(ctx, "john", nil)
// With expiration
exp := 6 * time.Hour
channel.Mute(ctx, "john", &exp)
// Android SDK
// Mute a channel
ChannelClient channelClient = client.channel("messaging", "general");
channelClient.mute().enqueue(result -> {
if (result.isSuccess()) {
// Channel is muted
} else {
// Handle result.error()
}
});
// Get list of muted channels when user is connected
User user = new User();
user.setId("user-id");
client.connectUser(user, "token").enqueue(result -> {
if (result.isSuccess()) {
// Result contains the list of channel mutes
List<ChannelMute> mutes = result.data().getUser().getChannelMutes();
}
});
// Get updates about muted channels
client.subscribeFor(
new Class[]{NotificationChannelMutesUpdatedEvent.class},
channelsMuteEvent -> {
List<ChannelMute> mutes = ((NotificationChannelMutesUpdatedEvent) channelsMuteEvent).getMe().getChannelMutes();
}
);
// Backend SDK
Channel.mute()
.channelCid(channel.getType() + ":" + channel.getId())
.user(user)
.expiration(TimeUnit.MILLISECONDS.convert(14, TimeUnit.DAYS)) // Optionally set mute duration
.request();
await channel.MuteChannelAsync();
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.isSuccess) {
val channels: List<Channel> = result.data()
} else {
// Handle result.error()
}
}
// retrieve all channels excluding muted ones
await client.queryChannels({ members: { $in: [userId] }, muted: false });
// retrieve all muted channels
await client.queryChannels({ muted: true });
let controller = chatClient.channelListController(
query: .init(
filter: .equal(.muted, to: true)
)
)
controller.synchronize { error in
print(error ?? controller.channels)
}
// retrieve all channels excluding muted ones
await client.queryChannels(
filter: {
'members': {
r'$in': [userId],
},
'muted': false,
}
);
// retrieve all muted channels
await client.queryChannels(
filter: {
'muted': true,
}
);
// retrieve all channels excluding muted ones
const FFilter NotMuted = FFilter::And({
FFilter::In(TEXT("members"), {UserId}),
FFilter::Equal(TEXT("muted"), false),
});
Client->QueryChannels(NotMuted);
// retrieve all muted channels
const FFilter Muted = FFilter::Equal(TEXT("muted"), true);
Client->QueryChannels(Muted);
$client->queryChannels(['muted' => true]);
client.query_channels({"muted": True})
client.query_channels({ 'muted' => true })
await channelClient.QueryChannelsAsync(QueryChannelsOptions.Default.WithFilter(new Dictionary<string, object>
{
{ "muted", true },
}));
client.QueryChannels(ctx, &QueryOption{
Filter: map[string]interface{}{
"muted": true,
},
})
// Android SDK
// Filter for all channels excluding muted ones
FilterObject notMutedFilter = Filters.and(
Filters.eq("muted", false),
Filters.in("members", Arrays.asList(currentUserId))
);
// Filter for muted channels
FilterObject mutedFilter = Filters.eq("muted", true);
// Executing a channels query with either of the filters
int offset = 0;
int limit = 10;
QuerySorter<Channel> sort = new QuerySortByField<>();
int messageLimit = 0;
int memberLimit = 0;
client.queryChannels(new QueryChannelsRequest(
filter, // Set the correct filter here
offset,
limit,
sort,
messageLimit,
memberLimit)).enqueue(result -> {
if (result.isSuccess()) {
List<Channel> channels = result.data();
} else {
// Handle result.error()
}
});
// Backend SDK
// retrieve all channels excluding muted ones
Channel.list()
.filterCondition("muted", false) // Or 'true' for selected muted channels
.filterCondition(FilterCondition.in("members", userId))
.request();
// Will be implemented soon, raise a GitHub issue if you need this feature https://github.com/GetStream/stream-chat-unity/issues/
Remove a Channel Mute
Whenever you need to unmute, you are able to.
// Unmute channel for current user
channelClient.unmute().enqueue { result ->
if (result.isSuccess) {
// Channel is unmuted
} else {
// Handle result.error()
}
}
// unmute channel for current user
await channel.unmute();
// unmute channel for a user (server-side)
await channel.unmute({ user_id: userId });
import Stream Chat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
// unmute channel
controller.unmuteChannel { error in
if let error = error {
// handle error
print(error)
}
}
// unmute channel for current user
await channel.unmute();
// unmute channel for a user (server-side)
await channel.unmute({ user_id: userId });
// unmute channel for current user
Channel->Unmute();
$channel->unmute("john");
channel.unmute("john")
channel.unmute("john")
await channelClient.UnmuteChannelAsync(new ChannelUnmuteRequest
{
ChannelCids = new[] { "<channel-cid-here>" },
UserId = "john",
});
channel.Unmute(ctx, "john")
// Android SDK
// Unmute channel for current user
channelClient.unmute().enqueue(result -> {
if (result.isSuccess()) {
// Channel is unmuted
} else {
// Handle result.error()
}
});
// Backend SDK
Channel.unmute().channelCid(cid).userId(userId).request();
await channel.UnmuteChannelAsync();
Hiding a Channel
Hiding a channel will remove it from query channel requests for that user until a new message is added. Please keep in mind that hiding a channel is only available to members of that channel. Hidden channels may still have unread messages and you may wish to mark the channel as read prior to hiding it.
Optionally you can also clear the entire message history of that channel for the user. This way, when a new message is received, it will be the only one present in the channel.
// Hides the channel until a new message is added there
channelClient.hide().enqueue { result ->
if (result.isSuccess) {
// Channel is hidden
} else {
// Handle result.error()
}
}
// Shows a previously hidden channel
channelClient.show().enqueue { result ->
if (result.isSuccess) {
// Channel is shown
} else {
// Handle result.error()
}
}
// Hide the channel and clear the message history
channelClient.hide(clearHistory = true).enqueue { result ->
if (result.isSuccess) {
// Channel is hidden
} else {
// Handle result.error()
}
}
// hides the channel until a new message is added there
await channel.hide();
// hides the channel until a new message is added there. This also clears the history for the user
await channel.hide(null, true);
// shows a previously hidden channel
await channel.show();
// hides the channel until a new message is added there
$channel->hide('elon');
// shows a previously hidden channel
$channel->show('elon');
// hides the channel until a new message is added there
await channel.hide();
// shows a previously hidden channel
await channel.show();
// hide the channel and clear the message history
await channel.hide(clearHistory: true);
import Stream Chat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
// hide channel
controller.hideChannel { error in
if let error = error {
// handle error
print(error)
}
}
// show channel
controller.showChannel { error in
if let error = error {
// handle error
print(error)
}
}
// hide channel and clear message history
controller.hideChannel(clearHistory: true) { error in
if let error = error {
// handle error
print(error)
}
}
// Android SDK
// hides the channel until a new message is added there
Channel->Hide();
// shows a previously hidden channel
Channel->Show();
// hide the channel and clear the message history
Channel->Hide(true);
// Backend SDK
// hide channel
Channel.hide(type, id)
.clearHistory(true) // Optionally clear history
.userId(userId)
.request();
// shows a previously hidden channel
Channel.show(type, id).userId(userId).request();
// hides the channel until a new message is added there
$channel->hide("john");
// shows a previously hidden channel
$channel->show("john");
# hides the channel until a new message is added there
channel.hide("john");
# shows a previously hidden channel
channel.show("john");
# hides the channel until a new message is added there
channel.hide("john");
# shows a previously hidden channel
channel.show("john");
// hides the channel until a new message is added there
await channelClient.HideAsync("<channel-type>", "<channel-id>", "john");
// shows a previously hidden channel
await channelClient.ShowAsync("<channel-type>", "<channel-id>", "john");
// hides the channel until a new message is added there
channel.hide(ctx, "john");
// shows a previously hidden channel
channel.show(ctx, "john");
// Hides the channel until a new message is added there
channelClient.hide(false).enqueue(result -> {
if (result.isSuccess()) {
// Channel is hidden
} else {
// Handle result.error()
}
});
// Shows a previously hidden channel
channelClient.show().enqueue(result -> {
if (result.isSuccess()) {
// Channel is shown
} else {
// Handle result.error()
}
});
// Hide the channel and clear the message history
channelClient.hide(true).enqueue(result -> {
if (result.isSuccess()) {
// Channel is hidden
} else {
// Handle result.error()
}
});
// Hide a channel
await channel.HideAsync();
// Show previously hidden channel
await channel.ShowAsync();
You can still retrieve the list of hidden channels using the { "hidden" : true }
query parameter.