/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Retrieve a list of channels

Copy link

You can retrieve a list of OpenChannel instances using the next() method of an OpenChannelListQuery instance.

On the other hand, a list of GroupChannel instances can be retrieved through GroupChannelCollection and its loadMore() method. First, create a GroupChannelCollectionParams object. Then pass it to createGroupChannelCollection() as an argument. To retrieve a list of certain group channels such as public group channels or Supergroup channels, use the params as described at the bottom of this page.

Note: You can also search for specific open channels and group channels with keywords and filters.


Open channels

Copy link

Create an OpenChannelListQuery instance to retrieve a list of open channels. If you wish to filter open channels, set OpenChannelListQueryParams. After a list of open channels is successfully retrieved, you can access the data of each open channel from the result list through the channels parameter of the callback handler.

JavaScriptTypeScript
const params = {
  // ...
};
const query = sb.openChannel.createOpenChannelListQuery(params);

if (query.hasNext) {
    const channels = await query.next();
}

Group channels

Copy link

A group channel list view can be drawn with a GroupChannelCollection instance. In order to filter and sort group channels when creating a group channel collection, set GroupChannelCollectionParams, which can be passed into createGroupChannelCollection(). Or you can create a GroupChannelFilter instance before setting the params.

To retrieve group channels in the collection, call hasMore first to check whether there are more channels to load for the collection. If so, call loadMore().

To learn more about how the collection works, see Group channel collection under Local caching.

JavaScriptTypeScript
// Call hasMore to see if there are more channels to load.
if (groupChannelCollection.hasMore) {
    const channels = await groupChannelCollection.loadMore();
}

Filter group channels using GroupChannelFilter

Copy link

When creating a GroupChannelCollection instance, you can create a GroupChannelFilter instance to filter and sort group channels in the collection. Once they are set, you can either pass the instance to filter in GroupChannelCollectionParams, or use it directly in createGroupChannelCollection(). The filter works much like other search options, retrieving a list of group channels matching the specifications. For example, use myMemberStateFilter when searching for only the group channels that the current user belongs to, and publicChannelFilter regardless of the current user's membership state. To retrieve a list of Supergroup channels only, you can set the superChannelFilter property to SuperChannelFilter.SUPER.

JavaScriptTypeScript
const groupChannelFilter = new GroupChannelFilter();
groupChannelFilter.includeEmpty = true; // Optional.
groupChannelFilter.publicChannelFilter  = PublicChannelFilter.PUBLIC; // Retrieve public group channels. Optional.
groupChannelFilter.superChannelFilter = SuperChannelFilter.SUPER; // Retrieve Supergroup channels. Optional.
// Set other attributes if needed.

const groupChannelCollection = sb.groupChannel.createGroupChannelCollection({
  filter: groupChannelFilter,
  order: GroupChannelListOrder.LATEST_LAST_MESSAGE,
  // ...
});

GroupChannelFilter

Copy link

This table only shows the properties of the class. To see the comprehensive list of all available methods and properties, see GroupChannelFilter in API reference.

Property nameTypeDescription

includeEmpty

boolean

Determines whether the list includes empty group channels that don't show any messages sent before the current user joins it because the chat history option is turned off. You can turn on or off the chat history option under Settings > Chat > Channels > Group channels on Sendbird Dashboard.

superChannelFilter

SuperChannelFilter

Determines which group channels to include in the list based on their isSuper value. Acceptable values are NON_SUPER, SUPER, and ALL. (Default: ALL)

publicChannelFilter

PublicChannelFilter

Determines which group channels to include in the list based on their isPublic value. Acceptable values are PRIVATE, PUBLIC, and ALL. (Default: ALL)