Manage channel updates
Update channel details and receive events whenever someone updates them.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Update channel details
You can edit the metadata of an existing channel with Update() and UpdateChannel().
Both of them give the same output. The only difference is that you call a given method either on the Chat (UpdateChannel()) or the Channel (Update()) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to update or not because it's already known.
Method signature
- Blueprint
- C++ / Input parameters
-
Channel->Update()1Channel->Update(FPubnubChatChannelData ChannelData); -
Chat->UpdateChannel()1Chat->UpdateChannel(
2 FString ChannelID,
3 FPubnubChatChannelData ChannelData
4);
| Parameter | Required in Channel->Update() | Required in Chat->UpdateChannel() | Description |
|---|---|---|---|
ChannelIDType: FStringDefault: n/a | No | Yes | Unique channel identifier. |
ChannelDataType: FPubnubChatChannelDataDefault: n\a | No | No | Information about the channel. |
FPubnubChatChannelData
| Parameter | Description |
|---|---|
ChannelNameType: FStringDefault: n/a | Display name for the channel (must not be empty or consist only of whitespace characters). |
DescriptionType: FStringDefault: n/a | Channel's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
CustomDataJsonType: FStringDefault: n/a | JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. |
StatusType: FStringDefault: n/a | Tag that lets you categorize your app channels by their current state. The tag choice is entirely up to you and depends on your use case. |
TypeType: FStringDefault: n/a | Tag that lets you categorize your app channels by their functional roles. The tag choice is entirely up to you and depends on your use case. |
Output
| Type | Description |
|---|---|
UPubnubChannel* | Object returning the updated channel metadata. |
Sample code
Update the description of the support channel.
-
Update()1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11// Define the channel data
12FPubnubChatChannelData ChannelData;
13ChannelData.Description = "Channel for CRM tickets";
14
15Channel->Update(ChannelData); -
UpdateChannel()1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9// Define the channel data
10FPubnubChatChannelData ChannelData;
11ChannelData.Description = "Channel for CRM tickets";
12
13Chat->UpdateChannel("support", ChannelData);
Get channel updates
You can receive updates when specific Channel object(s) are edited or removed on other clients using the following methods:
StreamUpdates()checks updates on a singleChannelobject.StreamUpdatesOn()checks updates on aChannelobject list.
Both methods accept a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, changes, or removes channel metadata.
Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects events of type channel. These methods also return the unsubscribe function you can invoke to stop receiving objects events and unsubscribe from the channel.
Method signature
- Blueprint
- C++ / Input parameters
-
StreamUpdates()1Channel->StreamUpdates(FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback); -
StreamUpdatesOn()1Channel->StreamUpdatesOn(
2 TArray<UPubnubChannel*> Channels,
3 FOnPubnubChannelStreamUpdateReceived ChannelUpdateCallback
4);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
ChannelsType: TArray<UPubnubChannel*>Default: n/a | No | Yes | Array of Channel objects for which you want to get updates. |
ChannelUpdateCallbackType: FOnPubnubChannelStreamUpdateReceivedDefault: n/a | Yes | Yes | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting channel metadata changes. |
Output
| Type | Description |
|---|---|
UPubnubCallbackStop* | Object on which you can call Stop() to stop receiving updates. |
Sample code
-
StreamUpdates()Get updates on the
supportchannel.
show all 17 lines1#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// Get the channel and save the reference
10UPubnubChannel* Channel = Chat->GetChannel("support");
11
12// Create a pubnub response delegate
13// you MUST implement your own callback function to handle the response
14FOnPubnubChannelStreamUpdateReceived StreamUpdatesResponse;
15StreamUpdatesResponse.BindDynamic(this, &AMyActor::OnChannelUpdateResponseReceived); -
StreamUpdatesOn()Get updates on the
supportandincident-managementchannels.
show all 22 lines1#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// Get the channels and save the reference
10UPubnubChannel* Channel1 = Chat->GetChannel("support");
11UPubnubChannel* Channel2 = Chat->GetChannel("incident-management");
12
13TArray<UPubnubChannel*> Channels;
14Channels.Add(Channel1);
15Channels.Add(Channel2);
Other examples
-
StreamUpdates()Stop listening to updates on the
supportchannel.1auto StopUpdates = Channel->Channel->StreamUpdates(StreamUpdatesResponse);
2
3StopUpdates->Stop(); -
StreamUpdatesOn()Stop listening to updates on the
supportandincident-managementchannels.1auto StopUpdates = Channel->StreamUpdatesOn(Channels, StreamUpdatesOnResponse);
2
3StopUpdates->Stop();