Skip to content

Commit c51d88d

Browse files
committed
Fix properties api bug sending only default properties for both custom and default propery list.
Microoptimization of network requests.
1 parent fc89ca1 commit c51d88d

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

Satori/Source/SatoriUnreal/Private/SatoriClient.cpp

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,30 @@ void USatoriClient::Authenticate(
145145
const TSharedPtr<FJsonObject> ContentJson = MakeShared<FJsonObject>();
146146

147147
ContentJson->SetStringField(TEXT("id"), ID);
148-
ContentJson->SetBoolField(TEXT("no_session"), bNoSession);
148+
if (bNoSession)
149+
{
150+
ContentJson->SetBoolField(TEXT("no_session"), bNoSession);
151+
}
149152

150-
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
151-
for (const TPair<FString, FString>& Pair : DefaultProperties)
153+
if(!DefaultProperties.IsEmpty())
152154
{
153-
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
155+
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
156+
for (const TPair<FString, FString>& Pair : DefaultProperties)
157+
{
158+
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
159+
}
160+
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
154161
}
155-
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
156162

157-
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
158-
for (const TPair<FString, FString>& Pair : DefaultProperties)
163+
if (!CustomProperties.IsEmpty())
159164
{
160-
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
165+
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
166+
for (const TPair<FString, FString>& Pair : CustomProperties)
167+
{
168+
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
169+
}
170+
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
161171
}
162-
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
163172

164173
// Serialize the request content
165174
FString Content;
@@ -530,19 +539,25 @@ void USatoriClient::Identify(
530539

531540
ContentJson->SetStringField(TEXT("id"), ID);
532541

533-
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
534-
for (const TPair<FString, FString>& Pair : DefaultProperties)
542+
if(!DefaultProperties.IsEmpty())
535543
{
536-
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
544+
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
545+
for (const TPair<FString, FString>& Pair : DefaultProperties)
546+
{
547+
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
548+
}
549+
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
537550
}
538-
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
539551

540-
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
541-
for (const TPair<FString, FString>& Pair : DefaultProperties)
552+
if (!CustomProperties.IsEmpty())
542553
{
543-
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
554+
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
555+
for (const TPair<FString, FString>& Pair : CustomProperties)
556+
{
557+
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
558+
}
559+
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
544560
}
545-
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
546561

547562
// Serialize the request content
548563
FString Content;
@@ -771,19 +786,25 @@ void USatoriClient::UpdateProperties(
771786
// Setup the request content
772787
const TSharedPtr<FJsonObject> ContentJson = MakeShared<FJsonObject>();
773788

774-
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
775-
for (const TPair<FString, FString>& Pair : DefaultProperties)
789+
if (!DefaultProperties.IsEmpty())
776790
{
777-
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
791+
TSharedPtr<FJsonObject> DefaultPropertiesJson = MakeShared<FJsonObject>();
792+
for (const TPair<FString, FString>& Pair : DefaultProperties)
793+
{
794+
DefaultPropertiesJson->SetStringField(Pair.Key, Pair.Value);
795+
}
796+
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
778797
}
779-
ContentJson->SetObjectField(TEXT("default"), DefaultPropertiesJson);
780798

781-
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
782-
for (const TPair<FString, FString>& Pair : DefaultProperties)
799+
if (!CustomProperties.IsEmpty())
783800
{
784-
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
801+
TSharedPtr<FJsonObject> CustomPropertiesJson = MakeShared<FJsonObject>();
802+
for (const TPair<FString, FString>& Pair : CustomProperties)
803+
{
804+
CustomPropertiesJson->SetStringField(Pair.Key, Pair.Value);
805+
}
806+
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
785807
}
786-
ContentJson->SetObjectField(TEXT("custom"), CustomPropertiesJson);
787808

788809
ContentJson->SetBoolField(TEXT("recompute"), bRecompute);
789810

0 commit comments

Comments
 (0)