Skip to content

Commit

Permalink
Add Email Identity Type Support
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStalnaker authored Dec 2, 2020
1 parent 33ac755 commit c3de1cc
Showing 1 changed file with 147 additions and 86 deletions.
233 changes: 147 additions & 86 deletions mParticle-Appboy/MPKitAppboy.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@
static NSString *const eabOptions = @"options";
static NSString *const hostConfigKey = @"host";
static NSString *const userIdTypeKey = @"userIdentificationType";
static NSString *const emailIdTypeKey = @"emailIdentificationType";
static NSString *const enableTypeDetectionKey = @"enableTypeDetection";

// The possible values for userIdentificationType
static NSString *const userIdValueOther = @"Other";
static NSString *const userIdValueOther2 = @"Other2";
static NSString *const userIdValueOther3 = @"Other3";
static NSString *const userIdValueOther4 = @"Other4";
static NSString *const userIdValueOther5 = @"Other5";
static NSString *const userIdValueOther6 = @"Other6";
static NSString *const userIdValueOther7 = @"Other7";
static NSString *const userIdValueOther8 = @"Other8";
static NSString *const userIdValueOther9 = @"Other9";
static NSString *const userIdValueOther10 = @"Other10";
static NSString *const userIdValueCustomerId = @"CustomerId";
static NSString *const userIdValueFacebook = @"Facebook";
static NSString *const userIdValueTwitter = @"Twitter";
Expand All @@ -55,7 +65,6 @@ @interface MPKitAppboy() {
}

@property (nonatomic) NSString *host;
@property (nonatomic) MPUserIdentity userIdType;
@property (nonatomic) BOOL enableTypeDetection;

@end
Expand Down Expand Up @@ -243,7 +252,6 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
forwardScreenViews = NO;

_host = configuration[hostConfigKey];
_userIdType = [self userIdentityForString:configuration[userIdTypeKey]];
_enableTypeDetection = [configuration[enableTypeDetectionKey] boolValue];

//If Braze is already initialize, immediately "start" the kit, this
Expand Down Expand Up @@ -703,63 +711,89 @@ - (nonnull MPKitExecStatus *)updateUser:(FilteredMParticleUser *)user request:(F
NSMutableDictionary *userIDsCopy = [request.userIdentities copy];
NSString *userId;

switch (_userIdType) {
case MPUserIdentityOther:
if (_configuration[userIdTypeKey]) {
NSString *userIdKey = _configuration[userIdTypeKey];
if ([userIdKey isEqualToString:userIdValueOther]) {
if (userIDsCopy[@(MPUserIdentityOther)]) {
userId = userIDsCopy[@(MPUserIdentityOther)];
}
break;
case MPUserIdentityCustomerId:
if (userIDsCopy[@(MPUserIdentityCustomerId)]) {
userId = userIDsCopy[@(MPUserIdentityCustomerId)];
}
break;
case MPUserIdentityFacebook:
if (userIDsCopy[@(MPUserIdentityFacebook)]) {
userId = userIDsCopy[@(MPUserIdentityFacebook)];
}
break;
case MPUserIdentityTwitter:
if (userIDsCopy[@(MPUserIdentityTwitter)]) {
userId = userIDsCopy[@(MPUserIdentityTwitter)];
}
break;
case MPUserIdentityGoogle:
if (userIDsCopy[@(MPUserIdentityGoogle)]) {
userId = userIDsCopy[@(MPUserIdentityGoogle)];
}
break;
case MPUserIdentityMicrosoft:
if (userIDsCopy[@(MPUserIdentityMicrosoft)]) {
userId = userIDsCopy[@(MPUserIdentityMicrosoft)];
}
break;
case MPUserIdentityYahoo:
if (userIDsCopy[@(MPUserIdentityYahoo)]) {
userId = userIDsCopy[@(MPUserIdentityYahoo)];
}
break;
case MPUserIdentityEmail:
if (userIDsCopy[@(MPUserIdentityEmail)]) {
userId = userIDsCopy[@(MPUserIdentityEmail)];
}
break;
case MPUserIdentityAlias:
if (userIDsCopy[@(MPUserIdentityAlias)]) {
userId = userIDsCopy[@(MPUserIdentityAlias)];
}
break;
case MPUserIdentityOther4:
if (user != nil) {
userId = user.userId.stringValue;
}
break;

default:
if (userIDsCopy[@(MPUserIdentityCustomerId)]) {
userId = userIDsCopy[@(MPUserIdentityCustomerId)];
}
break;
} else if ([userIdKey isEqualToString:userIdValueOther2]) {
if (userIDsCopy[@(MPUserIdentityOther2)]) {
userId = userIDsCopy[@(MPUserIdentityOther2)];
}
} else if ([userIdKey isEqualToString:userIdValueOther3]) {
if (userIDsCopy[@(MPUserIdentityOther3)]) {
userId = userIDsCopy[@(MPUserIdentityOther3)];
}
} else if ([userIdKey isEqualToString:userIdValueOther4]) {
if (userIDsCopy[@(MPUserIdentityOther4)]) {
userId = userIDsCopy[@(MPUserIdentityOther4)];
}
} else if ([userIdKey isEqualToString:userIdValueOther5]) {
if (userIDsCopy[@(MPUserIdentityOther5)]) {
userId = userIDsCopy[@(MPUserIdentityOther5)];
}
} else if ([userIdKey isEqualToString:userIdValueOther6]) {
if (userIDsCopy[@(MPUserIdentityOther6)]) {
userId = userIDsCopy[@(MPUserIdentityOther6)];
}
} else if ([userIdKey isEqualToString:userIdValueOther7]) {
if (userIDsCopy[@(MPUserIdentityOther7)]) {
userId = userIDsCopy[@(MPUserIdentityOther7)];
}
} else if ([userIdKey isEqualToString:userIdValueOther8]) {
if (userIDsCopy[@(MPUserIdentityOther8)]) {
userId = userIDsCopy[@(MPUserIdentityOther8)];
}
} else if ([userIdKey isEqualToString:userIdValueOther9]) {
if (userIDsCopy[@(MPUserIdentityOther9)]) {
userId = userIDsCopy[@(MPUserIdentityOther9)];
}
} else if ([userIdKey isEqualToString:userIdValueOther10]) {
if (userIDsCopy[@(MPUserIdentityOther10)]) {
userId = userIDsCopy[@(MPUserIdentityOther10)];
}
} else if ([userIdKey isEqualToString:userIdValueCustomerId]) {
if (userIDsCopy[@(MPUserIdentityCustomerId)]) {
userId = userIDsCopy[@(MPUserIdentityCustomerId)];
}
} else if ([userIdKey isEqualToString:userIdValueFacebook]) {
if (userIDsCopy[@(MPUserIdentityFacebook)]) {
userId = userIDsCopy[@(MPUserIdentityFacebook)];
}
} else if ([userIdKey isEqualToString:userIdValueTwitter]) {
if (userIDsCopy[@(MPUserIdentityTwitter)]) {
userId = userIDsCopy[@(MPUserIdentityTwitter)];
}
} else if ([userIdKey isEqualToString:userIdValueGoogle]) {
if (userIDsCopy[@(MPUserIdentityGoogle)]) {
userId = userIDsCopy[@(MPUserIdentityGoogle)];
}
} else if ([userIdKey isEqualToString:userIdValueMicrosoft]) {
if (userIDsCopy[@(MPUserIdentityMicrosoft)]) {
userId = userIDsCopy[@(MPUserIdentityMicrosoft)];
}
} else if ([userIdKey isEqualToString:userIdValueYahoo]) {
if (userIDsCopy[@(MPUserIdentityYahoo)]) {
userId = userIDsCopy[@(MPUserIdentityYahoo)];
}
} else if ([userIdKey isEqualToString:userIdValueEmail]) {
if (userIDsCopy[@(MPUserIdentityEmail)]) {
userId = userIDsCopy[@(MPUserIdentityEmail)];
}
} else if ([userIdKey isEqualToString:userIdValueAlias]) {
if (userIDsCopy[@(MPUserIdentityAlias)]) {
userId = userIDsCopy[@(MPUserIdentityAlias)];
}
} else if ([userIdKey isEqualToString:userIdValueMPID]) {
if (user != nil) {
userId = user.userId.stringValue;
}
} else {
if (userIDsCopy[@(MPUserIdentityCustomerId)]) {
userId = userIDsCopy[@(MPUserIdentityCustomerId)];
}
}
}

if (userId) {
Expand All @@ -775,8 +809,63 @@ - (nonnull MPKitExecStatus *)updateUser:(FilteredMParticleUser *)user request:(F
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceAppboy) returnCode:MPKitReturnCodeSuccess];
}

if (userIDsCopy[@(MPUserIdentityEmail)]) {
appboyInstance.user.email = userIDsCopy[@(MPUserIdentityEmail)];
NSString *userEmail;

if (_configuration[emailIdTypeKey]) {
NSString *emailIdKey = _configuration[emailIdTypeKey];
if ([emailIdKey isEqualToString:userIdValueOther]) {
if (userIDsCopy[@(MPUserIdentityOther)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther2]) {
if (userIDsCopy[@(MPUserIdentityOther2)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther2)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther3]) {
if (userIDsCopy[@(MPUserIdentityOther3)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther3)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther4]) {
if (userIDsCopy[@(MPUserIdentityOther4)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther4)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther5]) {
if (userIDsCopy[@(MPUserIdentityOther5)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther5)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther6]) {
if (userIDsCopy[@(MPUserIdentityOther6)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther6)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther7]) {
if (userIDsCopy[@(MPUserIdentityOther7)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther7)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther8]) {
if (userIDsCopy[@(MPUserIdentityOther8)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther8)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther9]) {
if (userIDsCopy[@(MPUserIdentityOther9)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther9)];
}
} else if ([emailIdKey isEqualToString:userIdValueOther10]) {
if (userIDsCopy[@(MPUserIdentityOther10)]) {
userEmail = userIDsCopy[@(MPUserIdentityOther10)];
}
} else if ([emailIdKey isEqualToString:userIdValueEmail]) {
if (userIDsCopy[@(MPUserIdentityEmail)]) {
userEmail = userIDsCopy[@(MPUserIdentityEmail)];
}
} else {
if (userIDsCopy[@(MPUserIdentityEmail)]) {
userEmail = userIDsCopy[@(MPUserIdentityEmail)];
}
}
}

if (userEmail) {
appboyInstance.user.email = userEmail;
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceAppboy) returnCode:MPKitReturnCodeSuccess];
}
}
Expand All @@ -797,34 +886,6 @@ - (nonnull MPKitExecStatus *)userNotificationCenter:(nonnull UNUserNotificationC
}
#endif

- (MPUserIdentity)userIdentityForString:(nullable NSString *)userIdString {
if (userIdString != nil) {
if ([userIdString isEqualToString:userIdValueOther]) {
return MPUserIdentityOther;
} else if ([userIdString isEqualToString:userIdValueCustomerId]) {
return MPUserIdentityCustomerId;
} else if ([userIdString isEqualToString:userIdValueFacebook]) {
return MPUserIdentityFacebook;
} else if ([userIdString isEqualToString:userIdValueTwitter]) {
return MPUserIdentityTwitter;
} else if ([userIdString isEqualToString:userIdValueGoogle]) {
return MPUserIdentityGoogle;
} else if ([userIdString isEqualToString:userIdValueMicrosoft]) {
return MPUserIdentityMicrosoft;
} else if ([userIdString isEqualToString:userIdValueYahoo]) {
return MPUserIdentityYahoo;
} else if ([userIdString isEqualToString:userIdValueEmail]) {
return MPUserIdentityEmail;
} else if ([userIdString isEqualToString:userIdValueAlias]) {
return MPUserIdentityAlias;
} else if ([userIdString isEqualToString:userIdValueMPID]) {
return MPUserIdentityOther4;
}
}

return MPUserIdentityCustomerId;
}

- (NSMutableDictionary *)simplifiedDictionary:(NSDictionary *)originalDictionary {
__block NSMutableDictionary *transformedDictionary = [[NSMutableDictionary alloc] init];

Expand Down

0 comments on commit c3de1cc

Please sign in to comment.