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()1User->Update(FPubnubChatUserData UserData); -
Chat->UpdateUser()1Chat->UpdateUser(
2 FString UserID,
3 FPubnubChatUserData UserData
4);
| Parameter | Required in User->Update() | Required in Chat->UpdateUser() | Description |
|---|---|---|---|
UserIDType: FStringDefault: n/a | No | Yes | Unique user identifier. |
UserDataType: FPubnubChatUserDataDefault: n/a | Yes | Yes | Additional user data. |
FPubnubChatUserData
| Parameter | Description |
|---|---|
UserNameType: FStringDefault: n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
ExternalIDType: FStringDefault: n/a | User's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
ProfileUrlType: FStringDefault: n/a | URL of the user's profile picture. |
EmailType: FStringDefault: n/a | User's email address. |
CustomDataJsonType: FStringDefault: 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. |
StatusType: FStringDefault: 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. |
TypeType: FStringDefault: 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. |
Sample code
Change the link to the user's support_agent_15 LinkedIn profile to https://www.linkedin.com/mkelly_vp2.
-
Update()
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// Define user ID
10FString UserID = "support_agent_15";
11UPubnubUser* User = Chat->GetUser(UserID);
12
13FPubnubChatUserData UserData;
14UserData.CustomDataJson = "{\"LinkedIn\":\"https://www.linkedin.com/mkelly_vp2\"}";
15 -
UpdateUser()
show all 16 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// Define user ID
10FString UserID = "support_agent_15";
11
12FPubnubChatUserData UserData;
13UserData.CustomDataJson = "{\"LinkedIn\":\"https://www.linkedin.com/mkelly_vp2\"}";
14
15// 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 singleUserobject.StreamUpdatesOn()checks updates on a list ofUserobjects.
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()1User->StreamUpdates(FOnPubnubUserStreamUpdateReceived UserUpdateCallback); -
StreamUpdatesOn()1User->StreamUpdatesOn(
2 TArray<UPubnubUser*> Users,
3 FOnPubnubUserStreamUpdateReceived UserUpdateCallback
4);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
UsersType: TArray<UPubnubUser*>Default: n/a | No | Yes | Array of User objects for which you want to get updates. |
UserUpdateCallbackType: FOnPubnubUserStreamUpdateReceivedDefault: 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
Get updates on support_agent_15.
-
StreamUpdates()
show all 20 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// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15// Create a pubnub response delegate
Get updates on support_agent_15 and support-manager.
-
StreamUpdatesOn()
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 users and save the reference
10UPubnubUser* User1 = Chat->GetUser("support_agent_15");
11UPubnubUser* User2 = Chat->GetUser("support-manager");
12
13TArray<UPubnubUser*> Users;
14Users.Add(User1);
15Users.Add(User2);
Other examples
Stop listening to updates on support_agent_15.
-
StreamUpdates()1auto StopUpdates = User->StreamUpdates(StreamUpdatesResponse);
2
3StopUpdates->Stop();
Stop listening to updates on support_agent_15 and support-manager.
-
StreamUpdatesOn()1auto StopUpdates = User->StreamUpdatesOn(Users, StreamUpdatesOnResponse);
2
3StopUpdates->Stop();