-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MC-1969 fixes #86
base: develop
Are you sure you want to change the base?
MC-1969 fixes #86
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,11 @@ | |
|
||
namespace CleverTapSDK.Native { | ||
internal class UnityNativeRaisedEventBuilder { | ||
internal UnityNativeRaisedEventBuilder() { } | ||
|
||
private UnityNativeEventValidator _eventValidator; | ||
internal UnityNativeRaisedEventBuilder(UnityNativeEventValidator eventValidator) | ||
{ | ||
this._eventValidator = eventValidator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the _eventValidator is not used, currently each method uses a new instance instead of that one. Use the instance _eventValidator or remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, reverted it back to last change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not fixed. You need to use the eventValidator passed from the constructor so it has the discarded events. |
||
} | ||
internal UnityNativeEventBuilderResult<Dictionary<string, object>> Build(string eventName, Dictionary<string, object> properties = null) { | ||
var eventValidator = new UnityNativeEventValidator(); | ||
var eventValidationResultsWithErrors = new List<UnityNativeValidationResult>(); | ||
|
@@ -19,6 +22,12 @@ internal UnityNativeEventBuilderResult<Dictionary<string, object>> Build(string | |
eventValidationResultsWithErrors.Add(isRestrictedNameValidationResult); | ||
return new UnityNativeEventBuilderResult<Dictionary<string, object>>(eventValidationResultsWithErrors, null); | ||
} | ||
|
||
var isDiscardedValidationResult = eventValidator.IsEventDiscarded(eventName); | ||
if (!isDiscardedValidationResult.IsSuccess) { | ||
eventValidationResultsWithErrors.Add(isDiscardedValidationResult); | ||
return new UnityNativeEventBuilderResult<Dictionary<string, object>>(eventValidationResultsWithErrors, null); | ||
} | ||
|
||
var cleanEventNameValidationResult = eventValidator.CleanEventName(eventName, out var cleanEventName); | ||
if (!cleanEventNameValidationResult.IsSuccess) { | ||
|
@@ -33,12 +42,12 @@ internal UnityNativeEventBuilderResult<Dictionary<string, object>> Build(string | |
return new UnityNativeEventBuilderResult<Dictionary<string, object>>(eventValidationResultsWithErrors, eventDetails); | ||
} | ||
|
||
var cleanObjectDictonaryValidationResult = CleanObjectDictonary(properties); | ||
if (cleanObjectDictonaryValidationResult.ValidationResults.Any(vr => !vr.IsSuccess)) { | ||
eventValidationResultsWithErrors.AddRange(cleanObjectDictonaryValidationResult.ValidationResults.Where(vr => !vr.IsSuccess)); | ||
var cleanObjectDictionaryValidationResult = CleanObjectDictonary(properties); | ||
if (cleanObjectDictionaryValidationResult.ValidationResults.Any(vr => !vr.IsSuccess)) { | ||
eventValidationResultsWithErrors.AddRange(cleanObjectDictionaryValidationResult.ValidationResults.Where(vr => !vr.IsSuccess)); | ||
} | ||
|
||
eventDetails.Add(UnityNativeConstants.Event.EVENT_DATA, cleanObjectDictonaryValidationResult.EventResult); | ||
eventDetails.Add(UnityNativeConstants.Event.EVENT_DATA, cleanObjectDictionaryValidationResult.EventResult); | ||
|
||
return new UnityNativeEventBuilderResult<Dictionary<string, object>>(eventValidationResultsWithErrors, eventDetails); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using CleverTapSDK.Native; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused namespace. |
||
using CleverTapSDK.Utilities; | ||
|
||
#if (!UNITY_IOS && !UNITY_ANDROID) || UNITY_EDITOR | ||
namespace CleverTapSDK.Native | ||
{ | ||
internal class UnityNativeARPResponseInterceptor : IUnityNativeResponseInterceptor | ||
{ | ||
private readonly UnityNativeEventValidator _eventValidator; | ||
private readonly string _accountId; | ||
private readonly string _namespaceARPKey; | ||
public UnityNativeARPResponseInterceptor(string accountId,string deviceId, UnityNativeEventValidator eventValidator) | ||
{ | ||
this._accountId = accountId; | ||
this._namespaceARPKey = string.Format(UnityNativeConstants.Network.ARP_NAMESPACE_KEY,accountId,deviceId); | ||
_eventValidator = eventValidator; | ||
} | ||
|
||
UnityNativeResponse IUnityNativeResponseInterceptor.Intercept(UnityNativeResponse response) | ||
{ | ||
var result = Json.Deserialize(response.Content) as Dictionary<string, object>; | ||
try | ||
{ | ||
if (result.ContainsKey("arp")) | ||
if (Json.Deserialize(result["arp"].ToString()) is Dictionary<string, object> { Count: > 0 } arp) | ||
{ | ||
//Handle Discarded events in ARP | ||
try | ||
{ | ||
ProcessDiscardedEventsList(arp); | ||
} | ||
catch (Exception t) | ||
{ | ||
CleverTapLogger.Log("Failed to process ARP discarded events"); | ||
} | ||
|
||
HandleARPUpdate(arp); | ||
} | ||
} | ||
catch (Exception exception) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'exception' variable is not used. Please log the exception details. |
||
{ | ||
CleverTapLogger.Log("Failed to process ARP"); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
|
||
private void HandleARPUpdate(Dictionary<string, object> arp) | ||
{ | ||
if (arp == null || arp.Count == 0 || string.IsNullOrEmpty(_namespaceARPKey)) | ||
return; | ||
|
||
UnityNativePreferenceManager preferenceManager = UnityNativePreferenceManager.GetPreferenceManager(_accountId); | ||
Dictionary<string, object> currentARP = Json.Deserialize(preferenceManager.GetString(_namespaceARPKey, "{}")) as Dictionary<string, object>; | ||
|
||
if (currentARP == null || currentARP.Count == 0) | ||
{ | ||
preferenceManager.SetString(_namespaceARPKey, Json.Serialize(arp)); | ||
return; | ||
} | ||
|
||
foreach (var keyValuePair in arp) | ||
{ | ||
string key = keyValuePair.Key; | ||
object value = keyValuePair.Value; | ||
|
||
switch (value) | ||
{ | ||
case int i: | ||
currentARP[key] = i; | ||
break; | ||
case long l: | ||
currentARP[key] = l; | ||
break; | ||
case float f: | ||
currentARP[key] = f; | ||
break; | ||
case double d: | ||
currentARP[key] = d; | ||
break; | ||
case string s: | ||
currentARP[key] = s; | ||
break; | ||
case bool b: | ||
currentARP[key] = b; | ||
break; | ||
default: | ||
CleverTapLogger.Log($"ARP update for key {key} rejected (invalid data type)"); | ||
break; | ||
} | ||
} | ||
|
||
preferenceManager.SetString(_namespaceARPKey, Json.Serialize(currentARP)); | ||
} | ||
|
||
|
||
private void ProcessDiscardedEventsList(Dictionary<string, object> response) | ||
{ | ||
if (!response.ContainsKey(UnityNativeConstants.EventMeta.DISCARDED_EVENT_JSON_KEY)) | ||
{ | ||
CleverTapLogger.Log("ARP doesn't contain the Discarded Events key"); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
var discardedEventsList = new List<string>(); | ||
// Get the discarded event JSON from the response | ||
string discardedEventsJson = response[UnityNativeConstants.EventMeta.DISCARDED_EVENT_JSON_KEY].ToString(); | ||
var discardedEventsArray = Json.Deserialize(discardedEventsJson) as List<string>; | ||
if (discardedEventsArray != null) | ||
{ | ||
discardedEventsList.AddRange(discardedEventsArray); | ||
} | ||
if (_eventValidator != null) | ||
_eventValidator.SetDiscardedEvents(discardedEventsList); | ||
else | ||
CleverTapLogger.Log("Validator object is NULL"); | ||
} | ||
catch (Exception e) | ||
{ | ||
CleverTapLogger.Log("Error parsing discarded events list" + e.StackTrace); | ||
} | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,14 @@ internal abstract class UnityNativeBaseEventQueue | |
|
||
protected UnityNativeCoreState coreState; | ||
protected UnityNativeNetworkEngine networkEngine; | ||
|
||
protected UnityNativeEventValidator eventValidator; | ||
private Coroutine timerCoroutine; | ||
|
||
internal UnityNativeBaseEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine, int queueLimit = 49, int defaultTimerInterval = 1) | ||
internal UnityNativeBaseEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine,UnityNativeEventValidator eventValidator, int queueLimit = 49, int defaultTimerInterval = 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eventValidator is not needed since it is unused. |
||
{ | ||
this.coreState = coreState; | ||
this.networkEngine = networkEngine; | ||
this.eventValidator = eventValidator; | ||
this.queueLimit = queueLimit; | ||
this.defaultTimerInterval = defaultTimerInterval; | ||
eventsQueue = new Queue<List<UnityNativeEvent>>(); | ||
|
@@ -163,7 +164,7 @@ internal Dictionary<string, object> BuildMeta() | |
{ | ||
{ UnityNativeConstants.EventMeta.GUID, deviceInfo.DeviceId }, | ||
{ UnityNativeConstants.EventMeta.TYPE, UnityNativeConstants.EventMeta.TYPE_NAME }, | ||
{ UnityNativeConstants.EventMeta.APPLICATION_FIELDS, new UnityNativeEventBuilder(coreState, networkEngine).BuildAppFields() }, | ||
{ UnityNativeConstants.EventMeta.APPLICATION_FIELDS, new UnityNativeEventBuilder(coreState, networkEngine,eventValidator).BuildAppFields() }, | ||
{ UnityNativeConstants.EventMeta.ACCOUNT_ID, accountInfo.AccountId }, | ||
{ UnityNativeConstants.EventMeta.ACCOUNT_TOKEN, accountInfo.AccountToken }, | ||
{ UnityNativeConstants.EventMeta.FIRST_REQUEST_IN_SESSION, coreState.SessionManager.IsFirstSession() } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ internal class UnityNativeRaisedEventQueue : UnityNativeBaseEventQueue { | |
|
||
protected override string QueueName => "RAISED_EVENTS"; | ||
|
||
internal UnityNativeRaisedEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine, int queueLimit = 49, int defaultTimerInterval = 1) : base(coreState, networkEngine, queueLimit, defaultTimerInterval) { } | ||
internal UnityNativeRaisedEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine, UnityNativeEventValidator eventValidator, int queueLimit = 49, int defaultTimerInterval = 1) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The eventValidator seems unused here. Why do we need it? |
||
base(coreState, networkEngine,eventValidator, queueLimit, defaultTimerInterval) { } | ||
|
||
protected override string RequestPath => UnityNativeConstants.Network.REQUEST_PATH_RECORD; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ internal class UnityNativeUserEventQueue : UnityNativeBaseEventQueue { | |
|
||
protected override string QueueName => "USER_EVENTS"; | ||
|
||
internal UnityNativeUserEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine, int queueLimit = 49, int defaultTimerInterval = 1) : base(coreState, networkEngine, queueLimit, defaultTimerInterval) { } | ||
internal UnityNativeUserEventQueue(UnityNativeCoreState coreState, UnityNativeNetworkEngine networkEngine, UnityNativeEventValidator eventValidator, int queueLimit = 49, int defaultTimerInterval = 1) : base(coreState, networkEngine, eventValidator, queueLimit, defaultTimerInterval) { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eventValidor is unused, remove it. |
||
|
||
protected override string RequestPath => UnityNativeConstants.Network.REQUEST_PATH_RECORD; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#if (!UNITY_IOS && !UNITY_ANDROID) || UNITY_EDITOR | ||
namespace CleverTapSDK.Native { | ||
internal class UnityNativeValidationResult { | ||
public class UnityNativeValidationResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this need to be public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not fixed. |
||
// TODO : Consider converting errorCode into appropriate enumration(Enum) | ||
|
||
private readonly int? _errorCode; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventValidator is unused, so it is not needed