Skip to content
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

Feature_MC-1970 #88

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ internal static class EventMeta {
internal const string REF = "ref";
internal const string WZRK_REF = "wzrk_ref";
internal const string DISCARDED_EVENT_JSON_KEY = "d_e";

internal const string NAMESPACE_IJ = "IJ";

internal const string KEY_I = "comms_i";
internal const string KEY_J = "comms_j";
}

internal static class Validator {
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is better for the interceptor to not have a reference to the network engine. This creates a circular reference since the engine adds and holds the interceptors.
The options on top of my head are:

  1. The interceptor to set the _i and _j in the preferences and the engine to use them from there. The interceptor can get the preference manager using the account id.
  2. Do this logic directly in the network engine.
    I believe it might be cleaner to go with 1. since you also already started with that approach.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using CleverTapSDK.Native;
using CleverTapSDK.Utilities;

#if (!UNITY_IOS && !UNITY_ANDROID) || UNITY_EDITOR
namespace Native.UnityNativeWrapper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix namespace to be CleverTapSDK.Native and remove it from the usings.

{
internal class UnityNativeMetadataResponseInterceptor : IUnityNativeResponseInterceptor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response interceptor is unused, it is not added to the engine interceptors.

{
private readonly UnityNativeNetworkEngine _networkEngine;
public UnityNativeMetadataResponseInterceptor(string accountId, UnityNativeNetworkEngine networkEngine)
{
_networkEngine = networkEngine;
}

UnityNativeResponse IUnityNativeResponseInterceptor.Intercept(UnityNativeResponse response)
{
Dictionary<string,object> responseContent = Json.Deserialize(response.Content) as Dictionary<string,object>;
if (responseContent == null || responseContent.Count <= 0)
return response;
// Handle i
try {
if (responseContent.TryGetValue("_i", out var value)) {
long i = long.Parse(value.ToString());
_networkEngine.SetI(i);
}
} catch (Exception t) {
// Ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not ignore the exception.

}

// Handle j
try {
if (responseContent.TryGetValue("_j", out var value)) {
long j = long.Parse(value.ToString());
_networkEngine.SetJ(j);
}
} catch (Exception t) {
// Ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not ignore the exception.

}

return response;
}
}
}
#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
Expand Up @@ -303,6 +303,17 @@ private void ApplyNetworkEngineRequestConfiguration(UnityNativeRequest request)
}
}
}

long i = GetI();
if (i > 0) {
allHeaders.Add("_i", i+"");
}

long j = GetJ();
if (j > 0) {
allHeaders.Add("_j", j+"");
}

//Add ARP
allHeaders = AddARP(allHeaders);
request.SetHeaders(allHeaders);
Expand Down Expand Up @@ -433,6 +444,30 @@ private async Task<UnityNativeResponse> SendRequest(UnityNativeRequest request)
return new UnityNativeResponse(request, HttpStatusCode.InternalServerError, null, null, ex.Message);
}
}

public long GetI()
{
string tempKey = $"{UnityNativeConstants.EventMeta.KEY_I}:{_coreState.AccountInfo.AccountId}";
return _preferenceManager.GetLong( tempKey,0);
}

public void SetI(long l)
{
string tempKey = $"{UnityNativeConstants.EventMeta.KEY_I}:{_coreState.AccountInfo.AccountId}";
_preferenceManager.SetLong( tempKey,l);
}

public long GetJ()
{
string tempKey = $"{UnityNativeConstants.EventMeta.KEY_J}:{_coreState.AccountInfo.AccountId}";
return _preferenceManager.GetLong( tempKey,0);
}
public void SetJ(long l)
{
string tempKey = $"{UnityNativeConstants.EventMeta.KEY_J}:{_coreState.AccountInfo.AccountId}";
_preferenceManager.SetLong( tempKey,l);
}

}
}
#endif