Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using action buttons in Android #743

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.onesignal.inAppMessages.IInAppMessageWillDismissEvent;
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent;
import com.onesignal.notifications.INotification;
import com.onesignal.notifications.IActionButton;
import com.onesignal.notifications.INotificationWillDisplayEvent;
import com.onesignal.notifications.INotificationClickResult;
import com.onesignal.notifications.INotificationClickEvent;
Expand Down Expand Up @@ -73,12 +74,25 @@ static HashMap<String, Object> convertNotificationToMap(INotification notificati
if (notification.getAdditionalData() != null && notification.getAdditionalData().length() > 0)
hash.put("additionalData", convertJSONObjectToHashMap(notification.getAdditionalData()));
if (notification.getActionButtons() != null) {
hash.put("actionButtons", notification.getActionButtons());
hash.put("buttons", convertActionButtonsToMap
(notification.getActionButtons()));
}
hash.put("rawPayload", notification.getRawPayload());
return hash;
}

static List<HashMap<String, Object>> convertActionButtonsToMap(List<IActionButton> actionButtons) {
List<HashMap<String, Object>> convertedList = new ArrayList<HashMap<String, Object>>();
for (IActionButton actionButton : actionButtons) {
HashMap<String, Object> hash = new HashMap<>();
hash.put("id", actionButton.getId());
hash.put("text", actionButton.getText());
hash.put("icon", actionButton.getIcon());
convertedList.add(hash);
}
return convertedList;
}

static HashMap<String, Object> convertNotificationWillDisplayEventToMap(INotificationWillDisplayEvent event) throws JSONException {
HashMap<String, Object> hash = new HashMap<>();
hash.put("notification", convertNotificationToMap(event.getNotification()));
Expand Down