Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -72,8 +73,17 @@ constructor(
.combine(accountService.currentAccountIdFlow) { filterState, accountId ->
filterState
}
.collect { filterState ->
.combine(settingsProvider.settingsFlow) { filterState, settings ->
filterState to settings
}
.distinctUntilChanged { (oldState, oldSettings), (newState, newSettings) ->
oldState == newState &&
oldSettings.hideDuplicateArticles == newSettings.hideDuplicateArticles &&
oldSettings.flowSortUnreadArticles == newSettings.flowSortUnreadArticles
}
.collect { (filterState, settings) ->
val searchContent = filterState.searchContent
val hideDuplicates = settings.hideDuplicateArticles.value

mutablePagerFlow.value =
PagerData(
Expand All @@ -90,8 +100,9 @@ constructor(
isStarred = filterState.filter.isStarred(),
isUnread = filterState.filter.isUnread(),
sortAscending =
settingsProvider.settings.flowSortUnreadArticles
settings.flowSortUnreadArticles
.value,
hideDuplicates = hideDuplicates,
)
} else {
rssService
Expand All @@ -102,8 +113,9 @@ constructor(
isStarred = filterState.filter.isStarred(),
isUnread = filterState.filter.isUnread(),
sortAscending =
settingsProvider.settings.flowSortUnreadArticles
settings.flowSortUnreadArticles
.value,
hideDuplicates = hideDuplicates,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
Expand Down Expand Up @@ -50,12 +51,18 @@ class GroupWithFeedsListUseCase @Inject constructor(
filterStateUseCase.filterStateFlow.map { it.filter }
.combine(accountFlow) { filter, account ->
filter
}.combine(
settingsProvider.settingsFlow
.map { it.hideDuplicateArticles.value }
.distinctUntilChanged()
) { filter, hideDuplicates ->
filter to hideDuplicates
}.collectLatest {
currentJob?.cancel()
currentJob = when (it) {
Filter.Unread -> pullUnreadFeeds()
currentJob = when (it.first) {
Filter.Unread -> pullUnreadFeeds(it.second)
Filter.Starred -> pullStarredFeeds()
else -> pullAllFeeds()
else -> pullAllFeeds(it.second)
}
}
}
Expand All @@ -72,9 +79,9 @@ class GroupWithFeedsListUseCase @Inject constructor(
private val hideEmptyGroups get() = settingsProvider.settings.hideEmptyGroups.value

@OptIn(ExperimentalCoroutinesApi::class)
private fun pullAllFeeds(): Job {
private fun pullAllFeeds(hideDuplicates: Boolean): Job {
val articleCountMapFlow =
rssService.get().pullImportant(isStarred = false, isUnread = false)
rssService.get().pullImportant(isStarred = false, isUnread = false, hideDuplicates = hideDuplicates)

return applicationScope.launch {
feedsFlow.combine(articleCountMapFlow) { groupWithFeedsList, articleCountMap ->
Expand Down Expand Up @@ -128,8 +135,9 @@ class GroupWithFeedsListUseCase @Inject constructor(
}

@OptIn(FlowPreview::class)
private fun pullUnreadFeeds(): Job {
val unreadCountMapFlow = rssService.get().pullImportant(isStarred = false, isUnread = true)
private fun pullUnreadFeeds(hideDuplicates: Boolean): Job {
val unreadCountMapFlow =
rssService.get().pullImportant(isStarred = false, isUnread = true, hideDuplicates = hideDuplicates)
return applicationScope.launch {
combine(
feedsFlow, unreadCountMapFlow, diffMapHolder.diffMapSnapshotFlow
Expand Down
Loading
Loading