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.postssystem.features.auth.client.createAuthorizedFeaturesDIModule
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 kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
@ -85,7 +84,7 @@ data class DefaultAuthSettings(
currentModule ?.let { koin.loadModules(listOf(currentModule)) }
}
return when {
!serverAvailable -> ServerUnavailable
!serverAvailable -> AuthUIError.ServerUnavailable
!authCorrect -> AuthIncorrect
else -> {
_authorizedDIModule.value = newModule

View File

@ -1,12 +1,8 @@
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.UIFSMStateSerializer
import kotlinx.serialization.Serializable
@Serializable
data class AuthUIFSMState(
@Serializable(UIFSMStateSerializer::class)
override val from: UIFSMState?,
override val context: String = "main"
) : UIFSMState

View File

@ -3,21 +3,21 @@ package dev.inmo.postssystem.features.auth.client.ui
import kotlinx.serialization.Serializable
@Serializable
sealed class AuthUIError {
sealed interface AuthUIError {
@Serializable
object ServerUnavailable : AuthUIError()
object ServerUnavailable : AuthUIError
@Serializable
object AuthIncorrect : AuthUIError()
object AuthIncorrect : AuthUIError
}
@Serializable
sealed class AuthUIState {
sealed interface AuthUIState {
@Serializable
data class Init(val showError: AuthUIError? = null) : AuthUIState()
data class Init(val showError: AuthUIError? = null) : AuthUIState
@Serializable
object Loading : AuthUIState()
object Loading : AuthUIState
@Serializable
object Authorized : AuthUIState()
object Authorized : AuthUIState
companion object {
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.fsm.common.StatesMachine
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.ui.JSView
import dev.inmo.postssystem.features.common.common.ui.fsm.*
@ -98,7 +97,7 @@ class AuthView(
disabled.value = false
errorText.value = when (it.showError) {
ServerUnavailable -> "Server unavailable"
AuthUIError.ServerUnavailable -> "Server unavailable"
AuthIncorrect -> {
passwordState.value = ""
"Username or password is incorrect"

View File

@ -8,7 +8,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline
@Serializable(AuthKeySerializer::class)
sealed interface AuthKey
@Serializable
@ -18,34 +17,6 @@ private data class AuthKeySurrogate(
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
@SerialName("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 kotlinx.serialization.*
@Serializable(UIFSMStateSerializer::class)
interface UIFSMState : State {
val from: UIFSMState?
get() = null
override val context: String
get() = "main"
}
object UIFSMStateSerializer : KSerializer<UIFSMState>, TypedSerializer<UIFSMState>(
UIFSMState::class
)

View File

@ -7,7 +7,11 @@ import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
@Serializable(RoleSerializer::class)
interface Role
interface Role {
companion object {
fun serializer(): KSerializer<Role> = RoleSerializer
}
}
@Serializable
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.RoleSerializer
import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
private val justForLoading = RolesManagerRoleSerializer
@Serializable(RolesManagerRoleSerializer::class)
interface RolesManagerRole : Role
@Serializable
sealed interface RolesManagerRole : Role
@Serializable
@SerialName("GeneralRolesManagerRole")
object GeneralRolesManagerRole : RolesManagerRole {
override fun toString(): String = "GeneralRolesManagerRole"
}
private const val KEY = "roles_manager"
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) }
}
}
private val justForLoading = GeneralRolesManagerRole.serializer()

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.postssystem.features.roles.common.RolesStorage
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.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
@ -12,7 +11,7 @@ class RolesManagerRolesStorageServerRoutesConfigurator(
unifiedRouter: UnifiedRouter
) : ApplicationRoutingConfigurator.Element by RolesStorageWriteServerRoutesConfigurator(
storage,
RolesManagerRoleSerializer,
RolesManagerRole.serializer(),
RolesManagerRolesChecker.key,
unifiedRouter = unifiedRouter
)

View File

@ -2,10 +2,10 @@
kotlin = "1.6.21"
kotlin-serialization = "1.3.3"
jsuikit = "0.1.0"
compose = "1.2.0-alpha01-dev683"
jsuikit = "0.1.1"
compose = "1.2.0-alpha01-dev686"
microutils = "0.10.4"
tgbotapi = "1.1.0"
tgbotapi = "1.1.1"
ktor = "2.0.1"
klock = "2.7.0"
koin = "3.2.0"
@ -16,7 +16,6 @@ dokka = "1.6.21"
logback = "1.2.10"
uuid = "0.4.0"
android-dexcount = "3.0.1"
android-junit = "4.12"
android-test-junit = "1.1.2"
android-espresso-core = "3.3.0"
@ -24,7 +23,7 @@ android-espresso-core = "3.3.0"
gh-release = "2.3.7"
android-gradle = "7.0.4"
dexcount = "3.0.1"
dexcount = "3.1.0"
android-coreKtx = "1.7.0"
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.telegramBotAPIDefaultUrl
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
data class SubConfig(
@ -12,9 +13,11 @@ data class SubConfig(
val targetChatId: ChatId,
private val hostUrl: String = telegramBotAPIDefaultUrl
) {
@Transient
val telegramInfo by lazy {
TelegramAPIUrlsKeeper(botToken, hostUrl)
}
@Transient
val bot by lazy {
telegramBot(telegramInfo)
}