Manage user updates
Update user details and receive events whenever someone updates them.
Requires App Context
To store data about users, you must enable App Context for your app's keyset in the Admin Portal.
Update user details
You can edit the metadata of an existing user with Update()
and UpdateUser()
.
Both of these methods give the same output. The only difference is that you call a given method either on the Chat
(UpdateUser()
) or the User
(Update()
) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the user ID you want to update or not because it's already known.
Method signature
- Blueprint
- C++ / Input parameters
-
User->Update()
User->Update(FPubnubChatUserData UserData);
-
Chat->UpdateUser()
Chat->UpdateUser(
FString UserID,
FPubnubChatUserData UserData
);
Parameter | Type | Required in User->Update() | Required in Chat->UpdateUser() | Default | Description |
---|---|---|---|---|---|
UserID | FString | No | Yes | n/a | Unique user identifier. |
UserData | FPubnubChatUserData | Yes | Yes | n/a | Additional user data. |
FPubnubChatUserData
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
UserName | FString | No | n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
ExternalID | FString | No | n/a | User's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
ProfileUrl | FString | No | n/a | URL of the user's profile picture. |
Email | FString | No | n/a | User's email address. |
CustomDataJson | FString | No | n/a | JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. |
Status | FString | No | n/a | Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use status to mark users in your chat app as invited , active , or archived . |
Type | FString | No | n/a | Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use type to group users by their roles in your app, such as moderator , player , or support-agent . |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Output
Type | Description |
---|---|
UPubnubUser* | Returned object containing the updated user metadata. |
Basic usage
Change the link to the user's support_agent_15
LinkedIn profile to https://www.linkedin.com/mkelly_vp2
.
-
Update()
show all 17 lines#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");
// Define user ID
FString UserID = "support_agent_15";
UPubnubUser* User = Chat->GetUser(UserID);
FPubnubChatUserData UserData;
UserData.CustomDataJson = "{\"LinkedIn\":\"https://www.linkedin.com/mkelly_vp2\"}"; -
UpdateUser()
show all 16 lines#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");
// Define user ID
FString UserID = "support_agent_15";
FPubnubChatUserData UserData;
UserData.CustomDataJson = "{\"LinkedIn\":\"https://www.linkedin.com/mkelly_vp2\"}";
// Update the user and save the reference
Get user updates
Two methods let you receive updates about users (user IDs) added, edited, or removed on other clients:
StreamUpdates()
checks updates on a singleUser
object.StreamUpdatesOn()
checks updates on a list ofUser
objects.
Both methods accept a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, changes, or removes user metadata.
Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects
(known as App Context) events of type uuid
. 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()
User->StreamUpdates(FOnPubnubUserStreamUpdateReceived UserUpdateCallback);
-
StreamUpdatesOn()
User->StreamUpdatesOn(
TArray<UPubnubUser*> Users,
FOnPubnubUserStreamUpdateReceived UserUpdateCallback
);
Parameter | Type | Required in StreamUpdates() | Required in StreamUpdatesOn() | Default | Description |
---|---|---|---|---|---|
Users | TArray<UPubnubUser*> | No | Yes | n/a | Array of User objects for which you want to get updates. |
UserUpdateCallback | FOnPubnubUserStreamUpdateReceived | Yes | Yes | n/a | 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. |
Basic usage
Get updates on support_agent_15
.
-
StreamUpdates()
show all 20 lines#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");
// Define user ID
FString UserID = "support_agent_15";
// Get the user and save the reference
UPubnubUser* User = Chat->GetUser(UserID);
// Create a pubnub response delegate
Get updates on support_agent_15
and support-manager
.
-
StreamUpdatesOn()
show all 22 lines#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");
// Get the users and save the reference
UPubnubUser* User1 = Chat->GetUser("support_agent_15");
UPubnubUser* User2 = Chat->GetUser("support-manager");
TArray<UPubnubUser*> Users;
Users.Add(User1);
Users.Add(User2);
Other examples
Stop listening to updates on support_agent_15
.
-
StreamUpdates()
auto StopUpdates = User->StreamUpdates(StreamUpdatesResponse);
StopUpdates->Stop();
Stop listening to updates on support_agent_15
and support-manager
.
-
StreamUpdatesOn()
auto StopUpdates = User->StreamUpdatesOn(Users, StreamUpdatesOnResponse);
StopUpdates->Stop();