Skip to content

Commit

Permalink
Added user stability check for remote config list requests. (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpertsyanKM authored Apr 3, 2024
1 parent c32c8a4 commit 6793bc7
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,27 @@ internal class QRemoteConfigManager @Inject constructor(
var isInProgress: Boolean = false
)

internal class ListRequestData(
val callback: QonversionRemoteConfigListCallback,
val contextKeys: List<String>? = null,
val includeEmptyContextKey: Boolean = false
)

lateinit var userStateProvider: UserStateProvider
private var loadingStates = mutableMapOf<String?, LoadingState>()
private val listRequests = mutableListOf<ListRequestData>()

fun handlePendingRequests() {
loadingStates.filter { it.value.callbacks.isNotEmpty() }
.keys.forEach { contextKey -> loadRemoteConfig(contextKey, null) }

listRequests.forEach { requestData ->
requestData.contextKeys?.let {
loadRemoteConfigList(it, requestData.includeEmptyContextKey, requestData.callback)
} ?: run {
loadRemoteConfigList(requestData.callback)
}
}
}

fun userChangingRequestFailedWithError(error: QonversionError) {
Expand Down Expand Up @@ -86,6 +101,11 @@ internal class QRemoteConfigManager @Inject constructor(
return
}

if (!userStateProvider.isUserStable) {
listRequests.add(ListRequestData(callback, contextKeys, includeEmptyContextKey))
return
}

remoteConfigService.loadRemoteConfigs(
contextKeys,
includeEmptyContextKey,
Expand All @@ -94,6 +114,11 @@ internal class QRemoteConfigManager @Inject constructor(
}

fun loadRemoteConfigList(callback: QonversionRemoteConfigListCallback) {
if (!userStateProvider.isUserStable) {
listRequests.add(ListRequestData(callback))
return
}

remoteConfigService.loadRemoteConfigs(getRemoteConfigListCallbackWrapper(callback))
}

Expand Down

0 comments on commit 6793bc7

Please sign in to comment.