diff --git a/features/auth/client/build.gradle b/features/auth/client/build.gradle index 611d9b31..8687f515 100644 --- a/features/auth/client/build.gradle +++ b/features/auth/client/build.gradle @@ -16,9 +16,5 @@ kotlin { api project(":postssystem.features.auth.common") } } - clientMain { - dependencies { - } - } } } diff --git a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/settings/DefaultAuthSettings.kt b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/settings/DefaultAuthSettings.kt index 747d60fc..36ca0a39 100644 --- a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/settings/DefaultAuthSettings.kt +++ b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/settings/DefaultAuthSettings.kt @@ -9,6 +9,8 @@ import dev.inmo.micro_utils.common.Either 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.* @@ -83,8 +85,8 @@ data class DefaultAuthSettings( currentModule ?.let { koin.loadModules(listOf(currentModule)) } } return when { - !serverAvailable -> ServerUnavailableAuthUIError - !authCorrect -> AuthIncorrectAuthUIError + !serverAvailable -> ServerUnavailable + !authCorrect -> AuthIncorrect else -> { _authorizedDIModule.value = newModule null diff --git a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/AuthUIState.kt b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/AuthUIState.kt index aeaf4f5f..e8ff6381 100644 --- a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/AuthUIState.kt +++ b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/AuthUIState.kt @@ -3,18 +3,23 @@ package dev.inmo.postssystem.features.auth.client.ui import kotlinx.serialization.Serializable @Serializable -sealed class AuthUIError -@Serializable -object ServerUnavailableAuthUIError : AuthUIError() -@Serializable -object AuthIncorrectAuthUIError : AuthUIError() +sealed class AuthUIError { + @Serializable + object ServerUnavailable : AuthUIError() + @Serializable + object AuthIncorrect : AuthUIError() +} @Serializable -sealed class AuthUIState -@Serializable -data class InitAuthUIState(val showError: AuthUIError? = null) : AuthUIState() -val DefaultInitAuthUIState = InitAuthUIState() -@Serializable -object LoadingAuthUIState : AuthUIState() -@Serializable -object AuthorizedAuthUIState : AuthUIState() +sealed class AuthUIState { + @Serializable + data class Init(val showError: AuthUIError? = null) : AuthUIState() + @Serializable + object Loading : AuthUIState() + @Serializable + object Authorized : AuthUIState() + + companion object { + val DefaultInit = Init() + } +} diff --git a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/DefaultAuthUIModel.kt b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/DefaultAuthUIModel.kt index 65de6bf1..3699f618 100644 --- a/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/DefaultAuthUIModel.kt +++ b/features/auth/client/src/commonMain/kotlin/dev/inmo/postssystem/features/auth/client/ui/DefaultAuthUIModel.kt @@ -9,26 +9,26 @@ import kotlinx.coroutines.launch class DefaultAuthUIModel( private val scope: CoroutineScope, private val authSettings: AuthSettings -) : AbstractUIModel(LoadingAuthUIState), AuthUIModel { +) : AbstractUIModel(AuthUIState.Loading), AuthUIModel { init { scope.launch { - _currentState.value = LoadingAuthUIState + _currentState.value = AuthUIState.Loading authSettings.loadingJob.join() if (authSettings.authorizedDIModule.value == null) { - _currentState.value = DefaultInitAuthUIState + _currentState.value = AuthUIState.DefaultInit } else { - _currentState.value = AuthorizedAuthUIState + _currentState.value = AuthUIState.Authorized } } } override suspend fun initAuth(serverUrl: String, creds: AuthCreds) { - _currentState.value = LoadingAuthUIState + _currentState.value = AuthUIState.Loading val authError = authSettings.auth(serverUrl, creds) if (authError == null) { - _currentState.value = AuthorizedAuthUIState + _currentState.value = AuthUIState.Authorized } else { - _currentState.value = InitAuthUIState(authError) + _currentState.value = AuthUIState.Init(authError) } } diff --git a/features/auth/client/src/jsMain/kotlin/dev/inmo/postssystem/features/auth/client/AuthView.kt b/features/auth/client/src/jsMain/kotlin/dev/inmo/postssystem/features/auth/client/AuthView.kt index 7b516807..81e8a35d 100644 --- a/features/auth/client/src/jsMain/kotlin/dev/inmo/postssystem/features/auth/client/AuthView.kt +++ b/features/auth/client/src/jsMain/kotlin/dev/inmo/postssystem/features/auth/client/AuthView.kt @@ -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.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.* @@ -19,9 +21,11 @@ import org.jetbrains.compose.web.attributes.InputType import org.jetbrains.compose.web.dom.Text import org.w3c.dom.* +@ExperimentalStdlibApi +@EagerInitialization val loader = DefaultModuleLoader { factory { AuthView(get(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) } - singleWithRandomQualifier { + singleWithRandomQualifier { UIFSMHandler.Registrator { strictlyOn(get()) } @@ -64,13 +68,13 @@ class AuthView( } } - TextField( + StandardInput( InputType.Text, usernameState, disabled, "Username", ) - TextField( + StandardInput( InputType.Password, passwordState, disabled, @@ -90,23 +94,23 @@ class AuthView( val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) { when (it) { - is InitAuthUIState -> { + is AuthUIState.Init -> { disabled.value = false errorText.value = when (it.showError) { - ServerUnavailableAuthUIError -> "Server unavailable" - AuthIncorrectAuthUIError -> { + ServerUnavailable -> "Server unavailable" + AuthIncorrect -> { passwordState.value = "" "Username or password is incorrect" } null -> null } } - LoadingAuthUIState -> { + AuthUIState.Loading -> { disabled.value = true errorText.value = null } - AuthorizedAuthUIState -> { + AuthUIState.Authorized -> { completion.complete(state.from) } } diff --git a/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt index 455484d2..13fce4c4 100644 --- a/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt +++ b/features/common/common/src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/SimpleInputProvider.kt @@ -33,9 +33,10 @@ expect class FileBasedInputProvider : SimpleInputProvider { } @Serializable(SimpleInputProviderSerializer::class) -class CustomInputProvider(private val provider: () -> Input) : SimpleInputProvider { - override val contentBytes: Long? - get() = null +class CustomInputProvider( + override val contentBytes: Long? = null, + private val provider: () -> Input +) : SimpleInputProvider { override fun invoke(): Input = provider() } diff --git a/features/roles/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/common/Role.kt b/features/roles/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/common/Role.kt index b075618d..78215029 100644 --- a/features/roles/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/common/Role.kt +++ b/features/roles/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/common/Role.kt @@ -7,11 +7,7 @@ import kotlinx.serialization.encoding.* import kotlinx.serialization.json.* @Serializable(RoleSerializer::class) -interface Role { - companion object { - fun serializer() = RoleSerializer - } -} +interface Role @Serializable data class UnknownRole(val originalJson: JsonElement) : Role diff --git a/features/roles/manager/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/manager/common/RolesManagerRole.kt b/features/roles/manager/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/manager/common/RolesManagerRole.kt index bb500ae0..f9b4f615 100644 --- a/features/roles/manager/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/manager/common/RolesManagerRole.kt +++ b/features/roles/manager/common/src/commonMain/kotlin/dev/inmo/postssystem/features/roles/manager/common/RolesManagerRole.kt @@ -8,11 +8,7 @@ import kotlinx.serialization.Serializable private val justForLoading = RolesManagerRoleSerializer @Serializable(RolesManagerRoleSerializer::class) -interface RolesManagerRole : Role { - companion object { - fun serializer() = RolesManagerRoleSerializer - } -} +interface RolesManagerRole : Role @Serializable object GeneralRolesManagerRole : RolesManagerRole { diff --git a/targets/telegram/loader/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/loader/server/SubConfig.kt b/targets/telegram/loader/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/loader/server/SubConfig.kt index 282a3f61..a3264e6c 100644 --- a/targets/telegram/loader/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/loader/server/SubConfig.kt +++ b/targets/telegram/loader/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/loader/server/SubConfig.kt @@ -1,6 +1,6 @@ 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.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl diff --git a/targets/telegram/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/publication/server/PublicationTargetTelegram.kt b/targets/telegram/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/publication/server/PublicationTargetTelegram.kt index ae5902da..35cd43a9 100644 --- a/targets/telegram/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/publication/server/PublicationTargetTelegram.kt +++ b/targets/telegram/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/targets/telegram/publication/server/PublicationTargetTelegram.kt @@ -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.PublicationTarget 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.asMultipartFile import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.requests.send.media.* import dev.inmo.tgbotapi.types.ChatId -import io.ktor.utils.io.ByteReadChannel -import io.ktor.utils.io.core.readBytes import kotlinx.coroutines.delay class PublicationTargetTelegram( @@ -24,7 +20,7 @@ class PublicationTargetTelegram( post.content.mapNotNull { when (val content = it.content) { is BinaryContent -> { - val storageFile by lazy { + val multipartFile by lazy { MultipartFile(content.filename.name) { content.inputProvider() } @@ -32,17 +28,17 @@ class PublicationTargetTelegram( when (content.mimeType) { is KnownMimeTypes.Image.Jpeg, is KnownMimeTypes.Image.Png -> { - SendPhoto(targetChatId, storageFile) + SendPhoto(targetChatId, multipartFile) } is KnownMimeTypes.Video.Mp4 -> { - SendVideo(targetChatId, storageFile) + SendVideo(targetChatId, multipartFile) } is KnownMimeTypes.Audio.Mpeg -> { - SendAudio(targetChatId, storageFile) + SendAudio(targetChatId, multipartFile) } else -> SendDocument( targetChatId, - storageFile + multipartFile ) } }