fix: Lemmy value cache refresh with no connection (#1120)

This commit is contained in:
Diego Beraldin 2024-07-12 17:27:36 +02:00 committed by GitHub
parent 2789408aa7
commit 573068cdbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,11 +1,11 @@
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.GetSiteResponse
import com.github.diegoberaldin.raccoonforlemmy.core.api.provider.ServiceProvider
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.utils.toAuthHeader
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
// TODO: add tests
internal class DefaultLemmyValueCache(
private val services: ServiceProvider,
) : LemmyValueCache {
@ -16,10 +16,12 @@ internal class DefaultLemmyValueCache(
override suspend fun refresh(auth: String?) {
val response =
services.site.get(
auth = auth,
authHeader = auth.toAuthHeader(),
)
runCatching {
services.site.get(
auth = auth,
authHeader = auth.toAuthHeader(),
)
}.getOrElse { GetSiteResponse() }
isDownVoteEnabled.update {
response.siteView?.localSite?.enableDownvotes == true
}