fix: settings now respond to logging in/out
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
d33315b49f
commit
47730bcf87
|
|
@ -12,4 +12,8 @@ object GlobalState {
|
|||
fun hydrateWithSettings(settings: SyncedSettings) {
|
||||
settings.android.theme?.let { this.theme = Theme.valueOf(it) }
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
theme = getDefaultTheme()
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.navigation.NavController
|
||||
import chat.revolt.R
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.settings.GlobalState
|
||||
import chat.revolt.components.generic.PageHeader
|
||||
import chat.revolt.components.screens.home.LinkOnHome
|
||||
import chat.revolt.persistence.KVStorage
|
||||
|
|
@ -26,6 +27,7 @@ class HomeScreenViewModel @Inject constructor(
|
|||
fun logout() {
|
||||
runBlocking {
|
||||
kvStorage.remove("sessionToken")
|
||||
GlobalState.reset()
|
||||
RevoltAPI.logout()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ import chat.revolt.api.RevoltAPI
|
|||
import chat.revolt.api.routes.account.EmailPasswordAssessment
|
||||
import chat.revolt.api.routes.account.negotiateAuthentication
|
||||
import chat.revolt.api.routes.onboard.needsOnboarding
|
||||
import chat.revolt.api.settings.GlobalState
|
||||
import chat.revolt.api.settings.SyncedSettings
|
||||
import chat.revolt.components.generic.AnyLink
|
||||
import chat.revolt.components.generic.FormTextField
|
||||
import chat.revolt.components.generic.Weblink
|
||||
|
|
@ -70,6 +72,11 @@ class LoginViewModel @Inject constructor(
|
|||
val mfaResponse: EmailPasswordAssessment?
|
||||
get() = _mfaResponse
|
||||
|
||||
private suspend fun loadSettings() {
|
||||
SyncedSettings.fetch()
|
||||
GlobalState.hydrateWithSettings(SyncedSettings)
|
||||
}
|
||||
|
||||
fun doLogin() {
|
||||
_error = null
|
||||
|
||||
|
|
@ -99,7 +106,8 @@ class LoginViewModel @Inject constructor(
|
|||
_navigateTo = "onboarding"
|
||||
return@launch
|
||||
}
|
||||
|
||||
|
||||
loadSettings()
|
||||
RevoltAPI.loginAs(token)
|
||||
|
||||
_navigateTo = "home"
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import chat.revolt.api.routes.account.MfaResponseRecoveryCode
|
|||
import chat.revolt.api.routes.account.MfaResponseTotpCode
|
||||
import chat.revolt.api.routes.account.authenticateWithMfaRecoveryCode
|
||||
import chat.revolt.api.routes.account.authenticateWithMfaTotpCode
|
||||
import chat.revolt.api.settings.GlobalState
|
||||
import chat.revolt.api.settings.SyncedSettings
|
||||
import chat.revolt.components.generic.CollapsibleCard
|
||||
import chat.revolt.components.generic.FormTextField
|
||||
import chat.revolt.persistence.KVStorage
|
||||
|
|
@ -71,6 +73,11 @@ class MfaScreenViewModel @Inject constructor(
|
|||
_recoveryCode = code
|
||||
}
|
||||
|
||||
private suspend fun loadSettings() {
|
||||
SyncedSettings.fetch()
|
||||
GlobalState.hydrateWithSettings(SyncedSettings)
|
||||
}
|
||||
|
||||
fun tryAuthorizeTotp(mfaTicket: String) {
|
||||
_error = null
|
||||
viewModelScope.launch {
|
||||
|
|
@ -84,6 +91,7 @@ class MfaScreenViewModel @Inject constructor(
|
|||
)
|
||||
|
||||
try {
|
||||
loadSettings()
|
||||
RevoltAPI.loginAs(response.firstUserHints!!.token)
|
||||
kvStorage.set("sessionToken", response.firstUserHints.token)
|
||||
|
||||
|
|
@ -109,6 +117,7 @@ class MfaScreenViewModel @Inject constructor(
|
|||
)
|
||||
|
||||
try {
|
||||
loadSettings()
|
||||
RevoltAPI.loginAs(response.firstUserHints!!.token)
|
||||
kvStorage.set("sessionToken", response.firstUserHints.token)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue