Skip to content

Commit

Permalink
Merge pull request #108 from zoyi-jin/fix/isChannelPushNotification
Browse files Browse the repository at this point in the history
Fix toPushNotification
  • Loading branch information
zoyi-jin authored May 18, 2023
2 parents 3d0cf33 + 7ece47c commit 62ccb23
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions android/src/main/java/com/zoyi/channel/rn/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ public static Map<String, Object> toHashMap(ReadableMap readableMap) {
break;

case Number:
hashMap.put(key, Utils.getDouble(readableMap, key).getValue());
try {
int number = readableMap.getInt(key);
hashMap.put(key, number);
} catch (Exception e) {
double number = readableMap.getDouble(key);
hashMap.put(key, number);
}

break;

case String:
Expand Down Expand Up @@ -380,16 +387,40 @@ public static UserData toUserData(ReadableMap userDataMap) {
}

public static Map<String, String> toPushNotification(ReadableMap pushNotificationMap) {
Map<String, String> pushNotification = new HashMap<>();
HashMap<String, String> pushNotification = new HashMap<>();
ReadableMapKeySetIterator iterator = pushNotificationMap.keySetIterator();

while (iterator.hasNextKey()) {
String key = iterator.nextKey();
ReadableType type = pushNotificationMap.getType(key);
String value = pushNotificationMap.getString(key);

if (type == ReadableType.String && value != null) {
pushNotification.put(key, value);
switch (type) {
case Boolean:
boolean bool = pushNotificationMap.getBoolean(key);
pushNotification.put(key, Boolean.toString(bool));
break;

case Number:
try {
int number = pushNotificationMap.getInt(key);
pushNotification.put(key, Integer.toString(number));
} catch (Exception e) {
double number = pushNotificationMap.getDouble(key);
pushNotification.put(key, Double.toString(number));
}

break;

case String:
String str = pushNotificationMap.getString(key);

if (str != null) {
pushNotification.put(key, str);
}
break;

default:
break;
}
}

Expand Down

0 comments on commit 62ccb23

Please sign in to comment.