fix: loading circle (due to lost state)
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
6e008a2148
commit
8f3ac3741a
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
|||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Image
|
||||
|
|
@ -25,6 +26,7 @@ import androidx.navigation.NavController
|
|||
import chat.revolt.R
|
||||
import chat.revolt.activities.WebChallengeActivity
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.internals.WebChallenge
|
||||
import chat.revolt.api.settings.GlobalState
|
||||
import chat.revolt.api.settings.SyncedSettings
|
||||
|
|
@ -34,6 +36,7 @@ import chat.revolt.ui.theme.RevoltColorScheme
|
|||
import chat.revolt.ui.theme.Theme
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.ktor.client.request.get
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -76,6 +79,11 @@ class SplashScreenViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun canReachRevolt(): Boolean {
|
||||
val res = RevoltHttp.get("/")
|
||||
return res.status.value == 200
|
||||
}
|
||||
|
||||
fun checkLoggedInState() {
|
||||
Log.d("SplashScreenViewModel", "Checking logged in state")
|
||||
viewModelScope.launch {
|
||||
|
|
@ -92,9 +100,15 @@ class SplashScreenViewModel @Inject constructor(
|
|||
|
||||
val token = kvStorage.get("sessionToken") ?: return@launch setNavigateTo("login")
|
||||
|
||||
val canReachRevolt = canReachRevolt()
|
||||
val valid = RevoltAPI.checkSessionToken(token)
|
||||
|
||||
if (!valid) {
|
||||
if (canReachRevolt && !valid) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.token_invalid_toast),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
kvStorage.remove("sessionToken")
|
||||
setNavigateTo("login")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -212,6 +212,20 @@ fun ChatRouterScreen(topNav: NavController, viewModel: ChatRouterViewModel = hil
|
|||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(RevoltAPI.selfId) {
|
||||
snapshotFlow { RevoltAPI.selfId }
|
||||
.distinctUntilChanged()
|
||||
.collect { selfId ->
|
||||
if (selfId == null) {
|
||||
topNav.popBackStack(
|
||||
topNav.graph.startDestinationRoute!!,
|
||||
inclusive = true
|
||||
)
|
||||
topNav.navigate("splash")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModalBottomSheetLayout(
|
||||
sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
||||
sheetBackgroundColor = MaterialTheme.colorScheme.surface,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,15 @@
|
|||
<string name="password_forgot_heading">Forgot your password?</string>
|
||||
<string name="password_forgot_instructions">Enter your email and we\'ll send you instructions on how to reset your password.</string>
|
||||
|
||||
<string name="register_heading">Let\'s get you started</string>
|
||||
<string name="register_heading">Welcome to Revolt</string>
|
||||
<string name="register_instructions">It\'s like a place to hang out, get together, and talk about stuff. Best part, it\'s on the internet.</string>
|
||||
<string name="register_form_heading">Let\'s get you set up.</string>
|
||||
<string name="register_data">Your data is safe with us. We don\'t sell it, or use it to show you ads.</string>
|
||||
<string name="register_email">Email</string>
|
||||
<string name="register_email_verification_hint">We\'ll send you a verification email to confirm your account.</string>
|
||||
<string name="register_password">Password</string>
|
||||
<string name="register_password_rules">Eight or more, common ones are bad. Try messing around with a sentence.</string>
|
||||
|
||||
<string name="check_mail">Check your mail!</string>
|
||||
<string name="instructions_at_mail">We\'ve sent further instructions to %1$s.</string>
|
||||
<string name="verify_then_choose_username">Verify your email, and then we\'ll get on with choosing your username.</string>
|
||||
|
|
@ -41,6 +49,8 @@
|
|||
<string name="username_choose_others">Others will find, recognise and mention you with this name.</string>
|
||||
<string name="username_choose_changeable">But if you change your mind, you can change your username at any time in your User Settings.</string>
|
||||
|
||||
<string name="token_invalid_toast">You have been logged out. Please log in again.</string>
|
||||
|
||||
<string name="mfa_interstitial_header">One more thing</string>
|
||||
<string name="mfa_interstitial_lead">You\'ve got 2FA enabled to keep your account extra-safe.</string>
|
||||
<string name="mfa_type_otp">Use a one-time password</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue