fix: Lemmy value cache refresh with no connection (#1120)
This commit is contained in:
parent
2789408aa7
commit
573068cdbb
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user