1
1
package com.onesignal.user.internal.operations.impl.executors
2
2
3
3
import com.onesignal.common.NetworkUtils
4
+ import com.onesignal.common.consistency.IamFetchReadyCondition
5
+ import com.onesignal.common.consistency.enums.IamFetchRywTokenKey
6
+ import com.onesignal.common.consistency.models.IConsistencyManager
4
7
import com.onesignal.common.exceptions.BackendException
5
8
import com.onesignal.common.modeling.ModelChangeTags
6
9
import com.onesignal.core.internal.operations.ExecutionResponse
@@ -31,12 +34,13 @@ internal class UpdateUserOperationExecutor(
31
34
private val _propertiesModelStore : PropertiesModelStore ,
32
35
private val _buildUserService : IRebuildUserService ,
33
36
private val _newRecordState : NewRecordsState ,
37
+ private val _consistencyManager : IConsistencyManager ,
34
38
) : IOperationExecutor {
35
39
override val operations: List <String >
36
40
get() = listOf (SET_TAG , DELETE_TAG , SET_PROPERTY , TRACK_SESSION_START , TRACK_SESSION_END , TRACK_PURCHASE )
37
41
38
- override suspend fun execute (ops : List <Operation >): ExecutionResponse {
39
- Logging .log(LogLevel .DEBUG , " UpdateUserOperationExecutor(operation: $ops )" )
42
+ override suspend fun execute (operations : List <Operation >): ExecutionResponse {
43
+ Logging .log(LogLevel .DEBUG , " UpdateUserOperationExecutor(operation: $operations )" )
40
44
41
45
var appId: String? = null
42
46
var onesignalId: String? = null
@@ -45,7 +49,7 @@ internal class UpdateUserOperationExecutor(
45
49
var deltasObject = PropertiesDeltasObject ()
46
50
var refreshDeviceMetadata = false
47
51
48
- for (operation in ops ) {
52
+ for (operation in operations ) {
49
53
when (operation) {
50
54
is SetTagOperation -> {
51
55
if (appId == null ) {
@@ -83,7 +87,8 @@ internal class UpdateUserOperationExecutor(
83
87
// that exist in this group.
84
88
val sessionCount = if (deltasObject.sessionCount != null ) deltasObject.sessionCount!! + 1 else 1
85
89
86
- deltasObject = PropertiesDeltasObject (deltasObject.sessionTime, sessionCount, deltasObject.amountSpent, deltasObject.purchases)
90
+ deltasObject =
91
+ PropertiesDeltasObject (deltasObject.sessionTime, sessionCount, deltasObject.amountSpent, deltasObject.purchases)
87
92
refreshDeviceMetadata = true
88
93
}
89
94
is TrackSessionEndOperation -> {
@@ -94,9 +99,15 @@ internal class UpdateUserOperationExecutor(
94
99
95
100
// The session time we pass up is the total session time across all `TrackSessionEndOperation`
96
101
// operations that exist in this group.
97
- val sessionTime = if (deltasObject.sessionTime != null ) deltasObject.sessionTime!! + operation.sessionTime else operation.sessionTime
102
+ val sessionTime =
103
+ if (deltasObject.sessionTime != null ) {
104
+ deltasObject.sessionTime!! + operation.sessionTime
105
+ } else {
106
+ operation.sessionTime
107
+ }
98
108
99
- deltasObject = PropertiesDeltasObject (sessionTime, deltasObject.sessionCount, deltasObject.amountSpent, deltasObject.purchases)
109
+ deltasObject =
110
+ PropertiesDeltasObject (sessionTime, deltasObject.sessionCount, deltasObject.amountSpent, deltasObject.purchases)
100
111
}
101
112
is TrackPurchaseOperation -> {
102
113
if (appId == null ) {
@@ -107,7 +118,12 @@ internal class UpdateUserOperationExecutor(
107
118
// The amount spent we pass up is the total amount spent across all `TrackPurchaseOperation`
108
119
// operations that exist in this group, while the purchases is the union of all
109
120
// `TrackPurchaseOperation` operations that exist in this group.
110
- val amountSpent = if (deltasObject.amountSpent != null ) deltasObject.amountSpent!! + operation.amountSpent else operation.amountSpent
121
+ val amountSpent =
122
+ if (deltasObject.amountSpent != null ) {
123
+ deltasObject.amountSpent!! + operation.amountSpent
124
+ } else {
125
+ operation.amountSpent
126
+ }
111
127
val purchasesArray = if (deltasObject.purchases != null ) deltasObject.purchases!! .toMutableList() else mutableListOf ()
112
128
113
129
for (purchase in operation.purchases) {
@@ -122,18 +138,25 @@ internal class UpdateUserOperationExecutor(
122
138
123
139
if (appId != null && onesignalId != null ) {
124
140
try {
125
- _userBackend .updateUser(
126
- appId,
127
- IdentityConstants .ONESIGNAL_ID ,
128
- onesignalId,
129
- propertiesObject,
130
- refreshDeviceMetadata,
131
- deltasObject,
132
- )
141
+ val rywToken =
142
+ _userBackend .updateUser(
143
+ appId,
144
+ IdentityConstants .ONESIGNAL_ID ,
145
+ onesignalId,
146
+ propertiesObject,
147
+ refreshDeviceMetadata,
148
+ deltasObject,
149
+ )
150
+
151
+ if (rywToken != null ) {
152
+ _consistencyManager .setRywToken(onesignalId, IamFetchRywTokenKey .USER , rywToken)
153
+ } else {
154
+ _consistencyManager .resolveConditionsWithID(IamFetchReadyCondition .ID )
155
+ }
133
156
134
157
if (_identityModelStore .model.onesignalId == onesignalId) {
135
158
// go through and make sure any properties are in the correct model state
136
- for (operation in ops ) {
159
+ for (operation in operations ) {
137
160
when (operation) {
138
161
is SetTagOperation ->
139
162
_propertiesModelStore .model.tags.setStringProperty(
0 commit comments