Skip to content

Commit dd6b61e

Browse files
Clean up and simplify method logic
1 parent c2f7341 commit dd6b61e

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,52 +1488,58 @@ private void confirmEmail(
14881488
IdentityApi identityApi,
14891489
Runnable runnable
14901490
) {
1491-
if (((email != null && !email.isEmpty()) || (hashedEmail != null && !hashedEmail.isEmpty())) && user != null) {
1491+
boolean hasEmail = email != null && !email.isEmpty();
1492+
boolean hasHashedEmail = hashedEmail != null && !hashedEmail.isEmpty();
1493+
1494+
if ((hasEmail || hasHashedEmail) && user != null) {
14921495
String existingEmail = user.getUserIdentities().get(MParticle.IdentityType.Email);
14931496
String existingHashedEmail = user.getUserIdentities().get(MParticle.IdentityType.Other);
14941497

1495-
if ((email != null && !email.equalsIgnoreCase(existingEmail)) || (hashedEmail != null && !hashedEmail.equalsIgnoreCase(existingHashedEmail))) {
1498+
boolean emailMismatch = hasEmail && !email.equalsIgnoreCase(existingEmail);
1499+
boolean hashedEmailMismatch = hasHashedEmail && !hashedEmail.equalsIgnoreCase(existingHashedEmail);
1500+
1501+
if (emailMismatch || hashedEmailMismatch) {
14961502
// If there's an existing email but it doesn't match the passed-in email, log a warning
1497-
if (existingEmail != null && email != null) {
1503+
if (emailMismatch && existingEmail != null) {
14981504
Logger.warning(String.format(
14991505
"The existing email on the user (%s) does not match the email passed to selectPlacements (%s). " +
15001506
"Please make sure to sync the email identity to mParticle as soon as it's available. " +
15011507
"Identifying user with the provided email before continuing to selectPlacements.",
15021508
existingEmail, email
15031509
));
1504-
} else if (existingHashedEmail != null && hashedEmail != null) {
1510+
}
1511+
// If there's an existing other but it doesn't match the passed-in hashed email, log a warning
1512+
else if (hashedEmailMismatch && existingHashedEmail != null) {
15051513
Logger.warning(String.format(
15061514
"The existing hashed email on the user (%s) does not match the hashed email passed to selectPlacements (%s). " +
1507-
"Please make sure to sync the email identity to mParticle as soon as it's available. " +
1508-
"Identifying user with the provided email before continuing to selectPlacements.",
1515+
"Please make sure to sync the hashed email identity to mParticle as soon as it's available. " +
1516+
"Identifying user with the provided hashed email before continuing to selectPlacements.",
15091517
existingHashedEmail, hashedEmail
15101518
));
15111519
}
15121520

15131521
IdentityApiRequest.Builder identityBuilder = IdentityApiRequest.withUser(user);
1514-
if (email != null && !email.isEmpty() && !email.equalsIgnoreCase(existingEmail)) {
1522+
if (emailMismatch) {
15151523
identityBuilder.email(email);
15161524
}
1517-
if (hashedEmail != null && !hashedEmail.isEmpty() && !hashedEmail.equalsIgnoreCase(existingHashedEmail)) {
1525+
if (hashedEmailMismatch) {
15181526
identityBuilder.userIdentity(MParticle.IdentityType.Other, hashedEmail);
15191527
}
1528+
15201529
IdentityApiRequest identityRequest = identityBuilder.build();
15211530
MParticleTask<IdentityApiResult> task = identityApi.identify(identityRequest);
1522-
task.addFailureListener(new TaskFailureListener() {
1523-
@Override
1524-
public void onFailure(IdentityHttpResponse result) {
1525-
Logger.error("Failed to sync email from selectPlacement to user: " + result.getErrors().toString());
15261531

1527-
runnable.run();
1528-
}
1532+
task.addFailureListener(result -> {
1533+
Logger.error("Failed to sync email from selectPlacement to user: " + result.getErrors());
1534+
runnable.run();
15291535
});
1530-
task.addSuccessListener(new TaskSuccessListener() {
1531-
@Override
1532-
public void onSuccess(IdentityApiResult result) {
1533-
Logger.debug("Updated email identity based on selectPlacement's attributes: " + result.getUser().getUserIdentities().get(MParticle.IdentityType.Email));
1534-
runnable.run();
1535-
}
1536+
1537+
task.addSuccessListener(result -> {
1538+
Logger.debug("Updated email identity based on selectPlacement's attributes: " +
1539+
result.getUser().getUserIdentities().get(MParticle.IdentityType.Email));
1540+
runnable.run();
15361541
});
1542+
15371543
} else {
15381544
runnable.run();
15391545
}

0 commit comments

Comments
 (0)