Skip to content

Commit 38f0fd2

Browse files
authored
Merge pull request #93 from Leanplum/sdk-341-fcu
Fix FCU Inbox
2 parents aa1da2b + f372e6b commit 38f0fd2

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

Leanplum-Unity-SDK/Assets/LeanplumSDK/LeanplumUnityHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void Update()
117117
// This is called by Unity on every frame.
118118
if (VarCache.VarsNeedUpdate && developerModeEnabled && Leanplum.HasStarted)
119119
{
120-
VarCache.CheckVarsUpdate();
120+
Leanplum.ForceContentUpdate();
121121
}
122122

123123
// Run deferred actions.

Leanplum-Unity-SDK/Assets/LeanplumSDK/Native/LeanplumNative.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,54 @@ public override void ForceContentUpdate()
999999
///
10001000
public override void ForceContentUpdate(Action callback)
10011001
{
1002-
VarCache.CheckVarsUpdate(callback);
1002+
IDictionary<string, string> updateVarsParams = new Dictionary<string, string>();
1003+
1004+
if (Leanplum.IsDeveloperModeEnabled)
1005+
{
1006+
updateVarsParams[Constants.Params.INCLUDE_DEFAULTS] = Leanplum.IncludeDefaults.ToString();
1007+
}
1008+
else
1009+
{
1010+
updateVarsParams[Constants.Params.INCLUDE_DEFAULTS] = false.ToString();
1011+
}
1012+
// The Inbox is loaded on Start
1013+
updateVarsParams[Constants.Keys.INBOX_MESSAGES] = Json.Serialize(Inbox.MessageIds);
1014+
1015+
LeanplumRequest updateVarsReq = LeanplumRequest.Post(Constants.Methods.GET_VARS, updateVarsParams);
1016+
updateVarsReq.Response += delegate (object varsUpdate)
1017+
{
1018+
var getVariablesResponse = Util.GetLastResponse(varsUpdate) as IDictionary<string, object>;
1019+
var newVarValues = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.VARS) as IDictionary<string, object>;
1020+
var newMessages = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.MESSAGES) as IDictionary<string, object>;
1021+
var newVarFileAttributes = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.FILE_ATTRIBUTES) as IDictionary<string, object>;
1022+
var newVariants = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.VARIANTS) as List<object> ?? new List<object>();
1023+
bool syncInbox = (bool)Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.SYNC_INBOX, false);
1024+
1025+
VarCache.ApplyVariableDiffs(newVarValues, newMessages, newVarFileAttributes, newVariants);
1026+
1027+
// Download inbox messages
1028+
if (syncInbox)
1029+
{
1030+
if (Inbox is LeanplumInboxNative nativeInbox)
1031+
{
1032+
nativeInbox.DownloadMessages();
1033+
}
1034+
}
1035+
1036+
if (callback != null)
1037+
{
1038+
callback();
1039+
}
1040+
};
1041+
updateVarsReq.Error += delegate
1042+
{
1043+
if (callback != null)
1044+
{
1045+
callback();
1046+
}
1047+
};
1048+
updateVarsReq.SendNow();
1049+
VarCache.VarsNeedUpdate = false;
10031050
}
10041051

10051052
#endregion

Leanplum-Unity-SDK/Assets/LeanplumSDK/Native/VarCache.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -428,52 +428,6 @@ internal static IDictionary<string, object> MergeMessage(IDictionary<string, obj
428428
return messageConfig;
429429
}
430430

431-
internal static void CheckVarsUpdate()
432-
{
433-
CheckVarsUpdate (null);
434-
}
435-
436-
internal static void CheckVarsUpdate(Action callback)
437-
{
438-
IDictionary<string, string> updateVarsParams = new Dictionary<string, string>();
439-
440-
if (Leanplum.IsDeveloperModeEnabled)
441-
{
442-
updateVarsParams[Constants.Params.INCLUDE_DEFAULTS] = Leanplum.IncludeDefaults.ToString();
443-
}
444-
else
445-
{
446-
updateVarsParams[Constants.Params.INCLUDE_DEFAULTS] = false.ToString();
447-
}
448-
updateVarsParams[Constants.Params.INCLUDE_DEFAULTS] = false.ToString();
449-
450-
LeanplumRequest updateVarsReq = LeanplumRequest.Post(Constants.Methods.GET_VARS, updateVarsParams);
451-
updateVarsReq.Response += delegate(object varsUpdate)
452-
{
453-
var getVariablesResponse = Util.GetLastResponse(varsUpdate) as IDictionary<string, object>;
454-
var newVarValues = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.VARS) as IDictionary<string, object>;
455-
var newMessages = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.MESSAGES) as IDictionary<string, object>;
456-
var newVarFileAttributes = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.FILE_ATTRIBUTES) as IDictionary<string, object>;
457-
var newVariants = Util.GetValueOrDefault(getVariablesResponse, Constants.Keys.VARIANTS) as List<object> ?? new List<object>();
458-
459-
ApplyVariableDiffs(newVarValues, newMessages, newVarFileAttributes, newVariants);
460-
461-
if (callback != null)
462-
{
463-
callback();
464-
}
465-
};
466-
updateVarsReq.Error += delegate
467-
{
468-
if (callback != null)
469-
{
470-
callback();
471-
}
472-
};
473-
updateVarsReq.SendNow();
474-
VarsNeedUpdate = false;
475-
}
476-
477431
internal static bool SendVariablesIfChanged()
478432
{
479433
if (devModeValuesFromServer != null && valuesFromClient != devModeValuesFromServer)

0 commit comments

Comments
 (0)