Skip to content

Commit c643453

Browse files
brismithersjinliu9508
authored andcommitted
Merge pull request #1723 from OneSignal/user-model/tojsonobject
[User Model] Provide serialization mechanism for external classes
2 parents dae2b03 + c93d1d6 commit c643453

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/notifications/INotification.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ interface INotification {
126126
*/
127127
val ttl: Int
128128

129+
/**
130+
* When this notification is a summary notification, this will contain the list of
131+
* notifications it summarizes.
132+
*/
133+
val groupedNotifications: List<INotification>?
134+
129135
/**
130136
* Create a mutable copy of this notification. Typically used in [IRemoteNotificationReceivedHandler]
131137
* or [INotificationWillShowInForegroundHandler] to modify an incoming notification prior to it

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/InAppMessageClickResult.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ package com.onesignal.inAppMessages.internal
33
import com.onesignal.inAppMessages.IInAppMessage
44
import com.onesignal.inAppMessages.IInAppMessageAction
55
import com.onesignal.inAppMessages.IInAppMessageClickResult
6+
import org.json.JSONObject
67

7-
class InAppMessageClickResult(
8-
override val message: IInAppMessage,
8+
internal class InAppMessageClickResult(msg: InAppMessage, actn: InAppMessageAction) : IInAppMessageClickResult {
9+
override val message: IInAppMessage
10+
get() = _message
911

1012
override val action: IInAppMessageAction
11-
) : IInAppMessageClickResult
13+
get() = _action
14+
15+
private val _message: InAppMessage = msg
16+
private val _action: InAppMessageAction = actn
17+
18+
fun toJSONObject(): JSONObject {
19+
return JSONObject()
20+
.put("message", _message.toJSONObject())
21+
.put("action", _action.toJSONObject())
22+
}
23+
}

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/Notification.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ import org.json.JSONObject
2525
open class Notification : INotification {
2626
var notificationExtender: NotificationCompat.Extender? = null
2727

28-
/**
29-
* Summary notifications grouped
30-
* Notification payload will have the most recent notification received.
31-
*/
32-
var groupedNotifications: List<Notification>? = null
33-
28+
override var groupedNotifications: List<Notification>? = null
3429
override var androidNotificationId = 0
3530
override var notificationId: String? = null
3631
override var templateName: String? = null

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/NotificationAction.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626
*/
2727
package com.onesignal.notifications.internal
2828

29+
import com.onesignal.common.putSafe
2930
import com.onesignal.notifications.INotificationAction
31+
import org.json.JSONObject
3032

3133
internal class NotificationAction(
3234
override val type: INotificationAction.ActionType,
3335
override val actionId: String?
34-
) : INotificationAction
36+
) : INotificationAction {
37+
fun toJSONObject(): JSONObject {
38+
return JSONObject()
39+
.put("type", type)
40+
.putSafe("actionId", actionId)
41+
}
42+
}

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/NotificationClickResult.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ import com.onesignal.notifications.INotification
44
import com.onesignal.notifications.INotificationAction
55
import com.onesignal.notifications.INotificationClickHandler
66
import com.onesignal.notifications.INotificationClickResult
7+
import org.json.JSONObject
78

89
/**
910
* The data provided to [INotificationClickHandler.notificationClicked] when a notification
1011
* has been opened by the user.
1112
*/
12-
class NotificationClickResult(
13+
internal class NotificationClickResult(
14+
notif: Notification,
15+
actn: NotificationAction
16+
) : INotificationClickResult {
1317
/** The notification that was opened by the user. **/
14-
override val notification: INotification,
18+
override val notification: INotification
19+
get() = _notification
1520

1621
/** The action the user took to open the notification. **/
1722
override val action: INotificationAction
18-
) : INotificationClickResult
23+
get() = _action
24+
25+
private val _notification: Notification = notif
26+
private val _action: NotificationAction = actn
27+
28+
fun toJSONObject(): JSONObject {
29+
return JSONObject()
30+
.put("notification", _notification.toJSONObject())
31+
.put("action", _action.toJSONObject())
32+
}
33+
}

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/common/NotificationHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ object NotificationHelper {
203203
return ""
204204
}
205205

206-
fun generateNotificationOpenedResult(jsonArray: JSONArray, time: ITime): NotificationClickResult {
206+
internal fun generateNotificationOpenedResult(jsonArray: JSONArray, time: ITime): NotificationClickResult {
207207
val jsonArraySize = jsonArray.length()
208208
var firstMessage = true
209209
val androidNotificationId = jsonArray.optJSONObject(0)

0 commit comments

Comments
 (0)