one more try to fix nosuchelement exception

This commit is contained in:
InsanusMokrassar 2022-05-18 15:33:26 +06:00
parent 6c094f3ad9
commit dd369177c1
11 changed files with 27 additions and 74 deletions

View File

@ -10,7 +10,6 @@ import dev.inmo.micro_utils.common.either
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.postssystem.features.auth.client.createAuthorizedFeaturesDIModule import dev.inmo.postssystem.features.auth.client.createAuthorizedFeaturesDIModule
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
import dev.inmo.postssystem.features.common.common.DBDropper import dev.inmo.postssystem.features.common.common.DBDropper
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
@ -85,7 +84,7 @@ data class DefaultAuthSettings(
currentModule ?.let { koin.loadModules(listOf(currentModule)) } currentModule ?.let { koin.loadModules(listOf(currentModule)) }
} }
return when { return when {
!serverAvailable -> ServerUnavailable !serverAvailable -> AuthUIError.ServerUnavailable
!authCorrect -> AuthIncorrect !authCorrect -> AuthIncorrect
else -> { else -> {
_authorizedDIModule.value = newModule _authorizedDIModule.value = newModule

View File

@ -1,12 +1,8 @@
package dev.inmo.postssystem.features.auth.client.ui package dev.inmo.postssystem.features.auth.client.ui
import dev.inmo.postssystem.features.common.common.ui.fsm.UIFSMState import dev.inmo.postssystem.features.common.common.ui.fsm.UIFSMState
import dev.inmo.postssystem.features.common.common.ui.fsm.UIFSMStateSerializer
import kotlinx.serialization.Serializable
@Serializable
data class AuthUIFSMState( data class AuthUIFSMState(
@Serializable(UIFSMStateSerializer::class)
override val from: UIFSMState?, override val from: UIFSMState?,
override val context: String = "main" override val context: String = "main"
) : UIFSMState ) : UIFSMState

View File

@ -3,21 +3,21 @@ package dev.inmo.postssystem.features.auth.client.ui
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
sealed class AuthUIError { sealed interface AuthUIError {
@Serializable @Serializable
object ServerUnavailable : AuthUIError() object ServerUnavailable : AuthUIError
@Serializable @Serializable
object AuthIncorrect : AuthUIError() object AuthIncorrect : AuthUIError
} }
@Serializable @Serializable
sealed class AuthUIState { sealed interface AuthUIState {
@Serializable @Serializable
data class Init(val showError: AuthUIError? = null) : AuthUIState() data class Init(val showError: AuthUIError? = null) : AuthUIState
@Serializable @Serializable
object Loading : AuthUIState() object Loading : AuthUIState
@Serializable @Serializable
object Authorized : AuthUIState() object Authorized : AuthUIState
companion object { companion object {
val DefaultInit = Init() val DefaultInit = Init()

View File

@ -10,7 +10,6 @@ import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
import dev.inmo.micro_utils.fsm.common.StatesMachine import dev.inmo.micro_utils.fsm.common.StatesMachine
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
import dev.inmo.postssystem.features.common.common.* import dev.inmo.postssystem.features.common.common.*
import dev.inmo.postssystem.features.common.common.ui.JSView import dev.inmo.postssystem.features.common.common.ui.JSView
import dev.inmo.postssystem.features.common.common.ui.fsm.* import dev.inmo.postssystem.features.common.common.ui.fsm.*
@ -98,7 +97,7 @@ class AuthView(
disabled.value = false disabled.value = false
errorText.value = when (it.showError) { errorText.value = when (it.showError) {
ServerUnavailable -> "Server unavailable" AuthUIError.ServerUnavailable -> "Server unavailable"
AuthIncorrect -> { AuthIncorrect -> {
passwordState.value = "" passwordState.value = ""
"Username or password is incorrect" "Username or password is incorrect"

View File

@ -8,7 +8,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline import kotlin.jvm.JvmInline
@Serializable(AuthKeySerializer::class)
sealed interface AuthKey sealed interface AuthKey
@Serializable @Serializable
@ -18,34 +17,6 @@ private data class AuthKeySurrogate(
val refreshToken: RefreshToken? val refreshToken: RefreshToken?
) )
@Serializer(AuthKey::class)
object AuthKeySerializer : KSerializer<AuthKey> {
override val descriptor: SerialDescriptor
get() = AuthKeySurrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): AuthKey {
val surrogate = AuthKeySurrogate.serializer().deserialize(decoder)
when {
surrogate.authCreds != null -> return surrogate.authCreds
surrogate.token != null -> return surrogate.token
surrogate.refreshToken != null -> return surrogate.refreshToken
}
error("Unsupported version of auth key surrogate")
}
override fun serialize(encoder: Encoder, value: AuthKey) {
AuthKeySurrogate.serializer().serialize(
encoder,
AuthKeySurrogate(
value as? AuthCreds,
value as? AuthToken,
value as? RefreshToken
)
)
}
}
@Serializable @Serializable
@SerialName("authcreds") @SerialName("authcreds")
data class AuthCreds( data class AuthCreds(

View File

@ -4,14 +4,9 @@ import dev.inmo.micro_utils.fsm.common.State
import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer
import kotlinx.serialization.* import kotlinx.serialization.*
@Serializable(UIFSMStateSerializer::class)
interface UIFSMState : State { interface UIFSMState : State {
val from: UIFSMState? val from: UIFSMState?
get() = null get() = null
override val context: String override val context: String
get() = "main" get() = "main"
} }
object UIFSMStateSerializer : KSerializer<UIFSMState>, TypedSerializer<UIFSMState>(
UIFSMState::class
)

View File

@ -7,7 +7,11 @@ import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
@Serializable(RoleSerializer::class) @Serializable(RoleSerializer::class)
interface Role interface Role {
companion object {
fun serializer(): KSerializer<Role> = RoleSerializer
}
}
@Serializable @Serializable
data class UnknownRole(val originalJson: JsonElement) : Role data class UnknownRole(val originalJson: JsonElement) : Role

View File

@ -3,28 +3,16 @@ package dev.inmo.postssystem.features.roles.manager.common
import dev.inmo.postssystem.features.roles.common.Role import dev.inmo.postssystem.features.roles.common.Role
import dev.inmo.postssystem.features.roles.common.RoleSerializer import dev.inmo.postssystem.features.roles.common.RoleSerializer
import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
private val justForLoading = RolesManagerRoleSerializer @Serializable
sealed interface RolesManagerRole : Role
@Serializable(RolesManagerRoleSerializer::class)
interface RolesManagerRole : Role
@Serializable @Serializable
@SerialName("GeneralRolesManagerRole")
object GeneralRolesManagerRole : RolesManagerRole { object GeneralRolesManagerRole : RolesManagerRole {
override fun toString(): String = "GeneralRolesManagerRole" override fun toString(): String = "GeneralRolesManagerRole"
} }
private const val KEY = "roles_manager" private val justForLoading = GeneralRolesManagerRole.serializer()
object RolesManagerRoleSerializer : TypedSerializer<RolesManagerRole>(
RolesManagerRole::class,
mapOf(
"${KEY}_general" to GeneralRolesManagerRole.serializer()
)
) {
init {
RoleSerializer.includeSerializer(KEY, RolesManagerRoleSerializer)
serializers.forEach { (k, v) -> RoleSerializer.includeSerializer(k, v) }
}
}

View File

@ -3,7 +3,6 @@ package dev.inmo.postssystem.features.roles.manager.server
import dev.inmo.micro_utils.ktor.server.UnifiedRouter import dev.inmo.micro_utils.ktor.server.UnifiedRouter
import dev.inmo.postssystem.features.roles.common.RolesStorage import dev.inmo.postssystem.features.roles.common.RolesStorage
import dev.inmo.postssystem.features.roles.manager.common.RolesManagerRole import dev.inmo.postssystem.features.roles.manager.common.RolesManagerRole
import dev.inmo.postssystem.features.roles.manager.common.RolesManagerRoleSerializer
import dev.inmo.postssystem.features.roles.server.RolesStorageWriteServerRoutesConfigurator import dev.inmo.postssystem.features.roles.server.RolesStorageWriteServerRoutesConfigurator
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
@ -12,7 +11,7 @@ class RolesManagerRolesStorageServerRoutesConfigurator(
unifiedRouter: UnifiedRouter unifiedRouter: UnifiedRouter
) : ApplicationRoutingConfigurator.Element by RolesStorageWriteServerRoutesConfigurator( ) : ApplicationRoutingConfigurator.Element by RolesStorageWriteServerRoutesConfigurator(
storage, storage,
RolesManagerRoleSerializer, RolesManagerRole.serializer(),
RolesManagerRolesChecker.key, RolesManagerRolesChecker.key,
unifiedRouter = unifiedRouter unifiedRouter = unifiedRouter
) )

View File

@ -2,10 +2,10 @@
kotlin = "1.6.21" kotlin = "1.6.21"
kotlin-serialization = "1.3.3" kotlin-serialization = "1.3.3"
jsuikit = "0.1.0" jsuikit = "0.1.1"
compose = "1.2.0-alpha01-dev683" compose = "1.2.0-alpha01-dev686"
microutils = "0.10.4" microutils = "0.10.4"
tgbotapi = "1.1.0" tgbotapi = "1.1.1"
ktor = "2.0.1" ktor = "2.0.1"
klock = "2.7.0" klock = "2.7.0"
koin = "3.2.0" koin = "3.2.0"
@ -16,7 +16,6 @@ dokka = "1.6.21"
logback = "1.2.10" logback = "1.2.10"
uuid = "0.4.0" uuid = "0.4.0"
android-dexcount = "3.0.1"
android-junit = "4.12" android-junit = "4.12"
android-test-junit = "1.1.2" android-test-junit = "1.1.2"
android-espresso-core = "3.3.0" android-espresso-core = "3.3.0"
@ -24,7 +23,7 @@ android-espresso-core = "3.3.0"
gh-release = "2.3.7" gh-release = "2.3.7"
android-gradle = "7.0.4" android-gradle = "7.0.4"
dexcount = "3.0.1" dexcount = "3.1.0"
android-coreKtx = "1.7.0" android-coreKtx = "1.7.0"
android-recyclerView = "1.2.1" android-recyclerView = "1.2.1"

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable @Serializable
data class SubConfig( data class SubConfig(
@ -12,9 +13,11 @@ data class SubConfig(
val targetChatId: ChatId, val targetChatId: ChatId,
private val hostUrl: String = telegramBotAPIDefaultUrl private val hostUrl: String = telegramBotAPIDefaultUrl
) { ) {
@Transient
val telegramInfo by lazy { val telegramInfo by lazy {
TelegramAPIUrlsKeeper(botToken, hostUrl) TelegramAPIUrlsKeeper(botToken, hostUrl)
} }
@Transient
val bot by lazy { val bot by lazy {
telegramBot(telegramInfo) telegramBot(telegramInfo)
} }