From 6793bc7a2fb350027f91f34f1ff4c25372eaa9c7 Mon Sep 17 00:00:00 2001 From: Kamo Spertsyan Date: Wed, 3 Apr 2024 10:36:19 +0300 Subject: [PATCH] Added user stability check for remote config list requests. (#573) --- .../sdk/internal/QRemoteConfigManager.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt index 9cd835f1..4d537b65 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt @@ -22,12 +22,27 @@ internal class QRemoteConfigManager @Inject constructor( var isInProgress: Boolean = false ) + internal class ListRequestData( + val callback: QonversionRemoteConfigListCallback, + val contextKeys: List? = null, + val includeEmptyContextKey: Boolean = false + ) + lateinit var userStateProvider: UserStateProvider private var loadingStates = mutableMapOf() + private val listRequests = mutableListOf() 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) { @@ -86,6 +101,11 @@ internal class QRemoteConfigManager @Inject constructor( return } + if (!userStateProvider.isUserStable) { + listRequests.add(ListRequestData(callback, contextKeys, includeEmptyContextKey)) + return + } + remoteConfigService.loadRemoteConfigs( contextKeys, includeEmptyContextKey, @@ -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)) }