Skip to content

Commit

Permalink
Merge pull request #1840 from OneSignal/user_model/fix_notifications_…
Browse files Browse the repository at this point in the history
…replacing_each_other

[5.0.0] Fix new notifications were replacing old ones
  • Loading branch information
emawby authored and jinliu9508 committed Jan 31, 2024
2 parents b7dccae + 8f7063f commit 7a11f23
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,17 @@ import org.json.JSONObject
import java.security.SecureRandom

class NotificationGenerationJob(
private var _notification: Notification,
inNotification: Notification,
var jsonPayload: JSONObject,
) {
var notification: Notification
get() = _notification
private set(value) {
// If there is no android ID on the notification coming in, create one either
// copying from the previous one or generating a new one.
if (value != null && !value!!.hasNotificationId()) {
val curNotification = _notification
if (curNotification != null && curNotification.hasNotificationId()) {
value.androidNotificationId = curNotification.androidNotificationId
} else {
value.androidNotificationId = SecureRandom().nextInt()
}
}
val notification: Notification = inNotification.setAndroidNotificationId()

_notification = value
private fun Notification.setAndroidNotificationId() = this.also {
// If there is no android ID on the notification coming in, generate a new one.
if (it != null && !it.hasNotificationId()) {
it.androidNotificationId = SecureRandom().nextInt()
}
}

var isRestoring = false
var isNotificationToDisplay = false
Expand Down

0 comments on commit 7a11f23

Please sign in to comment.