From b735e325fb84f1f6a435dca8b606339c4a9fe3d8 Mon Sep 17 00:00:00 2001 From: Jenna Antilla <46546946+jennantilla@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:26:43 -0800 Subject: [PATCH] Update observer to include null external id --- .../cordova/OneSignalObserverController.java | 13 ++++++------- src/ios/OneSignalPush.m | 10 ++++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/android/com/onesignal/cordova/OneSignalObserverController.java b/src/android/com/onesignal/cordova/OneSignalObserverController.java index 59b9108a..57ab7d53 100644 --- a/src/android/com/onesignal/cordova/OneSignalObserverController.java +++ b/src/android/com/onesignal/cordova/OneSignalObserverController.java @@ -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; } diff --git a/src/ios/OneSignalPush.m b/src/ios/OneSignalPush.m index f6ec7271..5805c1d6 100644 --- a/src/ios/OneSignalPush.m +++ b/src/ios/OneSignalPush.m @@ -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;