[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/22499: Emit search group disband action on history group removal

This is needed to prevent removed search groups from coming back after
user interacts with the tab. E.g. if we don't fire this action, upon
interaction with the tab after a corresponding search group was removed
we will end up creating metadat with the deleted 'searchTerms' (they'll
be read from the 'historyMetadata' state on the tab).

At this point we probably want to start encapsulating all of this in a
use case - let's do that separately in
https://github.com/mozilla-mobile/android-components/issues/11309, and
just fix the bug for now.
pull/600/head
Grisha Kruglov 3 years ago committed by mergify[bot]
parent a3e898306a
commit ca22bb6ceb

@ -108,7 +108,7 @@ class DefaultPagedHistoryProvider(
/**
* Removes [group] and any corresponding history visits.
*/
suspend fun deleteHistoryGroup(group: History.Group) {
suspend fun deleteMetadataSearchGroup(group: History.Group) {
for (historyMetadata in group.items) {
getMatchingHistory(historyMetadata)?.let {
historyStorage.deleteVisit(

@ -22,6 +22,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.HistoryMetadataAction
import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.prompt.ShareData
@ -357,7 +358,13 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
when (item) {
is History.Regular -> core.historyStorage.deleteVisit(item.url, item.visitedAt)
is History.Group -> historyProvider.deleteHistoryGroup(item)
is History.Group -> {
// NB: If we have non-search groups, this logic needs to be updated.
historyProvider.deleteMetadataSearchGroup(item)
core.store.dispatch(
HistoryMetadataAction.DisbandSearchGroupAction(searchTerm = item.title)
)
}
// We won't encounter individual metadata entries outside of groups.
is History.Metadata -> {}
}

Loading…
Cancel
Save