Skip to content

Commit

Permalink
Merge pull request #127 from BranchMetrics/SDK-2041-Windows-Stop-call…
Browse files Browse the repository at this point in the history
…ing-v1-profile-and-v1-logout

SDK-2041 Windows Stop calling v1 profile and v1 logout
  • Loading branch information
NidhiDixit09 authored Sep 14, 2023
2 parents 927b3d2 + 5034783 commit ff74cf2
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 102 deletions.
8 changes: 4 additions & 4 deletions BranchSDK-Samples/TestBed/TestBed.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugMT|Win32">
<Configuration>DebugMT</Configuration>
Expand Down Expand Up @@ -322,13 +322,13 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.220331.4\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.220224.4\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@
<ProjectReference Include="..\TestBed.vcxproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="2.0.220331.4" />
<PackageReference Include="Microsoft.Windows.CppWinRT">
<Version>2.0.220224.4</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
2 changes: 1 addition & 1 deletion BranchSDK-Samples/TestBed/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.220331.4" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.220224.4" targetFramework="native" />
</packages>
1 change: 0 additions & 1 deletion BranchSDK/Visual Studio/BranchIO/BranchIO.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<ClInclude Include="..\..\src\BranchIO\Event\BaseEvent.h" />
<ClInclude Include="..\..\src\BranchIO\Event\CustomEvent.h" />
<ClInclude Include="..\..\src\BranchIO\Event\Event.h" />
<ClInclude Include="..\..\src\BranchIO\Event\IdentityEvent.h" />
<ClInclude Include="..\..\src\BranchIO\Event\SessionEvent.h" />
<ClInclude Include="..\..\src\BranchIO\Event\StandardEvent.h" />
<ClInclude Include="..\..\src\BranchIO\fwd.h" />
Expand Down
3 changes: 0 additions & 3 deletions BranchSDK/Visual Studio/BranchIO/BranchIO.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<ClInclude Include="..\..\src\BranchIO\Event\Event.h">
<Filter>Header Files\BranchIO\Event</Filter>
</ClInclude>
<ClInclude Include="..\..\src\BranchIO\Event\IdentityEvent.h">
<Filter>Header Files\BranchIO\Event</Filter>
</ClInclude>
<ClInclude Include="..\..\src\BranchIO\Event\SessionEvent.h">
<Filter>Header Files\BranchIO\Event</Filter>
</ClInclude>
Expand Down
86 changes: 52 additions & 34 deletions BranchSDK/src/BranchIO/Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using namespace std;

#include "BranchIO/DeviceInfo.h"
#include "BranchIO/Event/Event.h"
#include "BranchIO/Event/IdentityEvent.h"
#include "BranchIO/Event/SessionEvent.h"
#include "BranchIO/IRequestCallback.h"
#include "BranchIO/Util/Log.h"
Expand Down Expand Up @@ -54,6 +53,8 @@ class SessionCallback : public IRequestCallback {
}
if (jsonResponse.has(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN))
_context->getSessionInfo().setBundleToken(jsonResponse.getNamedString(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN));
if (jsonResponse.has(Defines::JSONKEY_LINK))
_context->getSessionInfo().setLinkValue(jsonResponse.getNamedString(Defines::JSONKEY_LINK));
}
_context->getSessionInfo().setSessionId(jsonResponse.getNamedString(Defines::JSONKEY_SESSION_ID));
}
Expand Down Expand Up @@ -218,26 +219,23 @@ Branch::sendEvent(const BaseEvent &event, IRequestCallback *callback) {
void
Branch::setIdentity(const String& userId, IRequestCallback* callback) {
if (getSessionInfo().hasSessionId()) {
IdentityLoginEvent event(userId.str());
event.setResultHandler([this, userId](const JSONObject& result) {
/*
* Note that setBundleToken just generates an error via sendEvent below
* if tracking is disabled. This callback is only invoked on successful
* completion of the request.
*/
IStorage& storage(Storage::instance());
storage.setString("session.identity", userId.str());
if (result.has(Defines::JSONKEY_SESSION_ID)) {
auto sessionId = result.getNamedString(Defines::JSONKEY_SESSION_ID);
getSessionInfo().setSessionId(sessionId);
if (getAdvertiserInfo().isTrackingDisabled()) {
if (callback) {
callback->onStatus(0, 0, "Requested operation cannot be completed since tracking is disabled");
callback->onError(0, 0, "Tracking is disabled");
}
if (result.has(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN)) {
auto bundleToken = result.getNamedString(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN);
getSessionInfo().setBundleToken(bundleToken);
storage.setString("session.randomized_bundle_token", bundleToken);
}
});
sendEvent(event, callback);
return;
}

IStorage& storage(Storage::instance());
storage.setString("session.identity", userId.str());

if (callback) {
JSONObject& result = JSONObject();
getIdentityCallbackReturnParams(result);
callback->onSuccess(0, result);
}

} else {
if (callback) {
callback->onError(0, 0, "No Session has been started.");
Expand All @@ -248,28 +246,48 @@ Branch::setIdentity(const String& userId, IRequestCallback* callback) {
void
Branch::logout(IRequestCallback *callback) {
if (getSessionInfo().hasSessionId()) {
IdentityLogoutEvent event;
event.setResultHandler([this](const JSONObject& result) {
IStorage& storage(Storage::instance());
storage.remove("session.identity");
if (result.has(Defines::JSONKEY_SESSION_ID)) {
auto sessionId = result.getNamedString(Defines::JSONKEY_SESSION_ID);
getSessionInfo().setSessionId(sessionId);
if (getAdvertiserInfo().isTrackingDisabled()) {
if (callback) {
callback->onStatus(0, 0, "Requested operation cannot be completed since tracking is disabled");
callback->onError(0, 0, "Tracking is disabled");
}
if (result.has(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN)) {
auto bundleToken = result.getNamedString(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN);
getSessionInfo().setBundleToken(bundleToken);
storage.setString("session.randomized_bundle_token", bundleToken);
}
});
sendEvent(event, callback);
return;
}

IStorage& storage(Storage::instance());
storage.remove("session.identity");

if (callback) {
JSONObject& result = JSONObject();
getIdentityCallbackReturnParams(result);
callback->onSuccess(0, result);
}

} else {
if (callback) {
callback->onError(0, 0, "No Session has been started.");
}
}
}


void Branch::getIdentityCallbackReturnParams(JSONObject& identityParams)
{

std::string sessionID = getSessionInfo().getStringProperty(Defines::JSONKEY_SESSION_ID);
if (sessionID.length())
identityParams.set(Defines::JSONKEY_SESSION_ID, sessionID);

std::string bundleToken = getSessionInfo().getStringProperty(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN);
if (bundleToken.length())
identityParams.set(Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN, bundleToken);

std::string link = getSessionInfo().getStringProperty(Defines::JSONKEY_LINK);
if (link.length())
identityParams.set(Defines::JSONKEY_LINK, link);

// return resultParams;
}
string
Branch::getIdentity() {
return Storage::instance().getString("session.identity");
Expand Down
6 changes: 6 additions & 0 deletions BranchSDK/src/BranchIO/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ class BRANCHIO_DLL_EXPORT Branch {
*/
void waitTillFinished();

/**
* Returns a JSON object with SessionID, Randomized bundle Token and link.
* Its passed in callback in setIdentity and logout (to fake response from /v1/profile and v1/logout)
*/
//JSONObject & getIdentityCallbackReturnParams();
void getIdentityCallbackReturnParams(JSONObject& identityParams);
protected:
Branch();

Expand Down
1 change: 1 addition & 0 deletions BranchSDK/src/BranchIO/Defines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const char* Defines::JSONKEY_SESSION_RANDOMIZED_BUNDLE_TOKEN = "randomized_bundl
const char *Defines::JSONKEY_TRACKING_DISABLED = "tracking_disabled";
const char* Defines::JSONKEY_WINDOWS_ADVERTISING_ID = "windows_advertising_id";
const char* Defines::JSONKEY_LINK_IDENTIFIER = "link_identifier";
const char* Defines::JSONKEY_LINK = "link";
// Branch Url Path
const char *Defines::BASE_PATH_V2 = "https://api2.branch.io/";

Expand Down
1 change: 1 addition & 0 deletions BranchSDK/src/BranchIO/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class BRANCHIO_DLL_EXPORT Defines {
static const char *JSONKEY_TRACKING_DISABLED; ///< Tracking Disabled
static const char* JSONKEY_WINDOWS_ADVERTISING_ID; ///< Windows Advertising ID
static const char* JSONKEY_LINK_IDENTIFIER; ///< link_click_id from inbound URI
static const char* JSONKEY_LINK; /// link param returned in /v1/open response

// Branch Url Path
static const char *BASE_PATH_V1; ///< V1 Base Path
Expand Down
57 changes: 0 additions & 57 deletions BranchSDK/src/BranchIO/Event/IdentityEvent.h

This file was deleted.

5 changes: 5 additions & 0 deletions BranchSDK/src/BranchIO/SessionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ SessionInfo::setSessionId(const std::string &sessionId) {
return doAddProperty(Defines::JSONKEY_SESSION_ID, sessionId);
}

SessionInfo&
SessionInfo::setLinkValue(const std::string& link) {
return doAddProperty(Defines::JSONKEY_LINK, link);
}

bool
SessionInfo::hasSessionId() const {
return has(Defines::JSONKEY_SESSION_ID);
Expand Down
8 changes: 8 additions & 0 deletions BranchSDK/src/BranchIO/SessionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class BRANCHIO_DLL_EXPORT SessionInfo : public PropertyManager {
* @return true if there is a current session.
*/
virtual bool hasSessionId() const;

/**
* Set the link param value. This will be used by setIdentity function.
* @param link param returned from /v1/open
* @return This object for chaining builder methods
*/
virtual SessionInfo& setLinkValue(const std::string& link);


private:
virtual SessionInfo& doAddProperty(const char *name, const std::string &value);
Expand Down
3 changes: 2 additions & 1 deletion BranchSDK/src/BranchIO/Util/APIClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ APIClientSession::processResponse(IRequestCallback& callback, JSONObject& result

std::wstring httpResponseBody = httpResponseMessage.Content().ReadAsStringAsync().get().c_str();
result = JSONObject::parse(to_string(httpResponseBody));

if(!result.isEmpty())
BRANCH_LOG_D("Response : " << result.stringify());
callback.onSuccess(0, result);

return true;
Expand Down

0 comments on commit ff74cf2

Please sign in to comment.