/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Search group channels by name, URL, or other filters

Copy link

You can search for specific private or public group channels by using several types of search filters within the GroupChannelListQuery and PublicGroupChannelListQuery classes.


Search private group channels

Copy link

A GroupChannelListQuery instance provides many types of search filters such as channelNameContainsFilter and channelURLsFilter. You can use these filters to search for specific private group channels.

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

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    // ...

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            params.includeEmptyChannel = true
            params.setSearchFilter("Sendbird", fields: .channelName)
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the channels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of group channels that partially match "Sendbird"
            // in their names is returned.
        }
    }
}

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

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    // ...

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            params.includeEmptyChannel = true
            params.channelURLsFilter = [
                "seminar",
                "lecture"
            ]
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the channels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of group channels that partially match "seminar"
            // or "lecture" in their names is returned.
        }
    }
}

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

List of filters

Copy link
NameFilters

customTypesFilter

Group channels with one or more specified custom types.

customTypeStartsWithFilter

Group channels with a custom type that starts with the specified value.

channelNameContainsFilter

Group channels that contain the specified value in their names.

channelURLsFilter

Group channels with one or more specified channel URLs.

superChannelFilter

Either super or nonsuper group channels.

publicChannelFilter

Either public or private group channels.

unreadChannelFilter

Group channels with one or more unread messages.

channelHiddenStateFilter

Group channels with the specified hidden state and operating behavior.

myMemberStateFilter

Group channels based on whether the user has accepted an invitation.

userIdsExactFilter

Group channels that contain members with one or more specified user IDs.

userIdsIncludeFilter

Group channels that include one or more members with the specified user IDs.

nicknameContainsFilter

Group channels with members whose nicknames contain the specified value.

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.


Search public group channels

Copy link

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

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

class CustomViewController: ViewController {
    var query: PublicGroupChannelListQuery?

    // ...

    func createQuery() {
        self.query = GroupChannel.createPublicGroupChannelListQuery { params in
            params.includeEmptyChannel = true
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the channels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of group channels that partially match "Sendbird"
            // in their names is returned.
        }
    }
}

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

class CustomViewController: ViewController {
    var query: PublicGroupChannelListQuery?

    // ...

    func createQuery() {
        self.query = GroupChannel.createPublicGroupChannelListQuery { params in
            params.includeEmptyChannel = true
                params.channelURLsFilter = [
                    "seminar",
                    "lecture"
                ]
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the channels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of group channels that partially match "seminar"
            // or "lecture" in their names is returned.
        }
    }
}

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

List of filters

Copy link
NameFilters

customTypesFilter

Group channels with one or more specified custom types.

customTypeStartsWithFilter

Group channels with a custom type that starts with the specified value.

channelNameContainsFilter

Group channels that contain the specified value in their names.

channelURLsFilter

Group channels with the specified channel URLs.

superChannelFilter

Either super or nonsuper group channels.

publicMembershipFilter

Specifies public group channels to retrieve based on membership. Acceptable values are all and joined. If set to joined, retrieves only channels where the current user is a member. If set to all, retrieves all public group channels including those the current user hasn't 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.


Retrieve a list of Supergroup channels using a filter

Copy link

You can retrieve a list of Supergroup channels through the GroupChannelListQuery instance that is created by the createMyGroupChannelListQuery(paramsBuilder:) method of the GroupChannel class. A Supergroup channel is determined by the isSuper property. If the property has a value of true, the channel is a Supergroup channel.

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            // The `params` object is the `GroupChannelListQueryParams` class.
            params.superChannelFilter = .super
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { groupChannels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // A list of matching group channels is successfully retrieved.
            // Through the groupChannels parameter of the callback method,
            // you can access the data of each group channel from the result list that
            // the Sendbird server has passed to the callback method.
        }
    }
}