Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
Channel

Search group channels by name, URL, or other filters

You can search for specific group channels by adding keywords to a GroupChannelListQuery instance. There are three types of keywords that can be used: name, URL, and custom type.


Search private group channels

A GroupChannelListQuery instance provides many types of search filters such as ChannelNameContains and ChannelUrls filters.

The code sample below shows the query instance which returns a list of group channels that partially match the specified channelNameContains keyword in their channel names.

final listQuery = GroupChannelListQuery()
    ..channelNameContains = 'Sendbird';

try {
    final channels = await listQuery.loadNext();
    // A list of group channel names that partially match 'Sendbird' is returned.
} catch (e) {
    // Handle error.
}

The following shows the query instance which returns a list of group channels that partially match the specified channelUrls keyword in their channel URLs.

final listQuery = GroupChannelListQuery()
    ..channelUrls = 'seminar';

try {
    final channels = await listQuery.loadNext();
    // A list of group channel URLs that partially match 'seminar' is returned.
} catch (e) {
    // Handle error.
}

You can also search for group channels with a specific custom type by setting customTypes as in the following code.

final listQuery = GroupChannelListQuery()
    ..customTypes = 'movie';

try {
    final channels = await listQuery.loadNext();
    // A list of group channels with the custom type movie is returned.
} catch (e) {
    // Handle error.
}

The following table shows all filters supported in GroupChannelListQuery to search for specific channels you want to retrieve. You can use any of the filters in a similar fashion with the sample code above.

List of filters

NameFilters

customTypes

Group channels with one or more specified custom types. You can enable this filter using the customTypes property.

customTypeStartWith

Group channels with a custom type that starts with the specified value. You can enable this filter using the customTypeStartWith property.

channelNameContains

Group channels that contain the specified value in their names. You can enable this filter using the channelNameContains property.

channelUrls

Group channels with one or more specified channel URLs. You can enable this filter using the channelUrls property.

superChannelFilter

Either super or nonsuper group channels. Using the superChannelFilter property, you can enable this filter.

publicChannelFilter

Either public or private group channels. Using the publicChannelFilter property, you can enable this filter.

unreadChannelFilter

Group channels with one or more unread messages. Using the unreadChannelFilter property, you can enable this filter.

channelHiddenStateFilter

Group channels with the specified state and operating behavior. You can enable this filter using the channelHiddenStateFilter property.

memberStateFilter

Group channels based on whether the user has accepted an invitation. You can enable this filter using the memberStateFilter property.

userIdsExactlyIn

Group channels that contain members with one or more specified user IDs. You can enable this filter using the userIdsExactlyIn property.

userIdsIncludeIn

Group channels that include one or more members with the specified user IDs. You can enable this filter using the userIdsIncludeIn property.

nicknameContains

Group channels with members whose nicknames contain the specified value. You can enable this filter using the nicknameContains property.

metaDataOrderKey

Group channels with metadata containing an item with the specified value as its key. This filter is effective only when the metadata are sorted in alphabetical order. You can enable this filter using the metaDataOrderKey property.


Search public group channels

A PublicGroupChannelListQuery instance provides many types of search filters such as channelNameContainsFilter and channelUrls. You can use these filters to search for specific public group channels.

The sample code below shows the query instance, which returns the current user's public group channels that partially match the specified keyword in channelNameContainsFilter in their channel names.

  final query = PublicGroupChannelListQuery();
  query.channelNameContainsFilter = "Sendbird";
  query.includeEmptyChannel = true;
  final result = await query.loadNext();
}

The following shows the query instance, which returns a list of the current user's group channels that partially match the specified keyword in channelUrls in their channel URLs.

class PublicGroupChannelListQuery extends QueryBase {
/// Filters for channel urls.
///
/// Result will return a list containing only and exactly matched
/// with given urls. This filter does not cooperate with other filters.
List? channelUrls;

The following table shows all filters supported in PublicGroupChannelListQuery to search for specific channels you want to retrieve. You can use any of the filters in a similar fashion with the sample code above.

List of filters

NameFilters

customTypesFilter

Group channels with one or more specified custom types. You can enable this filter using the customTypesFilter property.

customTypeStartWithFilter

Group channels with a custom type that starts with the specified value. You can enable this filter using the customTypeStartWithFilter property.

channelNameContainsFilter

Group channels that contain the specified value in their names. You can enable this filter using the channelNameContainsFilter property.

channelUrls

Group channels with one or more specified channel URLs. You can enable this filter using the channelUrls property.

superChannelFilter

Either super or nonsuper group channels. Using the superChannelFilter property, you can enable this filter.

membershipFilter

Specifies public group channels to retrieve based on membership. Acceptable values are ALL and JOINED. If set to ALL, retrieves both channels where the current user is and isn't a member. If set to JOINED, retrieves only channels where the current user is a member. (Default: JOINED)

metaDataOrderKeyFilter

Group channels with metadata containing an item with the specified value as its key. This filter is effective only when the metadata are sorted in alphabetical order. You can enable this filter using the metaDataOrderKeyFilter property.


Retrieve a list of Supergroup channels using a filter

You can retrieve a list of Supergroup channels through the GroupChannelListQuery's superChannelFilter property. A Supergroup channel is determined by the groupChannel.isSuper property. If the property has a value of true, the channel is a Supergroup channel.

try {
    final listQuery = GroupChannelListQuery();
    listQuery.superChannelFilter = SuperChannelFilter.superChannel;
    final groupChannels = await listQuery.loadNext();
    // A list of matching group channels is successfully retrieved.
    // Access the data of each group channel from the result list that the Sendbird server has passed to the callback method.
} catch (e) {
    // Handle error.
}