Muting Channels

Last Edit: Sep 22 2020

Messages added to a channel will not trigger push notifications, 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.

Channel Mute


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();
                    

client.muteChannel(channelType, channelId)
    .enqueue { result: Result<Unit> ->
        if (result.isSuccess) {
            //channel is muted
        } else {
            result.error().printStackTrace()
        }
    }

// get list of muted channels when user is connected
client.setUser(user, token, object : InitConnectionListener() {
    override fun onSuccess(data: ConnectionData) {
        val user = data.user
        // mutes contains the list of channel mutes
        val mutes: List<ChannelMute> = user.channelMutes
    }
})

// get updates about muted channels
client
    .events()
    .subscribe { event: ChatEvent? ->
        if (event is NotificationChannelMutesUpdated) {
            val mutes = event.me.channelMutes
        } else if (event is NotificationMutesUpdated) {
            val mutes = event.me.channelMutes
        }
    }
                    

client.muteChannel(channelType, channelId).enqueue(result -> {
    if (result.isSuccess()) {
        //channel is muted
    } else {
        result.error().printStackTrace();
    }
    return Unit.INSTANCE;
});

// get list of muted channels when user is connected
client.setUser(user, token, new InitConnectionListener() {
    @Override
    public void onSuccess(@NotNull ConnectionData data) {
        User user = data.component1();
        // mutes contains the list of channel mutes
        List<ChannelMute> mutes = user.getChannelMutes();
    }
});

// get updates about muted channels
client
        .events()
        .subscribe(event -> {

            if (event instanceof NotificationChannelMutesUpdated) {
                List<ChannelMute> mutes = ((NotificationChannelMutesUpdated) event).me.getChannelMutes();
            } else if (event instanceof NotificationMutesUpdated) {
                List<ChannelMute> mutes = ((NotificationChannelMutesUpdated) event).me.getChannelMutes();
            }

            return Unit.INSTANCE;
        });
                    
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.


// retrieve all channels excluding muted ones
await client.queryChannels({ members: { $in: [userId] }, muted: false });

// retrieve all muted channels
await client.queryChannels({ muted: true });
                    

// retrieve channels excluding muted ones

val offset = 0
val limit = 10
val notMutedFilter = Filters.eq("muted", false)
client.queryChannels(QueryChannelsRequest(notMutedFilter, offset, limit))

// retrieve muted channels

val mutedFilter = Filters.eq("muted", true)
client.queryChannels(QueryChannelsRequest(mutedFilter, offset, limit))
                    

Client.shared.queryChannels(filter: .equal("muted", to: true)) { (result) in
    // handle result
}

Client.shared.queryChannels(filter: .equal("muted", to: false)) { (result) in
    // handle result
}
                    

// retrieve channels excluding muted ones
int offset = 0;
int limit = 10;
int messageLimit = 0;
QuerySort sort = new QuerySort();

FilterObject mutedFiler = eq("muted", false);

client.queryChannels(
        new QueryChannelsRequest(mutedFiler, offset, limit, sort, messageLimit)
).enqueue(result -> {
    if (result.isSuccess()) {
        List<Channel> channels = result.data();
    } else {
        result.error().printStackTrace();
    }
    return Unit.INSTANCE;
});

// retrieve muted channels

FilterObject unmutedFilter = eq("muted", true);

client.queryChannels(
        new QueryChannelsRequest(unmutedFilter, offset, limit, sort, messageLimit)
).enqueue(result -> {
    if (result.isSuccess()) {
        List<Channel> channels = result.data();
    } else {
        result.error().printStackTrace();
    }
    return Unit.INSTANCE;
});
                    

Remove a Channel Mute


// 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
channelController.unmute().enqueue { result ->
    if (result.isSuccess) {
        // channel is unmuted
    } else {
        result.error().printStackTrace()
    }
}
                    

// unmute channel for current user
channelController.unmute().enqueue(result -> {
    if (result.isSuccess()) {
        // channel is unmuted
    } else {
        result.error().printStackTrace();
    }
    return Unit.INSTANCE;
});