Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Channel
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Hide or archive a group channel

You can use the following code to hide or archive a specific group channel from the channel list UI.

// Hide or archive a group channel.
const params: GroupChannelHideParams = {
    hidePreviousMessages: false,
    allowAutoUnhide: true,
};
await channel.hide(params);

// Unhide a group channel.
await channel.unhide();

GroupChannelHideParams

ArgumentTypeDescription

hidePreviousMessages

boolean

Determines whether to show the messages sent and received before hiding or archiving the channel on the channel list. If set to true, previous messages aren't displayed in the channel. (Default: false)

allowAutoUnhide

boolean

Determines the state and operating behavior of a channel. If set to true, the channel is hidden from the channel list, but when a new message arrives, the hidden channel will show up again on the channel list. If set to false, the channel is archived and stays hidden from the channel list unless the unhide() method is called. (Default: true)

By using the channel.hiddenState property, you can check the channel state on the channel list.

if (channel.hiddenState === HiddenState.UNHIDDEN) {
    // Display the channel in the list.
} else if (channel.hiddenState === HiddenState.HIDDEN_ALLOW_AUTO_UNHIDE) {
    // Hide the channel from the list and show again depending on the set value.
} else if (channel.hiddenState === HiddenState.HIDDEN_PREVENT_AUTO_UNHIDE) {
    // Archive the channel and show again on the list only when the unhide() method is called.
}

You can also filter channels by their state like the following.

const params: GroupChannelListQueryParams = {
    includeEmpty: true,
    hiddenChannelFilter: HiddenChannelFilter.HIDDEN_PREVENT_AUTO_UNHIDE,
    // ...
};
const query: GroupChannelListQuery = sb.groupChannel.createMyGroupChannelListQuery(params);