|
|
|
@ -6,7 +6,6 @@ package org.mozilla.fenix.shopping.middleware
|
|
|
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
import mozilla.components.browser.engine.gecko.shopping.GeckoProductAnalysis
|
|
|
|
|
import mozilla.components.browser.state.selector.selectedTab
|
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
|
import mozilla.components.concept.engine.shopping.ProductAnalysis
|
|
|
|
@ -24,7 +23,7 @@ interface ReviewQualityCheckService {
|
|
|
|
|
*
|
|
|
|
|
* @return [ProductAnalysis] if the request succeeds, null otherwise.
|
|
|
|
|
*/
|
|
|
|
|
suspend fun fetchProductReview(): GeckoProductAnalysis?
|
|
|
|
|
suspend fun fetchProductReview(): ProductAnalysis?
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Triggers a reanalysis of the product review for the current tab.
|
|
|
|
@ -57,16 +56,13 @@ class DefaultReviewQualityCheckService(
|
|
|
|
|
|
|
|
|
|
private val logger = Logger("DefaultReviewQualityCheckService")
|
|
|
|
|
|
|
|
|
|
override suspend fun fetchProductReview(): GeckoProductAnalysis? = withContext(Dispatchers.Main) {
|
|
|
|
|
override suspend fun fetchProductReview(): ProductAnalysis? = withContext(Dispatchers.Main) {
|
|
|
|
|
suspendCoroutine { continuation ->
|
|
|
|
|
browserStore.state.selectedTab?.let { tab ->
|
|
|
|
|
tab.engineState.engineSession?.requestProductAnalysis(
|
|
|
|
|
url = tab.content.url,
|
|
|
|
|
onResult = {
|
|
|
|
|
when (it) {
|
|
|
|
|
is GeckoProductAnalysis -> continuation.resume(it)
|
|
|
|
|
else -> continuation.resume(null)
|
|
|
|
|
}
|
|
|
|
|
continuation.resume(it)
|
|
|
|
|
},
|
|
|
|
|
onException = {
|
|
|
|
|
logger.error("Error fetching product review", it)
|
|
|
|
|