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