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

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

Remove a Channel Mute

Whenever you need to unmute, you are able to.

// unmute channel for current user
await channel.unmute();

// unmute channel for a user (server-side)
await channel.unmute({ user_id: userId });

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

You can still retrieve the list of hidden channels using the { "hidden" : true } query parameter.

© Getstream.io, Inc. All Rights Reserved.