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.

Retrieve a list of channels

You can retrieve a list of OpenChannel objects using the next() method of an OpenChannelListQuery instance and a list of GroupChannel objects using the next() method of a GroupChannelListQuery instance as shown below.

Creating a GroupChannelListQuery instance from the createMyGroupChannelListQuery() returns a list of the user's private group channels. A different approach is needed to retrieve a list of public group channels and Supergroup channels as explained below.

Also for group channels, you can use the includeEmpty option of a GroupChannelListQuery instance to determine whether to include empty channels in the query result. Empty channels are group channels that have been created but don't contain any messages, and aren't included in the result by default. You can also turn off the Chat history option on Sendbird Dashboard to retrieve empty channels in the result.

Open channelGroup channel
const query: OpenChannelListQuery = sb.openChannel.createOpenChannelListQuery();

if (query.hasNext) {
    const channels: OpenChannel[] = await query.next();
}

Public group channels

You can get a list of a user's public group channels by passing a PublicGroupChannelListQueryParams instance to the createPublicGroupChannelListQuery() method. The method can also take list query parameters directly in it.

The hasNext() method checks if there are more public group channels to retrieve and the next() method will return them.

const params: PublicGroupChannelListQueryParams = {
    includeEmpty: true,
    membershipFilter: MembershipFilter.JOINED,
    order: PublicGroupChannelListOrder.CHRONOLOGICAL,
    limit: 15, // The value of the pagination limit could be set up to 100.
};
const query: PublicGroupChannelListQuery = sb.groupChannel.createPublicGroupChannelListQuery(params);

if (query.hasNext) {
    const channels: GroupChannel[] = await query.next();
}

Supergroup channels

Like how you search group channels using filters, you can retrieve a list of Supergroup channels through the GroupChannelListQuery's superChannelFilter property. You can tell a Supergroup channel by looking at the channel's isSuper property, which should be set to a value of true.

const params: GroupChannelListQueryParams = {
    superChannelFilter: SuperChannelFilter.SUPER,
};
const query: GroupChannelListQuery = sb.groupChannel.createMyGroupChannelListQuery(params);

const channels: GroupChannel[] = await query.next();