From 3695ab7936a8caa9862406f87a7383ad36794068 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Sep 2022 01:53:51 +0600 Subject: [PATCH 1/5] start 0.5.4 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index be1ce12..80f798e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,5 +33,5 @@ dokka_version=1.7.10 # Project data group=dev.inmo -version=0.5.3 -android_code_version=30 +version=0.5.4 +android_code_version=31 From 539515da430a38f8e5b10756edf51c633fa3026f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Sep 2022 01:54:44 +0600 Subject: [PATCH 2/5] update dependencies --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 80f798e..241e820 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,10 +11,10 @@ kotlin_serialisation_core_version=1.4.0 github_release_plugin_version=2.4.1 -tgbotapi_version=3.2.1 -micro_utils_version=0.12.11 +tgbotapi_version=3.2.5 +micro_utils_version=0.12.13 exposed_version=0.39.2 -plagubot_version=2.3.1 +plagubot_version=2.3.2 # ANDROID From 7845b7cc5f2797fd1badd5e6a4c3e644314bc70f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Sep 2022 01:56:41 +0600 Subject: [PATCH 3/5] small fixes --- .../tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt index dbde1f2..f46a31b 100644 --- a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt +++ b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt @@ -40,9 +40,9 @@ fun TelegramBot.createAdminsCacheAPI( "AdminsTable" ).withMapper( keyFromToTo = { chatId }, - valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, + valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdministratorChatMember.serializer(), this) }, keyToToFrom = { toChatId() }, - valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) } + valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(AdministratorChatMember.serializer(), this) } ), ExposedKeyValueRepo( database, @@ -65,9 +65,9 @@ fun TelegramBot.createAdminsCacheAPI( "DynamicAdminsCacheSettingsAPI" ).withMapper( keyFromToTo = { chatId }, - valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, + valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdminsCacheSettings.serializer() , this) }, keyToToFrom = { toChatId() }, - valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) } + valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(AdminsCacheSettings.serializer() , this) } ), scope ) From 950eebea061d62bcb5b5135927e55eaedb5c7686 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Sep 2022 02:42:10 +0600 Subject: [PATCH 4/5] fixes --- .../micro_utils/DefaultAdminsCacheAPI.kt | 58 +++++++++++++------ gradle.properties | 2 +- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt index 2c51f1d..ee77c23 100644 --- a/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt +++ b/cache/admins/micro_utils/src/commonMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/micro_utils/DefaultAdminsCacheAPI.kt @@ -1,31 +1,31 @@ package dev.inmo.tgbotapi.libraries.cache.admins.micro_utils import com.soywiz.klock.DateTime -import dev.inmo.micro_utils.coroutines.actor -import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.* import dev.inmo.micro_utils.repos.* import dev.inmo.tgbotapi.libraries.cache.admins.DefaultAdminsCacheAPIRepo import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.* import kotlin.coroutines.* private sealed class RepoActions { - abstract val toReturn: Continuation + abstract val deferred: CompletableDeferred } private class GetUpdateDateTimeRepoAction( val chatId: ChatId, - override val toReturn: Continuation + override val deferred: CompletableDeferred ) : RepoActions() private class GetChatAdminsRepoAction( val chatId: ChatId, - override val toReturn: Continuation?> + override val deferred: CompletableDeferred?> ) : RepoActions?>() private class SetChatAdminsRepoAction( val chatId: ChatId, val newValue: List, - override val toReturn: Continuation + override val deferred: CompletableDeferred ) : RepoActions() class DefaultAdminsCacheAPIRepoImpl( @@ -33,32 +33,54 @@ class DefaultAdminsCacheAPIRepoImpl( private val updatesRepo: KeyValueRepo, private val scope: CoroutineScope ) : DefaultAdminsCacheAPIRepo { - private val actor = scope.actor>(Channel.UNLIMITED) { - safelyWithoutExceptions { + private val actor = scope.actorAsync>(Channel.UNLIMITED) { + safelyWithoutExceptions( + { e -> + it.deferred.completeExceptionally(e) + } + ) { when (it) { - is GetUpdateDateTimeRepoAction -> it.toReturn.resume( + is GetUpdateDateTimeRepoAction -> it.deferred.complete( updatesRepo.get(it.chatId) ?.let { DateTime(it.toDouble()) } ) - is GetChatAdminsRepoAction -> it.toReturn.resume(adminsRepo.getAll(it.chatId)) + is GetChatAdminsRepoAction -> it.deferred.complete(adminsRepo.getAll(it.chatId)) is SetChatAdminsRepoAction -> { adminsRepo.clear(it.chatId) adminsRepo.set(it.chatId, it.newValue) updatesRepo.set(it.chatId, DateTime.now().unixMillisLong) - it.toReturn.resume(Unit) + it.deferred.complete(Unit) } } } } - override suspend fun getChatAdmins(chatId: ChatId): List? = suspendCoroutine { - actor.trySend(GetChatAdminsRepoAction(chatId, it)) + override suspend fun getChatAdmins(chatId: ChatId): List? { + val deferred = CompletableDeferred?>() + actor.trySend( + GetChatAdminsRepoAction(chatId, deferred) + ).onFailure { + deferred.completeExceptionally(it ?: IllegalStateException("Something went wrong when tried to add getChatAdmins action")) + } + return deferred.await() } - override suspend fun setChatAdmins(chatId: ChatId, chatMembers: List) = suspendCoroutine { - actor.trySend(SetChatAdminsRepoAction(chatId, chatMembers, it)) + override suspend fun setChatAdmins(chatId: ChatId, chatMembers: List) { + val deferred = CompletableDeferred() + actor.trySend( + SetChatAdminsRepoAction(chatId, chatMembers, deferred) + ).onFailure { + deferred.completeExceptionally(it ?: IllegalStateException("Something went wrong when tried to add setChatAdmins action")) + } + return deferred.await() } - override suspend fun lastUpdate(chatId: ChatId): DateTime? = suspendCoroutine { - actor.trySend(GetUpdateDateTimeRepoAction(chatId, it)) + override suspend fun lastUpdate(chatId: ChatId): DateTime? { + val deferred = CompletableDeferred() + actor.trySend( + GetUpdateDateTimeRepoAction(chatId, deferred) + ).onFailure { + deferred.completeExceptionally(it ?: IllegalStateException("Something went wrong when tried to add lastUpdate action")) + } + return deferred.await() } } diff --git a/gradle.properties b/gradle.properties index 241e820..045c2c7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ kotlin_serialisation_core_version=1.4.0 github_release_plugin_version=2.4.1 -tgbotapi_version=3.2.5 +tgbotapi_version=3.2.6 micro_utils_version=0.12.13 exposed_version=0.39.2 plagubot_version=2.3.2 From ee9f524fc6cd7bdf0d4f5bf8cc70093089e05e5a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Sep 2022 23:32:07 +0600 Subject: [PATCH 5/5] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 045c2c7..44bd163 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ github_release_plugin_version=2.4.1 tgbotapi_version=3.2.6 micro_utils_version=0.12.13 exposed_version=0.39.2 -plagubot_version=2.3.2 +plagubot_version=2.3.3 # ANDROID