@@ -35,6 +35,7 @@ void ASample_AppContext::RunSamples()
35
35
SetUserMetadataWithResultSample ();
36
36
SetUserMetadataWithLambdaSample ();
37
37
SetUserMetadataRawSample ();
38
+ UpdateUserMetadataIterativelySample ();
38
39
GetAllUserMetadataSample ();
39
40
GetAllUserMetadataWithSettingsSample ();
40
41
GetAllUserMetadataWithAllIncludesSample ();
@@ -51,6 +52,7 @@ void ASample_AppContext::RunSamples()
51
52
SetChannelMetadataWithResultSample ();
52
53
SetChannelMetadataWithLambdaSample ();
53
54
SetChannelMetadataRawSample ();
55
+ UpdateChannelMetadataIterativelySample ();
54
56
GetAllChannelMetadataSample ();
55
57
GetAllChannelMetadataWithSettingsSample ();
56
58
GetAllChannelMetadataWithAllIncludesSample ();
@@ -198,6 +200,77 @@ void ASample_AppContext::SetUserMetadataRawSample()
198
200
PubnubSubsystem->SetUserMetadataRaw (UserID, UserMetadataJson, OnSetUserMetadataResponse, Include);
199
201
}
200
202
203
+ // snippet.update_user_metadata_iteratively
204
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
205
+ void ASample_AppContext::UpdateUserMetadataIterativelySample ()
206
+ {
207
+ // Get PubnubSubsystem from GameInstance
208
+ UGameInstance* GameInstance = UGameplayStatics::GetGameInstance (this );
209
+ UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem <UPubnubSubsystem>();
210
+
211
+ // Set UserID
212
+ FString UserID = TEXT (" Player_005" );
213
+ PubnubSubsystem->SetUserID (UserID);
214
+
215
+ // Create initial user metadata object
216
+ FPubnubUserData UserMetadata;
217
+ UserMetadata.UserName = " Player Two" ;
218
+ UserMetadata.Status = " active" ;
219
+ UserMetadata.Custom = " {\" inventory_slots\" : 20, \" guild_id\" : \" G2\" }" ;
220
+
221
+ // Bind response delegate
222
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
223
+ FOnSetUserMetadataResponse OnSetUserMetadataResponse;
224
+ OnSetUserMetadataResponse.BindDynamic (this , &ASample_AppContext::OnInitialSetUserMetadataResponse);
225
+
226
+ // Set initial user metadata
227
+ FPubnubGetMetadataInclude Include = FPubnubGetMetadataInclude::FromValue (true );
228
+ PubnubSubsystem->SetUserMetadata (UserID, UserMetadata, OnSetUserMetadataResponse);
229
+ }
230
+
231
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
232
+ void ASample_AppContext::OnInitialSetUserMetadataResponse (FPubnubOperationResult Result, FPubnubUserData UserData)
233
+ {
234
+ if (Result.Error )
235
+ {
236
+ UE_LOG (LogTemp, Error, TEXT (" Failed to set initial user metadata. Status: %d, Reason: %s" ), Result.Status , *Result.ErrorMessage );
237
+ return ;
238
+ }
239
+
240
+ // Get PubnubSubsystem from GameInstance
241
+ UGameInstance* GameInstance = UGameplayStatics::GetGameInstance (this );
242
+ UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem <UPubnubSubsystem>();
243
+
244
+ FString UserID = TEXT (" Player_005" );
245
+
246
+ // Create updated version of user metadata object - change status to "inactive"
247
+ FPubnubUserData UpdatedUserMetadata = UserData;
248
+ UpdatedUserMetadata.Status = " inactive" ;
249
+
250
+ // Bind response delegate
251
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
252
+ FOnSetUserMetadataResponse OnSetUserMetadataResponse;
253
+ OnSetUserMetadataResponse.BindDynamic (this , &ASample_AppContext::OnUpdateUserMetadataResponse);
254
+
255
+ // Update user metadata
256
+ FPubnubGetMetadataInclude Include;
257
+ Include.IncludeStatus = true ;
258
+ PubnubSubsystem->SetUserMetadata (UserID, UpdatedUserMetadata, OnSetUserMetadataResponse, Include);
259
+ }
260
+
261
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
262
+ void ASample_AppContext::OnUpdateUserMetadataResponse (FPubnubOperationResult Result, FPubnubUserData UserData)
263
+ {
264
+ if (Result.Error )
265
+ {
266
+ UE_LOG (LogTemp, Error, TEXT (" Failed to update user metadata. Status: %d, Reason: %s" ), Result.Status , *Result.ErrorMessage );
267
+ }
268
+ else
269
+ {
270
+ UE_LOG (LogTemp, Log, TEXT (" Successfully updated user metadata. New status is: %s" ), *UserData.Status );
271
+ }
272
+ }
273
+
201
274
// ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
202
275
void ASample_AppContext::OnSetUserMetadataRawResponse (FPubnubOperationResult Result, FPubnubUserData UserData)
203
276
{
@@ -779,6 +852,78 @@ void ASample_AppContext::SetChannelMetadataRawSample()
779
852
PubnubSubsystem->SetChannelMetadataRaw (Channel, ChannelMetadataJson, OnSetChannelMetadataResponse, Include);
780
853
}
781
854
855
+ // snippet.update_channel_metadata_iteratively
856
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
857
+ void ASample_AppContext::UpdateChannelMetadataIterativelySample ()
858
+ {
859
+ // Get PubnubSubsystem from GameInstance
860
+ UGameInstance* GameInstance = UGameplayStatics::GetGameInstance (this );
861
+ UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem <UPubnubSubsystem>();
862
+
863
+ // Set UserID
864
+ FString UserID = TEXT (" Player_001" );
865
+ PubnubSubsystem->SetUserID (UserID);
866
+
867
+ // Create initial channel metadata object
868
+ FString ChannelID = TEXT (" iterative-channel-update-test" );
869
+ FPubnubChannelData ChannelMetadata;
870
+ ChannelMetadata.ChannelName = " Channel For Iterative Update" ;
871
+ ChannelMetadata.Description = " This is the initial description." ;
872
+ ChannelMetadata.Custom = " {\" topic\" : \" initial_topic\" }" ;
873
+
874
+ // Bind response delegate
875
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
876
+ FOnSetChannelMetadataResponse OnSetChannelMetadataResponse;
877
+ OnSetChannelMetadataResponse.BindDynamic (this , &ASample_AppContext::OnInitialSetChannelMetadataResponse);
878
+
879
+ // Set initial channel metadata
880
+ PubnubSubsystem->SetChannelMetadata (ChannelID, ChannelMetadata, OnSetChannelMetadataResponse);
881
+ }
882
+
883
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
884
+ void ASample_AppContext::OnInitialSetChannelMetadataResponse (FPubnubOperationResult Result, FPubnubChannelData ChannelData)
885
+ {
886
+ if (Result.Error )
887
+ {
888
+ UE_LOG (LogTemp, Error, TEXT (" Failed to set initial channel metadata. Status: %d, Reason: %s" ), Result.Status , *Result.ErrorMessage );
889
+ return ;
890
+ }
891
+
892
+ UE_LOG (LogTemp, Log, TEXT (" Successfully set initial channel metadata. Description: %s" ), *ChannelData.Description );
893
+
894
+ // Get PubnubSubsystem from GameInstance
895
+ UGameInstance* GameInstance = UGameplayStatics::GetGameInstance (this );
896
+ UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem <UPubnubSubsystem>();
897
+
898
+ // Use the ChannelID from the response
899
+ FString ChannelID = ChannelData.ChannelID ;
900
+
901
+ // Create updated version of channel metadata object - change description only
902
+ FPubnubChannelData UpdatedChannelMetadata;
903
+ UpdatedChannelMetadata.Description = " This is the updated description!" ;
904
+
905
+ // Bind response delegate
906
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
907
+ FOnSetChannelMetadataResponse OnSetChannelMetadataResponse;
908
+ OnSetChannelMetadataResponse.BindDynamic (this , &ASample_AppContext::OnUpdateChannelMetadataResponse);
909
+
910
+ // Update channel metadata
911
+ PubnubSubsystem->SetChannelMetadata (ChannelID, UpdatedChannelMetadata, OnSetChannelMetadataResponse);
912
+ }
913
+
914
+ // ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
915
+ void ASample_AppContext::OnUpdateChannelMetadataResponse (FPubnubOperationResult Result, FPubnubChannelData ChannelData)
916
+ {
917
+ if (Result.Error )
918
+ {
919
+ UE_LOG (LogTemp, Error, TEXT (" Failed to update channel metadata. Status: %d, Reason: %s" ), Result.Status , *Result.ErrorMessage );
920
+ }
921
+ else
922
+ {
923
+ UE_LOG (LogTemp, Log, TEXT (" Successfully updated channel metadata. New description is: '%s' and channel name is still: '%s'" ), *ChannelData.Description , *ChannelData.ChannelName );
924
+ }
925
+ }
926
+
782
927
// ACTION REQUIRED: Replace ASample_AppContext with name of your Actor class
783
928
void ASample_AppContext::OnSetChannelMetadataRawResponse (FPubnubOperationResult Result, FPubnubChannelData ChannelData)
784
929
{
0 commit comments