Skip to content

Commit

Permalink
fixup! Update RywData usage so rywToken is non-null
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezp committed Oct 30, 2024
1 parent f6e4a90 commit ec5e3dd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.onesignal.user.internal.backend.impl
import com.onesignal.common.consistency.RywData
import com.onesignal.common.exceptions.BackendException
import com.onesignal.common.safeJSONObject
import com.onesignal.common.safeLong
import com.onesignal.common.safeString
import com.onesignal.common.toMap
import com.onesignal.core.internal.http.IHttpClient
import com.onesignal.user.internal.backend.ISubscriptionBackendService
Expand Down Expand Up @@ -34,10 +36,6 @@ internal class SubscriptionBackendService(
if (subscriptionJSON == null || !subscriptionJSON.has("id")) {
return null
}

fun JSONObject.safeString(key: String): String? = if (this.has(key)) this.getString(key) else null

fun JSONObject.safeLong(key: String): Long? = if (this.has(key)) this.getLong(key) else null
val rywToken = responseJSON.safeString("ryw_token")
val rywDelay = responseJSON.safeLong("ryw_delay")
var rywData: RywData? = null
Expand All @@ -64,10 +62,6 @@ internal class SubscriptionBackendService(
throw BackendException(response.statusCode, response.payload, response.retryAfterSeconds)
}

fun JSONObject.safeString(key: String): String? = if (this.has(key)) this.getString(key) else null

fun JSONObject.safeLong(key: String): Long? = if (this.has(key)) this.getLong(key) else null

val responseJSON = response.payload?.let { JSONObject(it) }

val rywToken = responseJSON?.safeString("ryw_token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.onesignal.user.internal.backend.impl
import com.onesignal.common.consistency.RywData
import com.onesignal.common.exceptions.BackendException
import com.onesignal.common.putMap
import com.onesignal.common.safeLong
import com.onesignal.common.safeString
import com.onesignal.core.internal.http.IHttpClient
import com.onesignal.user.internal.backend.CreateUserResponse
import com.onesignal.user.internal.backend.IUserBackendService
Expand Down Expand Up @@ -72,10 +74,6 @@ internal class UserBackendService(
throw BackendException(response.statusCode, response.payload, response.retryAfterSeconds)
}

fun JSONObject.safeString(key: String): String? = if (this.has(key)) this.getString(key) else null

fun JSONObject.safeLong(key: String): Long? = if (this.has(key)) this.getLong(key) else null

val responseJSON = response.payload?.let { JSONObject(it) }

val rywToken = responseJSON?.safeString("ryw_token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal class SubscriptionOperationExecutor(
val backendSubscriptionId = result.first
val rywData = result.second

if (rywData?.rywToken != null) {
if (rywData != null) {
_consistencyManager.setRywData(createOperation.onesignalId, IamFetchRywTokenKey.SUBSCRIPTION, rywData)
} else {
_consistencyManager.resolveConditionsWithID(IamFetchReadyCondition.ID)
Expand Down Expand Up @@ -190,7 +190,7 @@ internal class SubscriptionOperationExecutor(

val rywData = _subscriptionBackend.updateSubscription(lastOperation.appId, lastOperation.subscriptionId, subscription)

if (rywData?.rywToken != null) {
if (rywData != null) {
_consistencyManager.setRywData(startingOperation.onesignalId, IamFetchRywTokenKey.SUBSCRIPTION, rywData)
} else {
_consistencyManager.resolveConditionsWithID(IamFetchReadyCondition.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal class UpdateUserOperationExecutor(
deltasObject,
)

if (rywData?.rywToken != null) {
if (rywData != null) {
_consistencyManager.setRywData(onesignalId, IamFetchRywTokenKey.USER, rywData)
} else {
_consistencyManager.resolveConditionsWithID(IamFetchReadyCondition.ID)
Expand Down

0 comments on commit ec5e3dd

Please sign in to comment.