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
- Blueprint
- C++ / Input parameters
1Chat->GetChannels(
2 FString Filter = "",
3 FString Sort = "",
4 int Limit = 0,
5 FPubnubPage Page = FPubnubPage()
6);
| Parameter | Description |
|---|---|
FilterType: FStringDefault: 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: FStringDefault: n/a | Key-value pair of a property to sort by, and a sort direction. Available options are id, name, and updated. Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"}. By default, the items are sorted by the last updated date. |
LimitType: intDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
PageType: FPubnubPageDefault: n/a | Object used for pagination to define which previous or next result page you want to fetch. |
→ NextType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FStringDefault: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
Output
| Parameter | Description |
|---|---|
FPubnubChannelsResponseWrapperType: struct | Returned object containing three fields: Channels, Page, and Total. |
→ ChannelsType: TArray<UPubnubChannel*> | Array of all matching Channel objects. |
→ PageType: FPubnubPage | Struct that lets you either fetch the next (next) or previous (prev) result page. |
→ NextType: FString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. |
→ PrevType: FString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the Next parameter is supplied. |
→ TotalType: int | Total number of Channel objects matching the request query. |
Sample code
Fetch all existing channel IDs.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9FPubnubChannelsResponseWrapper Channels = Chat->GetChannels("", "", 100);
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.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Fetch first 25 channels (result page 1)
10FPubnubChannelsResponseWrapper Channels = Chat->GetChannels("", "", 25);
11
12// Handle the channels retrieved from first request
13for (auto& Channel : Channels.Channels) {
14 FString ChannelID = Channel->GetChannelID();
15 // Process the ChannelID
show all 28 linesArchived 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.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
7
8// Fetch all archived channels
9FPubnubChannelsResponseWrapper Channels = Chat->GetChannels("status=='deleted'", "", 100);
10
11for (auto& Channel : Channels.Channels) {
12 FString ChannelID = Channel->GetChannelID();
13 // Process the ChannelID
14}
15
show all 23 lines