List all channels
Get a paginated list of all channels with getChannels(). Custom channel metadata is included by default.
Requires App Context
Enable App Context for your keyset in the Admin Portal.
With Access Manager enabled, uncheck Disallow Get All Channel Metadata in the App Context configuration to retrieve all channel metadata without defining permissions in the authentication token.
To list channels a user belongs to, use getMemberships() instead.
Method signature
This method takes the following parameters:
1chat.getChannels(
2 filter: String?,
3 sort: Collection<PNSortKey<PNKey>> = listOf(),
4 limit: Int?,
5 page: PNPage?
6): PNFuture<GetChannelsResponse>
Input
| Parameter | Description |
|---|---|
filterType: StringDefault: n/a | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: Collection<PNSortKey<PNKey>>Default: listOf() | A collection to specify the sort order. Available options are id, name, and updated. Use asc or desc to specify the sorting direction. For example: listOf(PNSortKey.asc(PNKey.NAME)). Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list. |
limitType: IntDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
pageType: PNPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
Output
| Type | Description |
|---|---|
PNFuture<GetChannelsResponse> | PNFuture containing a set of channels with pagination information (next, prev, total). |
Sample code
Fetch all existing channel IDs.
1chat.getChannels().async { result ->
2 result.onSuccess {
3 // handle success
4 }.onFailure {
5 // handle failure
6 }
7}
Other examples
Pagination
Get the number of 25 channels and then specify that you want to fetch the results from the next page using a string previously returned from the PubNub server.
1chat.getChannels(limit = 25).async { result ->
2 result.onSuccess { channelsObject: GetChannelsResponse ->
3 chat.getChannels(limit = 25, page = channelsObject.next)
4 .async { result2 ->
5 result2.onSuccess { channelsObjectPage2 -> ... }
6 .onFailure { ... }
7 }
8 }.onFailure { ... }
9}
Archived channels
Get all archived channels. This request will return all channels removed with the soft option set to true, whose data is still stored in the App Context storage.
1chat.getChannels(filter = "status=='deleted'").async { result ->
2 result.onSuccess {
3 // handle success
4 }.onFailure {
5 // handle failure
6 }
7}