Unauthenticated: Use GET when subs <= 100

This commit is contained in:
Bnyro 2023-02-05 11:05:03 +01:00
parent 1f2be76559
commit 67a951f39e
2 changed files with 28 additions and 2 deletions

View File

@ -108,6 +108,11 @@ interface PipedApi {
@GET("feed")
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>
@GET("feed/unauthenticated")
suspend fun getUnauthenticatedFeed(
@Query("channels") channels: String
): List<StreamItem>
@POST("feed/unauthenticated")
suspend fun getUnauthenticatedFeed(
@Body channels: List<String>
@ -122,6 +127,11 @@ interface PipedApi {
@GET("subscriptions")
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
@GET("subscriptions/unauthenticated")
suspend fun unauthenticatedSubscriptions(
@Query("channels") channels: String
): List<Subscription>
@POST("subscriptions/unauthenticated")
suspend fun unauthenticatedSubscriptions(
@Body channels: List<String>

View File

@ -17,6 +17,8 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
object SubscriptionHelper {
private const val GET_SUBSCRIPTIONS_LIMIT = 100
suspend fun subscribe(channelId: String) {
val token = PreferenceHelper.getToken()
if (token.isNotEmpty()) {
@ -108,7 +110,14 @@ object SubscriptionHelper {
RetrofitInstance.authApi.subscriptions(token)
} else {
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
RetrofitInstance.authApi.unauthenticatedSubscriptions(subscriptions)
when {
subscriptions.size > GET_SUBSCRIPTIONS_LIMIT -> RetrofitInstance.authApi.unauthenticatedSubscriptions(
subscriptions
)
else -> RetrofitInstance.authApi.unauthenticatedSubscriptions(
subscriptions.joinToString(",")
)
}
}
}
@ -118,7 +127,14 @@ object SubscriptionHelper {
RetrofitInstance.authApi.getFeed(token)
} else {
val subscriptions = Database.localSubscriptionDao().getAll().map { it.channelId }
RetrofitInstance.authApi.getUnauthenticatedFeed(subscriptions)
when {
subscriptions.size > GET_SUBSCRIPTIONS_LIMIT -> RetrofitInstance.authApi.getUnauthenticatedFeed(
subscriptions
)
else -> RetrofitInstance.authApi.getUnauthenticatedFeed(
subscriptions.joinToString(",")
)
}
}
}
}