[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/22083 - Match history groups to history pages by all items within the group

When deciding if we should include a history group within the "page of
history" results on the History View UI, we used to look at the most
recent timestamp of the metadata items within the group, and see if that
falls within the range of the timestamps of the history page, +/- some
buffer.

This assumes that each metadata entry will have a corresponding history
item. However, that's not true - when restarting the app, the selected
tab will be restored, and when opening History View right after we'll
record some metadata for it. However, we won't record a history visit
during the app restore for the selected tab.

That's all correct, but the assumption around group matching to history is now incorrect.

This patch changes the logic to instead look at every item within the
group, and see if any of them match the time window of the current
history page. This has a side-effect of also displaying search groups
multiple times on diffenent pages of history, if it makes sense to do so chronologically.
I think that's fine, it reflects reality at least (e.g. items within the
group may have been visited at very different points in time).

Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com>
pull/600/head
Grisha Kruglov 3 years ago committed by Grisha Kruglov
parent 1de688e7d7
commit ef375069eb

@ -155,8 +155,10 @@ class DefaultPagedHistoryProvider(
// items.
val historyGroupsInOffset = if (history.isNotEmpty()) {
historyGroups?.filter {
history.last().visitedAt <= it.visitedAt - visitedAtBuffer &&
it.visitedAt - visitedAtBuffer <= (history.first().visitedAt + visitedAtBuffer)
it.items.any { item ->
history.last().visitedAt <= item.visitedAt - visitedAtBuffer &&
item.visitedAt - visitedAtBuffer <= (history.first().visitedAt + visitedAtBuffer)
}
} ?: emptyList()
} else {
emptyList()

@ -59,7 +59,7 @@ class PagedHistoryProviderTest {
val historyEntry1 = HistoryMetadata(
key = historyMetadataKey1,
title = "mozilla",
createdAt = 5,
createdAt = 150000000, // a large amount to fall outside of the history page.
updatedAt = 10,
totalViewTime = 10,
documentType = DocumentType.Regular,

Loading…
Cancel
Save