Skip to content

Commit

Permalink
Fix notification parsing
Browse files Browse the repository at this point in the history
* Fix OSNotification creation with additional data under Android
* Fix OSNotification creation with background image titleTextColor not being initialize correctly
* Fix OSNotification jsonRepresentation method
  • Loading branch information
Jeasmine committed Apr 22, 2021
1 parent 617c6dd commit c139643
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ static HashMap<String, Object> convertNotificationToMap(OSNotification notificat
if (notification.getCollapseId() != null)
hash.put("collapseId", notification.getCollapseId());
hash.put("priority", notification.getPriority());
if (notification.getAdditionalData() != null)
hash.put("additionalData", notification.getAdditionalData());

if (notification.getActionButtons() != null) {
if (notification.getAdditionalData() != null && notification.getAdditionalData().length() > 0)
hash.put("additionalData", convertJSONObjectToHashMap(notification.getAdditionalData()));
if (notification.getActionButtons() != null && !notification.getActionButtons().isEmpty()) {
ArrayList<HashMap> buttons = new ArrayList<>();

List<OSNotification.ActionButton> actionButtons = notification.getActionButtons();
Expand All @@ -168,7 +167,7 @@ static HashMap<String, Object> convertNotificationToMap(OSNotification notificat

hash.put("rawPayload", notification.getRawPayload());

Log.d("onesignal", "Created json raw payload: " + convertJSONObjectToHashMap(new JSONObject(notification.getRawPayload())).toString());
Log.d("onesignal", "Created json raw payload: " + hash.toString());

return hash;
}
Expand Down Expand Up @@ -235,7 +234,7 @@ private static HashMap<String, Object> convertAndroidBackgroundImageLayoutToMap(

hash.put("image", layout.getImage());
hash.put("bodyTextColor", layout.getBodyTextColor());
hash.put("titleTextColor", layout.getBodyTextColor());
hash.put("titleTextColor", layout.getTitleTextColor());

return hash;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class OSNotification extends JSONStringRepresentable {

//converts JSON map to OSNotification instance
OSNotification(Map<String, dynamic> json) {

// iOS Specific Parameters
if (json.containsKey('contentAvailable'))
this.contentAvailable = json['contentAvailable'] as bool?;
Expand Down Expand Up @@ -386,7 +385,7 @@ class OSNotificationReceivedEvent extends JSONStringRepresentable {

String jsonRepresentation() {
return convertToJsonString({
'notification': this.notification.jsonRepresentation
'notification': this.notification.jsonRepresentation()
});
}
}

0 comments on commit c139643

Please sign in to comment.