Skip to content

Commit 2e04cd1

Browse files
authored
Merge pull request #1840 from OneSignal/user_model/fix_notifications_replacing_each_other
[5.0.0] Fix new notifications were replacing old ones
2 parents cbfaeb9 + 669fa51 commit 2e04cd1

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ import org.json.JSONObject
77
import java.security.SecureRandom
88

99
class NotificationGenerationJob(
10-
private var _notification: Notification,
10+
inNotification: Notification,
1111
var jsonPayload: JSONObject,
1212
) {
13-
var notification: Notification
14-
get() = _notification
15-
private set(value) {
16-
// If there is no android ID on the notification coming in, create one either
17-
// copying from the previous one or generating a new one.
18-
if (value != null && !value!!.hasNotificationId()) {
19-
val curNotification = _notification
20-
if (curNotification != null && curNotification.hasNotificationId()) {
21-
value.androidNotificationId = curNotification.androidNotificationId
22-
} else {
23-
value.androidNotificationId = SecureRandom().nextInt()
24-
}
25-
}
13+
val notification: Notification = inNotification.setAndroidNotificationId()
2614

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

3022
var isRestoring = false
3123
var isNotificationToDisplay = false

0 commit comments

Comments
 (0)