feat: Fetch more trending posts, links, and hashtags (#634)

The previous code didn't set a limit for the number of posts, links, and
hashtags to fetch on the trending pages, so used the conservative
defaults.

Increase these to the API maximums to show the user more information.
This commit is contained in:
Nik Clayton 2024-04-22 21:34:22 +02:00 committed by GitHub
parent 7e335ed51c
commit aa930f3a6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 6 deletions

View File

@ -125,7 +125,7 @@ class NetworkTimelineRemoteMediator(
Timeline.Home -> api.homeTimeline(maxId = maxId, minId = minId, limit = loadSize) Timeline.Home -> api.homeTimeline(maxId = maxId, minId = minId, limit = loadSize)
Timeline.PublicFederated -> api.publicTimeline(local = false, maxId = maxId, minId = minId, limit = loadSize) Timeline.PublicFederated -> api.publicTimeline(local = false, maxId = maxId, minId = minId, limit = loadSize)
Timeline.PublicLocal -> api.publicTimeline(local = true, maxId = maxId, minId = minId, limit = loadSize) Timeline.PublicLocal -> api.publicTimeline(local = true, maxId = maxId, minId = minId, limit = loadSize)
Timeline.TrendingStatuses -> api.trendingStatuses() Timeline.TrendingStatuses -> api.trendingStatuses(limit = LIMIT_TRENDING_STATUSES)
is Timeline.Hashtags -> { is Timeline.Hashtags -> {
val firstHashtag = timeline.tags.first() val firstHashtag = timeline.tags.first()
val additionalHashtags = timeline.tags.subList(1, timeline.tags.size) val additionalHashtags = timeline.tags.subList(1, timeline.tags.size)
@ -167,4 +167,13 @@ class NetworkTimelineRemoteMediator(
else -> throw IllegalStateException("NetworkTimelineRemoteMediator does not support $timeline") else -> throw IllegalStateException("NetworkTimelineRemoteMediator does not support $timeline")
} }
} }
companion object {
/**
* How many trending statuses to fetch. These are not paged, so fetch the
* documented (https://docs.joinmastodon.org/methods/trends/#query-parameters-1)
* maximum.
*/
const val LIMIT_TRENDING_STATUSES = 40
}
} }

View File

@ -23,5 +23,14 @@ import javax.inject.Inject
class TrendingLinksRepository @Inject constructor( class TrendingLinksRepository @Inject constructor(
private val api: MastodonApi, private val api: MastodonApi,
) { ) {
suspend fun getTrendingLinks() = api.trendingLinks() suspend fun getTrendingLinks() = api.trendingLinks(limit = LIMIT_TRENDING_LINKS)
companion object {
/**
* How many trending links to fetch. These are not paged, so fetch the
* documented (https://docs.joinmastodon.org/methods/trends/#query-parameters-2)
* maximum.
*/
const val LIMIT_TRENDING_LINKS = 20
}
} }

View File

@ -88,7 +88,7 @@ class TrendingTagsViewModel @Inject constructor(
val deferredFilters = async { mastodonApi.getFilters() } val deferredFilters = async { mastodonApi.getFilters() }
mastodonApi.trendingTags().fold( mastodonApi.trendingTags(limit = LIMIT_TRENDING_HASHTAGS).fold(
{ tagResponse -> { tagResponse ->
val firstTag = tagResponse.firstOrNull() val firstTag = tagResponse.firstOrNull()
@ -129,4 +129,13 @@ class TrendingTagsViewModel @Inject constructor(
return map { TrendingViewData.Tag.from(it, maxTrendingValue) } return map { TrendingViewData.Tag.from(it, maxTrendingValue) }
} }
companion object {
/**
* How many trending hashtags to fetch. These are not paged, so fetch the
* documented (https://docs.joinmastodon.org/methods/trends/#query-parameters)
* maximum.
*/
const val LIMIT_TRENDING_HASHTAGS = 20
}
} }

View File

@ -787,11 +787,17 @@ interface MastodonApi {
suspend fun unfollowTag(@Path("name") name: String): NetworkResult<HashTag> suspend fun unfollowTag(@Path("name") name: String): NetworkResult<HashTag>
@GET("api/v1/trends/tags") @GET("api/v1/trends/tags")
suspend fun trendingTags(): NetworkResult<List<TrendingTag>> suspend fun trendingTags(
@Query("limit") limit: Int? = null,
): NetworkResult<List<TrendingTag>>
@GET("api/v1/trends/links") @GET("api/v1/trends/links")
suspend fun trendingLinks(): NetworkResult<List<TrendsLink>> suspend fun trendingLinks(
@Query("limit") limit: Int? = null,
): NetworkResult<List<TrendsLink>>
@GET("api/v1/trends/statuses") @GET("api/v1/trends/statuses")
suspend fun trendingStatuses(): Response<List<Status>> suspend fun trendingStatuses(
@Query("limit") limit: Int? = null,
): Response<List<Status>>
} }