Skip to content

Commit

Permalink
Update observer to include null external id
Browse files Browse the repository at this point in the history
  • Loading branch information
jennantilla committed Feb 16, 2024
1 parent c383ccf commit b735e32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ public void onUserStateChange(UserChangedState state) {
private static JSONObject createUserIds(UserState user) {
JSONObject userIds = new JSONObject();
try {
if (!user.getExternalId().isEmpty()) {
userIds.put("externalId", user.getExternalId());
}
if (!user.getOnesignalId().isEmpty()) {
userIds.put("onesignalId", user.getOnesignalId());
}
String externalId = user.getExternalId();
String onesignalId = user.getOnesignalId();

userIds.put("externalId", externalId != null && !externalId.isEmpty() ? externalId : JSONObject.NULL);
userIds.put("onesignalId", onesignalId != null && !onesignalId.isEmpty() ? onesignalId : JSONObject.NULL);
} catch (JSONException e) {
e.printStackTrace();
e.printStackTrace();
}
return userIds;
}
Expand Down
10 changes: 8 additions & 2 deletions src/ios/OneSignalPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ - (void)onUserStateDidChangeWithState:(OSUserChangedState * _Nonnull)state {
NSMutableDictionary *result = [NSMutableDictionary new];

NSMutableDictionary *currentObject = [NSMutableDictionary new];
if (onesignalId.length > 0) {

if (onesignalId && ![onesignalId isEqualToString:@""]) {
currentObject[@"onesignalId"] = onesignalId;
} else {
currentObject[@"onesignalId"] = [NSNull null];
}
if (externalId.length > 0) {

if (externalId && ![externalId isEqualToString:@""]) {
currentObject[@"externalId"] = externalId;
} else {
currentObject[@"externalId"] = [NSNull null];
}

result[@"current"] = currentObject;
Expand Down

0 comments on commit b735e32

Please sign in to comment.