-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1922 from OneSignal/update_between_sessions
Update push subscription model properties between sessions
- Loading branch information
Showing
8 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletion
28
...al/core/src/main/java/com/onesignal/user/internal/subscriptions/SubscriptionModelStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
package com.onesignal.user.internal.subscriptions | ||
|
||
import com.onesignal.common.modeling.ModelChangeTags | ||
import com.onesignal.common.modeling.SimpleModelStore | ||
import com.onesignal.core.internal.preferences.IPreferencesService | ||
|
||
open class SubscriptionModelStore(prefs: IPreferencesService) : SimpleModelStore<SubscriptionModel>({ | ||
SubscriptionModel() | ||
}, "subscriptions", prefs) | ||
}, "subscriptions", prefs) { | ||
override fun replaceAll( | ||
models: List<SubscriptionModel>, | ||
tag: String, | ||
) { | ||
if (tag != ModelChangeTags.HYDRATE) { | ||
return super.replaceAll(models, tag) | ||
} | ||
// When hydrating an existing push subscription model, use existing device properties | ||
synchronized(models) { | ||
for (model in models) { | ||
if (model.type == SubscriptionType.PUSH) { | ||
val existingPushModel = get(model.id) | ||
if (existingPushModel != null) { | ||
model.sdk = existingPushModel.sdk | ||
model.deviceOS = existingPushModel.deviceOS | ||
model.carrier = existingPushModel.carrier | ||
model.appVersion = existingPushModel.appVersion | ||
} | ||
break | ||
} | ||
} | ||
super.replaceAll(models, tag) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.