Skip to content

Commit

Permalink
Merge pull request #607 from qonversion/offlineModeFix
Browse files Browse the repository at this point in the history
Fixed offline mode issue
  • Loading branch information
suriksarkisyan authored Jul 8, 2024
2 parents 510ace4 + a09b7ff commit ee6dfb4
Showing 1 changed file with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,29 +828,26 @@ internal class QProductCenterManager internal constructor(
}

@Synchronized
private fun executeEntitlementsBlock(error: QonversionError? = null) {
private fun executeEntitlementsBlock(actualError: QonversionError? = null) {
if (entitlementCallbacks.isEmpty()) {
return
}

val callbacks = entitlementCallbacks.toList()
entitlementCallbacks.clear()

error?.let {
callbacks.forEach { it.onError(error) }
} ?: run {
preparePermissionsResult(
{ permissions ->
callbacks.forEach {
it.onSuccess(permissions.toEntitlementsMap())
}
},
{ error ->
callbacks.forEach {
it.onError(error)
}
})
}
preparePermissionsResult(
{ permissions ->
callbacks.forEach {
it.onSuccess(permissions.toEntitlementsMap())
}
},
{ error ->
callbacks.forEach {
it.onError(error)
}
},
actualError)
}

private fun executeRestoreBlocksOnSuccess(entitlements: Map<String, QEntitlement>) {
Expand Down Expand Up @@ -896,7 +893,8 @@ internal class QProductCenterManager internal constructor(

private fun preparePermissionsResult(
onSuccess: (permissions: Map<String, QPermission>) -> Unit,
onError: (QonversionError) -> Unit
onError: (QonversionError) -> Unit,
error: QonversionError?
) {
fun actualizePermissions() {
retryLaunch(
Expand All @@ -913,11 +911,6 @@ internal class QProductCenterManager internal constructor(
})
}

if (launchError != null || unhandledLogoutAvailable) {
actualizePermissions()
return
}

val permissions = launchResultCache.getActualPermissions() ?: emptyMap()

val nowMs = System.currentTimeMillis()
Expand All @@ -926,9 +919,11 @@ internal class QProductCenterManager internal constructor(
it.value.isActive() && expirationTs < nowMs
}

if (permissionsAreActual) {
if ((error == null || error.shouldFireFallback) && permissionsAreActual) {
onSuccess(permissions)
} else {
} else if (error != null) {
onError(error)
} else if (launchError != null || unhandledLogoutAvailable) {
actualizePermissions()
}
}
Expand Down

0 comments on commit ee6dfb4

Please sign in to comment.