From 52df5cd2f47cc81cda296b70f28111fcf0001561 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Fri, 8 Apr 2022 16:11:20 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/24596 - Only restore Pocket categories selections once This fixes a regression from migrating from HomeStore to Appstore but indirectly by ensuring that previous categories selections are only restored once, not everytime user selects a new category and that change is persisted. --- .../mozilla/fenix/home/PocketUpdatesMiddleware.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/PocketUpdatesMiddleware.kt b/app/src/main/java/org/mozilla/fenix/home/PocketUpdatesMiddleware.kt index 5ab43fbf39..fb82ccdd80 100644 --- a/app/src/main/java/org/mozilla/fenix/home/PocketUpdatesMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/home/PocketUpdatesMiddleware.kt @@ -8,7 +8,7 @@ import androidx.annotation.VisibleForTesting import androidx.datastore.core.DataStore import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware @@ -155,18 +155,17 @@ internal fun restoreSelectedCategories( selectedPocketCategoriesDataStore: DataStore ) { coroutineScope.launch { - selectedPocketCategoriesDataStore.data.collect { persistedSelectedCategories -> - store.dispatch( - AppAction.PocketStoriesCategoriesSelectionsChange( - currentCategories, - persistedSelectedCategories.valuesList.map { + store.dispatch( + AppAction.PocketStoriesCategoriesSelectionsChange( + currentCategories, + selectedPocketCategoriesDataStore.data.first() + .valuesList.map { PocketRecommendedStoriesSelectedCategory( name = it.name, selectionTimestamp = it.selectionTimestamp ) } - ) ) - } + ) } }