feat(login): added custom stoat instance URL field to LoginScreen
overrides the `STOAT_WEB_APP`, `STOAT_BASE` and `STOAT_WEBSOCKET` globals to use the user-provided URL
This commit is contained in:
parent
4ba9b59127
commit
a66d3e6040
|
|
@ -56,20 +56,35 @@ import chat.stoat.core.model.schemas.Channel as ChannelSchema
|
|||
|
||||
private const val USE_ALPHA_API = false
|
||||
|
||||
val STOAT_BASE =
|
||||
val STOAT_BASE_DEFAULT =
|
||||
if (USE_ALPHA_API) "https://alpha.revolt.chat/api" else "https://api.stoat.chat/0.8"
|
||||
|
||||
var STOAT_BASE = STOAT_BASE_DEFAULT
|
||||
|
||||
const val STOAT_SUPPORT = "https://support.stoat.chat"
|
||||
const val STOAT_MARKETING = "https://stoat.chat"
|
||||
val STOAT_FILES =
|
||||
if (USE_ALPHA_API) "https://alpha.revolt.chat/autumn" else "https://cdn.stoatusercontent.com"
|
||||
val STOAT_PROXY =
|
||||
if (USE_ALPHA_API) "https://alpha.revolt.chat/january" else "https://proxy.stoatusercontent.com"
|
||||
const val STOAT_WEB_APP = "https://stoat.chat"
|
||||
const val STOAT_WEB_APP_DEFAULT = "https://stoat.chat"
|
||||
var STOAT_WEB_APP = "https://stoat.chat"
|
||||
|
||||
|
||||
|
||||
const val STOAT_INVITES = "https://stt.gg"
|
||||
val STOAT_WEBSOCKET =
|
||||
val STOAT_WEBSOCKET_DEFAULT =
|
||||
if (USE_ALPHA_API) "wss://alpha.revolt.chat/ws" else "wss://events.stoat.chat"
|
||||
var STOAT_WEBSOCKET = STOAT_WEBSOCKET_DEFAULT
|
||||
const val STOAT_KJBOOK = "https://stoatchat.github.io/for-android"
|
||||
|
||||
fun updateStoatWebApp(webApp: String = STOAT_WEB_APP_DEFAULT) {
|
||||
STOAT_WEB_APP = webApp;
|
||||
STOAT_BASE = "$webApp/api"; // FIXME this wont work with default stoatchat instance
|
||||
var wssRoot = webApp.replace("https:", "wss:").replace("http:", "ws:");
|
||||
STOAT_WEBSOCKET = "$wssRoot/ws"; // FIXME this wont work with default stoatchat instance
|
||||
}
|
||||
|
||||
fun String.api(): String {
|
||||
return "$STOAT_BASE$this"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,10 +50,12 @@ import androidx.navigation.NavController
|
|||
import chat.stoat.R
|
||||
import chat.stoat.StoatApplication
|
||||
import chat.stoat.api.STOAT_WEB_APP
|
||||
import chat.stoat.api.STOAT_WEB_APP_DEFAULT
|
||||
import chat.stoat.api.StoatAPI
|
||||
import chat.stoat.api.routes.account.EmailPasswordAssessment
|
||||
import chat.stoat.api.routes.account.negotiateAuthentication
|
||||
import chat.stoat.api.routes.onboard.needsOnboarding
|
||||
import chat.stoat.api.updateStoatWebApp
|
||||
import chat.stoat.composables.generic.FormTextField
|
||||
import chat.stoat.composables.generic.Weblink
|
||||
import chat.stoat.persistence.KVStorage
|
||||
|
|
@ -74,6 +76,10 @@ class LoginViewModel @Inject constructor(
|
|||
val password: String
|
||||
get() = _password
|
||||
|
||||
private var _stoatInstanceUrl by mutableStateOf(STOAT_WEB_APP)
|
||||
val stoatInstanceUrl: String
|
||||
get() = _stoatInstanceUrl
|
||||
|
||||
private var _error by mutableStateOf<String?>(null)
|
||||
val error: String?
|
||||
get() = _error
|
||||
|
|
@ -120,8 +126,7 @@ class LoginViewModel @Inject constructor(
|
|||
kvStorage.set("sessionId", id)
|
||||
|
||||
val onboard = needsOnboarding(token)
|
||||
if (onboard) {
|
||||
_navigateTo = "onboarding"
|
||||
if (onboard) { _navigateTo = "onboarding"
|
||||
return@launch
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +153,11 @@ class LoginViewModel @Inject constructor(
|
|||
fun setPassword(password: String) {
|
||||
_password = password
|
||||
}
|
||||
|
||||
fun setStoatInstanceUrl(url: String = STOAT_WEB_APP) {
|
||||
_stoatInstanceUrl = url;
|
||||
updateStoatWebApp(url);
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
@ -222,6 +232,15 @@ fun LoginScreen(navController: NavController, viewModel: LoginViewModel = hiltVi
|
|||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
FormTextField(
|
||||
value = viewModel.stoatInstanceUrl,
|
||||
label = "Stoat instance", // FIXME hardcoded string
|
||||
type = KeyboardType.Uri,
|
||||
action = ImeAction.Next,
|
||||
onChange = viewModel::setStoatInstanceUrl,
|
||||
modifier = Modifier
|
||||
.padding(vertical = 25.dp)
|
||||
)
|
||||
FormTextField(
|
||||
value = viewModel.email,
|
||||
label = stringResource(R.string.email),
|
||||
|
|
|
|||
Loading…
Reference in New Issue