Skip to content

Commit

Permalink
feat: Fetch more trending posts, links, and hashtags (#634)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikclayton authored Apr 22, 2024
1 parent 7e335ed commit aa930f3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class NetworkTimelineRemoteMediator(
Timeline.Home -> api.homeTimeline(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.TrendingStatuses -> api.trendingStatuses()
Timeline.TrendingStatuses -> api.trendingStatuses(limit = LIMIT_TRENDING_STATUSES)
is Timeline.Hashtags -> {
val firstHashtag = timeline.tags.first()
val additionalHashtags = timeline.tags.subList(1, timeline.tags.size)
Expand Down Expand Up @@ -167,4 +167,13 @@ class NetworkTimelineRemoteMediator(
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ import javax.inject.Inject
class TrendingLinksRepository @Inject constructor(
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class TrendingTagsViewModel @Inject constructor(

val deferredFilters = async { mastodonApi.getFilters() }

mastodonApi.trendingTags().fold(
mastodonApi.trendingTags(limit = LIMIT_TRENDING_HASHTAGS).fold(
{ tagResponse ->

val firstTag = tagResponse.firstOrNull()
Expand Down Expand Up @@ -129,4 +129,13 @@ class TrendingTagsViewModel @Inject constructor(

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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,17 @@ interface MastodonApi {
suspend fun unfollowTag(@Path("name") name: String): NetworkResult<HashTag>

@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")
suspend fun trendingLinks(): NetworkResult<List<TrendsLink>>
suspend fun trendingLinks(
@Query("limit") limit: Int? = null,
): NetworkResult<List<TrendsLink>>

@GET("api/v1/trends/statuses")
suspend fun trendingStatuses(): Response<List<Status>>
suspend fun trendingStatuses(
@Query("limit") limit: Int? = null,
): Response<List<Status>>
}

0 comments on commit aa930f3

Please sign in to comment.