Skip to content

Commit

Permalink
Merge pull request #827 from Iterable/evan/MOB-10094
Browse files Browse the repository at this point in the history
[MOB-10094] merging bug fix
  • Loading branch information
evantk91 authored Nov 6, 2024
2 parents 53fa126 + 38d715f commit dd21046
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ private void onLogin(
boolean isEmail,
boolean merge,
boolean replay,
boolean isAnon,
@Nullable IterableHelper.FailureHandler failureHandler
) {
if (!isInitialized()) {
Expand All @@ -369,9 +370,9 @@ private void onLogin(
getAuthManager().pauseAuthRetries(false);
if (authToken != null) {
setAuthToken(authToken);
attemptMergeAndEventReplay(userIdOrEmail, isEmail, merge, replay, failureHandler);
attemptMergeAndEventReplay(userIdOrEmail, isEmail, merge, replay, isAnon, failureHandler);
} else {
getAuthManager().requestNewAuthToken(false, data -> attemptMergeAndEventReplay(userIdOrEmail, isEmail, merge, replay, failureHandler));
getAuthManager().requestNewAuthToken(false, data -> attemptMergeAndEventReplay(userIdOrEmail, isEmail, merge, replay, isAnon, failureHandler));
}
}

Expand Down Expand Up @@ -788,7 +789,7 @@ public void setEmail(@Nullable String email, @Nullable String authToken, @Nullab
_userId = null;

if (config.authHandler == null) {
attemptMergeAndEventReplay(email, true, merge, replay, failureHandler);
attemptMergeAndEventReplay(email, true, merge, replay, false, failureHandler);
}

_userIdAnon = null;
Expand All @@ -797,7 +798,7 @@ public void setEmail(@Nullable String email, @Nullable String authToken, @Nullab
_setUserFailureCallbackHandler = failureHandler;
storeAuthData();

onLogin(authToken, email, true, merge, replay, failureHandler);
onLogin(authToken, email, true, merge, replay, false, failureHandler);
}

public void setAnonUser(@Nullable String userId) {
Expand Down Expand Up @@ -854,18 +855,14 @@ public void setUserId(@Nullable String userId, @Nullable String authToken, @Null
_userId = userId;

if (config.authHandler == null) {
attemptMergeAndEventReplay(userId, false, merge, replay, failureHandler);
}

if (!isAnon) {
_userIdAnon = null;
attemptMergeAndEventReplay(userId, false, merge, replay, isAnon, failureHandler);
}

_setUserSuccessCallbackHandler = successHandler;
_setUserFailureCallbackHandler = failureHandler;
storeAuthData();

onLogin(authToken, userId, false, merge, replay, failureHandler);
onLogin(authToken, userId, false, merge, replay, isAnon, failureHandler);
}

private boolean isMerge(@Nullable IterableIdentityResolution iterableIdentityResolution) {
Expand All @@ -876,16 +873,19 @@ private boolean isReplay(@Nullable IterableIdentityResolution iterableIdentityRe
return (iterableIdentityResolution != null) ? iterableIdentityResolution.getReplayOnVisitorToKnown() : config.identityResolution.getReplayOnVisitorToKnown();
}

private void attemptMergeAndEventReplay(@Nullable String emailOrUserId, boolean isEmail, boolean merge, boolean replay, IterableHelper.FailureHandler failureHandler) {
private void attemptMergeAndEventReplay(@Nullable String emailOrUserId, boolean isEmail, boolean merge, boolean replay, boolean isAnon, IterableHelper.FailureHandler failureHandler) {
if (config.enableAnonActivation) {
if (emailOrUserId != null && _userIdAnon != null && !emailOrUserId.equals(_userIdAnon)) {
if (emailOrUserId != null && !emailOrUserId.equals(_userIdAnon)) {
attemptAndProcessMerge(emailOrUserId, isEmail, merge, failureHandler, _userIdAnon);
return;
}

if (replay && (_userId != null || _email != null)) {
anonymousUserManager.syncEventsAndUserUpdate();
}

if (!isAnon) {
_userIdAnon = null;
}
}
}

Expand Down

0 comments on commit dd21046

Please sign in to comment.