List all channels

GetChannels() returns a paginated list of all existing channels.

By default, this method returns all custom channel metadata without the need to explicitly define that during the call.

icon

Usage in Blueprints and C++


Requires App Context

To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.

If you have Access Manager enabled in your app, uncheck the Disallow Get All Channel Metadata option in the App Context configuration in the Admin Portal – this way you can get metadata of all channels without the need to define that in the permissions schema included in the authentication token.

To get a list of all channels a user is a member of, use the GetMemberships() method.

Method signature

Output

ParameterTypeDescription
FPubnubChannelsResponseWrapperstructReturned object containing three fields: Channels, Page, and Total.
 → ChannelsTArray<UPubnubChannel*>Array of all matching Channel objects.
 → PageFPubnubPageStruct that lets you either fetch the next (next) or previous (prev) result page.
   → NextFStringRandom 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.
   → PrevFStringRandom 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.
 → TotalintTotal number of Channel objects matching the request query.

Basic usage

Fetch all existing channel IDs.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

FPubnubChannelsResponseWrapper 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.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

// Fetch first 25 channels (result page 1)
FPubnubChannelsResponseWrapper Channels = Chat->GetChannels("", "", 25);

// Handle the channels retrieved from first request
for (auto& Channel : Channels.Channels) {
FString ChannelID = Channel->GetChannelID();
// Process the ChannelID
show all 28 lines

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.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");

// Fetch all archived channels
FPubnubChannelsResponseWrapper Channels = Chat->GetChannels("status=='deleted'", "", 100);

for (auto& Channel : Channels.Channels) {
FString ChannelID = Channel->GetChannelID();
// Process the ChannelID
}

show all 23 lines
Last updated on