a little updates

This commit is contained in:
2022-05-07 21:54:19 +06:00
parent a3ff08af27
commit 55d0e1b55f
10 changed files with 53 additions and 57 deletions
features
auth
client
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
jsMain
kotlin
dev
inmo
postssystem
features
auth
common
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
common
manager
common
src
commonMain
kotlin
dev
inmo
postssystem
features
roles
manager
targets/telegram
loader
server
src
jvmMain
kotlin
dev
inmo
postssystem
targets
telegram
loader
publication
server
src
jvmMain
kotlin
dev
inmo
postssystem
targets
telegram

@ -16,9 +16,5 @@ kotlin {
api project(":postssystem.features.auth.common") api project(":postssystem.features.auth.common")
} }
} }
clientMain {
dependencies {
}
}
} }
} }

@ -9,6 +9,8 @@ import dev.inmo.micro_utils.common.Either
import dev.inmo.micro_utils.common.either 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.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.*
@ -83,8 +85,8 @@ data class DefaultAuthSettings(
currentModule ?.let { koin.loadModules(listOf(currentModule)) } currentModule ?.let { koin.loadModules(listOf(currentModule)) }
} }
return when { return when {
!serverAvailable -> ServerUnavailableAuthUIError !serverAvailable -> ServerUnavailable
!authCorrect -> AuthIncorrectAuthUIError !authCorrect -> AuthIncorrect
else -> { else -> {
_authorizedDIModule.value = newModule _authorizedDIModule.value = newModule
null null

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

@ -9,26 +9,26 @@ import kotlinx.coroutines.launch
class DefaultAuthUIModel( class DefaultAuthUIModel(
private val scope: CoroutineScope, private val scope: CoroutineScope,
private val authSettings: AuthSettings private val authSettings: AuthSettings
) : AbstractUIModel<AuthUIState>(LoadingAuthUIState), AuthUIModel { ) : AbstractUIModel<AuthUIState>(AuthUIState.Loading), AuthUIModel {
init { init {
scope.launch { scope.launch {
_currentState.value = LoadingAuthUIState _currentState.value = AuthUIState.Loading
authSettings.loadingJob.join() authSettings.loadingJob.join()
if (authSettings.authorizedDIModule.value == null) { if (authSettings.authorizedDIModule.value == null) {
_currentState.value = DefaultInitAuthUIState _currentState.value = AuthUIState.DefaultInit
} else { } else {
_currentState.value = AuthorizedAuthUIState _currentState.value = AuthUIState.Authorized
} }
} }
} }
override suspend fun initAuth(serverUrl: String, creds: AuthCreds) { override suspend fun initAuth(serverUrl: String, creds: AuthCreds) {
_currentState.value = LoadingAuthUIState _currentState.value = AuthUIState.Loading
val authError = authSettings.auth(serverUrl, creds) val authError = authSettings.auth(serverUrl, creds)
if (authError == null) { if (authError == null) {
_currentState.value = AuthorizedAuthUIState _currentState.value = AuthUIState.Authorized
} else { } else {
_currentState.value = InitAuthUIState(authError) _currentState.value = AuthUIState.Init(authError)
} }
} }

@ -9,6 +9,8 @@ import dev.inmo.postssystem.features.auth.client.ui.*
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions 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.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.*
@ -19,9 +21,11 @@ import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.dom.Text import org.jetbrains.compose.web.dom.Text
import org.w3c.dom.* import org.w3c.dom.*
@ExperimentalStdlibApi
@EagerInitialization
val loader = DefaultModuleLoader { val loader = DefaultModuleLoader {
factory { AuthView(get(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) } factory { AuthView(get(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) }
singleWithRandomQualifier<UIFSMHandler.Registrator> { singleWithRandomQualifier {
UIFSMHandler.Registrator { UIFSMHandler.Registrator {
strictlyOn(get<AuthView>()) strictlyOn(get<AuthView>())
} }
@ -64,13 +68,13 @@ class AuthView(
} }
} }
TextField( StandardInput(
InputType.Text, InputType.Text,
usernameState, usernameState,
disabled, disabled,
"Username", "Username",
) )
TextField( StandardInput(
InputType.Password, InputType.Password,
passwordState, passwordState,
disabled, disabled,
@ -90,23 +94,23 @@ class AuthView(
val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) { val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) {
when (it) { when (it) {
is InitAuthUIState -> { is AuthUIState.Init -> {
disabled.value = false disabled.value = false
errorText.value = when (it.showError) { errorText.value = when (it.showError) {
ServerUnavailableAuthUIError -> "Server unavailable" ServerUnavailable -> "Server unavailable"
AuthIncorrectAuthUIError -> { AuthIncorrect -> {
passwordState.value = "" passwordState.value = ""
"Username or password is incorrect" "Username or password is incorrect"
} }
null -> null null -> null
} }
} }
LoadingAuthUIState -> { AuthUIState.Loading -> {
disabled.value = true disabled.value = true
errorText.value = null errorText.value = null
} }
AuthorizedAuthUIState -> { AuthUIState.Authorized -> {
completion.complete(state.from) completion.complete(state.from)
} }
} }

@ -33,9 +33,10 @@ expect class FileBasedInputProvider : SimpleInputProvider {
} }
@Serializable(SimpleInputProviderSerializer::class) @Serializable(SimpleInputProviderSerializer::class)
class CustomInputProvider(private val provider: () -> Input) : SimpleInputProvider { class CustomInputProvider(
override val contentBytes: Long? override val contentBytes: Long? = null,
get() = null private val provider: () -> Input
) : SimpleInputProvider {
override fun invoke(): Input = provider() override fun invoke(): Input = provider()
} }

@ -7,11 +7,7 @@ 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() = RoleSerializer
}
}
@Serializable @Serializable
data class UnknownRole(val originalJson: JsonElement) : Role data class UnknownRole(val originalJson: JsonElement) : Role

@ -8,11 +8,7 @@ import kotlinx.serialization.Serializable
private val justForLoading = RolesManagerRoleSerializer private val justForLoading = RolesManagerRoleSerializer
@Serializable(RolesManagerRoleSerializer::class) @Serializable(RolesManagerRoleSerializer::class)
interface RolesManagerRole : Role { interface RolesManagerRole : Role
companion object {
fun serializer() = RolesManagerRoleSerializer
}
}
@Serializable @Serializable
object GeneralRolesManagerRole : RolesManagerRole { object GeneralRolesManagerRole : RolesManagerRole {

@ -1,6 +1,6 @@
package dev.inmo.postssystem.targets.telegram.loader.server package dev.inmo.postssystem.targets.telegram.loader.server
import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.types.ChatId 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

@ -6,14 +6,10 @@ import dev.inmo.postssystem.features.content.text.common.TextContent
import dev.inmo.postssystem.features.publication.server.PublicationPost import dev.inmo.postssystem.features.publication.server.PublicationPost
import dev.inmo.postssystem.features.publication.server.PublicationTarget import dev.inmo.postssystem.features.publication.server.PublicationTarget
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.requests.send.SendTextMessage
import dev.inmo.tgbotapi.requests.send.media.* import dev.inmo.tgbotapi.requests.send.media.*
import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.ChatId
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.readBytes
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
class PublicationTargetTelegram( class PublicationTargetTelegram(
@ -24,7 +20,7 @@ class PublicationTargetTelegram(
post.content.mapNotNull { post.content.mapNotNull {
when (val content = it.content) { when (val content = it.content) {
is BinaryContent -> { is BinaryContent -> {
val storageFile by lazy { val multipartFile by lazy {
MultipartFile(content.filename.name) { MultipartFile(content.filename.name) {
content.inputProvider() content.inputProvider()
} }
@ -32,17 +28,17 @@ class PublicationTargetTelegram(
when (content.mimeType) { when (content.mimeType) {
is KnownMimeTypes.Image.Jpeg, is KnownMimeTypes.Image.Jpeg,
is KnownMimeTypes.Image.Png -> { is KnownMimeTypes.Image.Png -> {
SendPhoto(targetChatId, storageFile) SendPhoto(targetChatId, multipartFile)
} }
is KnownMimeTypes.Video.Mp4 -> { is KnownMimeTypes.Video.Mp4 -> {
SendVideo(targetChatId, storageFile) SendVideo(targetChatId, multipartFile)
} }
is KnownMimeTypes.Audio.Mpeg -> { is KnownMimeTypes.Audio.Mpeg -> {
SendAudio(targetChatId, storageFile) SendAudio(targetChatId, multipartFile)
} }
else -> SendDocument( else -> SendDocument(
targetChatId, targetChatId,
storageFile multipartFile
) )
} }
} }