From dd3feaacdab0d1f1f3aeaace408eff72706c0846 Mon Sep 17 00:00:00 2001 From: emawby Date: Wed, 3 May 2023 13:40:29 -0700 Subject: [PATCH] adding toJSONObject for push subscription changed event parameters --- .../subscriptions/PushSubscriptionChangedState.kt | 11 ++++++++++- .../user/subscriptions/PushSubscriptionState.kt | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionChangedState.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionChangedState.kt index c9fa171635..669090d77a 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionChangedState.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionChangedState.kt @@ -1,6 +1,15 @@ package com.onesignal.user.subscriptions +import org.json.JSONObject + class PushSubscriptionChangedState( val previous: PushSubscriptionState, val current: PushSubscriptionState -) +) { + fun toJSONObject(): JSONObject { + return JSONObject() + .put("previous", previous.toJSONObject()) + .put("current", current.toJSONObject()) + } +} + diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionState.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionState.kt index 0fb5ae475c..5520b2432b 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionState.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/subscriptions/PushSubscriptionState.kt @@ -1,5 +1,7 @@ package com.onesignal.user.subscriptions +import org.json.JSONObject + /** * A subscription state. */ @@ -24,5 +26,14 @@ class PushSubscriptionState( * user will not receive notifications through this subscription (even when the user has * granted app permission). */ - val optedIn: Boolean -) + val optedIn: Boolean, +) { + fun toJSONObject(): JSONObject { + return JSONObject() + .put("id", id) + .put("token", token) + .put("optedIn", optedIn) + } +} + +