Check for empty trending response (#3853)

Fixes #3852
This commit is contained in:
Konrad Pozniak 2023-07-19 09:39:07 +02:00 committed by GitHub
parent 9a7e456edf
commit f3e0ee56df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 14 deletions

View File

@ -82,22 +82,26 @@ class TrendingViewModel @Inject constructor(
mastodonApi.trendingTags().fold( mastodonApi.trendingTags().fold(
{ tagResponse -> { tagResponse ->
val homeFilters = deferredFilters.await().getOrNull()?.filter { filter ->
filter.context.contains(Filter.Kind.HOME.kind) val firstTag = tagResponse.firstOrNull()
} _uiState.value = if (firstTag == null) {
val tags = tagResponse TrendingUiState(emptyList(), LoadingState.LOADED)
.filter { tag -> } else {
homeFilters?.none { filter -> val homeFilters = deferredFilters.await().getOrNull()?.filter { filter ->
filter.keywords.any { keyword -> keyword.keyword.equals(tag.name, ignoreCase = true) } filter.context.contains(Filter.Kind.HOME.kind)
} ?: false
} }
.sortedByDescending { tag -> tag.history.sumOf { it.uses.toLongOrNull() ?: 0 } } val tags = tagResponse
.toViewData() .filter { tag ->
homeFilters?.none { filter ->
filter.keywords.any { keyword -> keyword.keyword.equals(tag.name, ignoreCase = true) }
} ?: false
}
.sortedByDescending { tag -> tag.history.sumOf { it.uses.toLongOrNull() ?: 0 } }
.toViewData()
val firstTag = tagResponse.first() val header = TrendingViewData.Header(firstTag.start(), firstTag.end())
val header = TrendingViewData.Header(firstTag.start(), firstTag.end()) TrendingUiState(listOf(header) + tags, LoadingState.LOADED)
}
_uiState.value = TrendingUiState(listOf(header) + tags, LoadingState.LOADED)
}, },
{ error -> { error ->
Log.w(TAG, "failed loading trending tags", error) Log.w(TAG, "failed loading trending tags", error)