You can retrieve a list of all or certain users in your Sendbird application using an ApplicationUserListQuery instance. The loadNextPage(completionHandler:) method returns a list of User objects which contain information on users within the application.
class CustomViewController: ViewController {
var query: ApplicationUserListQuery?
// ...
func createQuery() {
// Retrieving all users.
self.query = SendbirdChat.createApplicationUserListQuery()
}
func loadNextPage() {
self.query?.loadNextPage { users, error in
guard error == nil else {
// Handle error.
return
}
// A list of users is successfully retrieved.
// Through the users parameter of the callback method,
// you can access the data of each user from the result list that
// the Sendbird server has passed to the callback method.
}
}
}
The ApplicationUserListQueryParams object is passed to the createApplicationUserListQuery(:) method to make the ApplicationUserListQuery instance. Using a number of different parameters the ApplicationUserListQuery instance provides, you can retrieve a list of specific users that match the set values in the parameters. Currently, the ApplicationUserListQuery instance supports the following parameters.
Specifies the unique IDs of users you want to retrieve in the filter.
MetaDataKeyFilter
string
Specifies a metadata key to retrieve users with metadata containing an item with the specified key and values. The setMetaDataFilter(key:values:) option must be specified.
MetaDataValuesFilter
string
Specifies the metadata values to retrieve users with metadata containing an item with the specified key and values. The setMetaDataFilter(key:values:) option must be specified.
Note: We recommend you set the maximum number of user IDs to 250 in the UserID filter. If exceeded, your query may receive an HTTP 414 error indicating that the submitted request data is longer than the Sendbird server is willing to interpret.
class CustomViewController: ViewController {
var query: ApplicationUserListQuery?
// ...
func createQuery() {
// Retrieving certain users using the userIdsFilter.
self.query = SendbirdChat.createApplicationUserListQuery { params in
// The `params` is the `ApplicationUserListQueryParams` object.
params.userIdsFilter = ["Harry", "Jay", "Jin"]
}
}
func loadNextPage() {
self.query?.loadNextPage { users, error in
guard error == nil else {
// Handle error.
return
}
// A list of matching users is successfully retrieved.
}
}
}
class CustomViewController: ViewController {
var query: ApplicationUserListQuery?
// ...
func createQuery() {
// Retrieving certain users using the metaDataFilter.
self.query = SendbirdChat.createApplicationUserListQuery { params in
// The `params` is the `ApplicationUserListQueryParams` object.
params.setMetaDataFilter(key: "hobby", values: ["movie", "book", "exercise"])
}
}
func loadNextPage() {
self.query?.loadNextPage { users, error in
guard error == nil else {
// Handle error.
return
}
// A list of matching users is successfully retrieved.
}
}
}