Manage user updates
Update user details and receive real-time update events.
Requires App Context
Enable App Context in the Admin Portal to store user data.
Update user details
Edit user metadata with Update() or UpdateUser().
Update()- call on aUserobject (no ID needed)UpdateUser()- call on aChatobject (requires user ID)
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
Receive updates when User objects are edited or removed:
StreamUpdates()- monitors a single userStreamUpdatesOn()- monitors multiple users
Both methods accept a callback invoked when user metadata changes. They subscribe to a channel and add an objects event listener, returning an unsubscribe function.
Callback behavior
StreamUpdates()- returns updatedUserobject (nullptrif deleted)StreamUpdatesOn()- returns complete list of monitored users on any change
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();