mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 14:48:45 +01:00
fix(profile): prevent seeing unlogged screen even if logged
This commit is contained in:
parent
ba6f573b20
commit
f8433211f5
@ -2,7 +2,11 @@ package com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository
|
||||
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.preferences.KeyStoreKeys
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.preferences.TemporaryKeyStore
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
internal class DefaultIdentityRepository(
|
||||
private val keyStore: TemporaryKeyStore,
|
||||
@ -10,9 +14,13 @@ internal class DefaultIdentityRepository(
|
||||
|
||||
override val authToken = MutableStateFlow<String?>(null)
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
override val isLogged: Flow<Boolean?> = authToken.debounce(100).map {
|
||||
it?.isNotEmpty()
|
||||
}
|
||||
|
||||
init {
|
||||
val previousToken = keyStore[KeyStoreKeys.AuthToken, ""]
|
||||
.takeIf { it.isNotEmpty() }
|
||||
val previousToken = keyStore[KeyStoreKeys.AuthToken, ""].takeIf { it.isNotEmpty() }
|
||||
authToken.value = previousToken
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface IdentityRepository {
|
||||
|
||||
val authToken: StateFlow<String?>
|
||||
val isLogged: Flow<Boolean?>
|
||||
|
||||
fun storeToken(value: String)
|
||||
|
||||
|
@ -8,7 +8,6 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.UserRepo
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.inbox.InboxCoordinator
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
@ -24,8 +23,8 @@ class InboxViewModel(
|
||||
override fun onStarted() {
|
||||
mvi.onStarted()
|
||||
mvi.scope?.launch {
|
||||
identityRepository.authToken.debounce(250).onEach { auth ->
|
||||
mvi.updateState { it.copy(isLogged = !auth.isNullOrEmpty()) }
|
||||
identityRepository.isLogged.onEach { logged ->
|
||||
mvi.updateState { it.copy(isLogged = logged) }
|
||||
}.launchIn(this)
|
||||
}
|
||||
}
|
||||
|
@ -94,13 +94,17 @@ internal object ProfileContentScreen : Tab {
|
||||
.padding(it),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
val screens = listOf(
|
||||
ProfileNotLoggedScreen,
|
||||
ProfileLoggedScreen,
|
||||
)
|
||||
// wait until logging status is determined
|
||||
if (uiState.logged != null) {
|
||||
TabNavigator(ProfileNotLoggedScreen) {
|
||||
val logged = uiState.logged
|
||||
if (logged != null) {
|
||||
val screens = remember {
|
||||
listOf(
|
||||
ProfileNotLoggedScreen,
|
||||
ProfileLoggedScreen,
|
||||
)
|
||||
}
|
||||
val root = if (logged) screens[1] else screens[0]
|
||||
TabNavigator(root) {
|
||||
CurrentScreen()
|
||||
val navigator = LocalTabNavigator.current
|
||||
LaunchedEffect(model) {
|
||||
|
@ -11,7 +11,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.preferences.KeyStoreKeys
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.preferences.TemporaryKeyStore
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
@ -30,8 +29,8 @@ class ProfileContentViewModel(
|
||||
mvi.onStarted()
|
||||
|
||||
mvi.scope?.launch {
|
||||
identityRepository.authToken.debounce(250).onEach { token ->
|
||||
mvi.updateState { it.copy(logged = !token.isNullOrEmpty()) }
|
||||
identityRepository.isLogged.onEach { logged ->
|
||||
mvi.updateState { it.copy(logged = logged) }
|
||||
}.launchIn(this)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.UserRepo
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
@ -26,8 +25,9 @@ class MainViewModel(
|
||||
|
||||
mvi.scope?.launch(Dispatchers.IO) {
|
||||
launch {
|
||||
identityRepository.authToken.debounce(250).onEach { auth ->
|
||||
val unreadCount = if (!auth.isNullOrEmpty()) {
|
||||
identityRepository.isLogged.onEach { logged ->
|
||||
val unreadCount = if (logged == true) {
|
||||
val auth = identityRepository.authToken.value
|
||||
val mentionCount =
|
||||
userRepository.getMentions(auth, page = 1, limit = 50).count()
|
||||
val replyCount =
|
||||
|
Loading…
x
Reference in New Issue
Block a user