From 07082bf896d2062cd5cb51c19d847833ad9c3841 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Feb 2023 14:02:18 +0600 Subject: [PATCH 1/4] start 5.2.0 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa8596f01..1dae9c7b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 5.2.0 + ## 5.1.1 * `Core`: diff --git a/gradle.properties b/gradle.properties index 2b0c021b60..9f0ef35fc6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=5.1.1 +library_version=5.2.0 From a95365a6913e864637f334fecca277f642e1cdfb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Feb 2023 14:03:00 +0600 Subject: [PATCH 2/4] update microutils up to 0.16.10 --- CHANGELOG.md | 3 +++ gradle/libs.versions.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dae9c7b9b..4006c7c608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 5.2.0 +* `Versions`: + * `MicroUtils`: `0.16.8` -> `0.16.10` + ## 5.1.1 * `Core`: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index caca9c0f70..c107f2ee30 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ ktor = "2.2.3" ksp = "1.7.22-1.0.8" kotlin-poet = "1.12.0" -microutils = "0.16.8" +microutils = "0.16.10" github-release-plugin = "2.4.1" dokka = "1.7.20" From 7795bc2b507b973ca1c6681ae29414d39ab02d45 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Feb 2023 15:28:41 +0600 Subject: [PATCH 3/4] LiveLocationProvider#message now is public, but as value instead of variable --- .../extensions/api/LiveLocationProvider.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt index 2831be8eaa..9204df3f32 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt @@ -2,15 +2,22 @@ package dev.inmo.tgbotapi.extensions.api import com.soywiz.klock.DateTime import com.soywiz.klock.TimeSpan +import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions +import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation +import dev.inmo.tgbotapi.extensions.api.send.send +import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.location.LiveLocation +import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -18,7 +25,15 @@ import dev.inmo.tgbotapi.types.message.content.LocationContent import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +import kotlin.js.JsName +import kotlin.jvm.JvmName import kotlin.math.ceil val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L @@ -45,7 +60,8 @@ class LiveLocationProvider internal constructor( private set get() = field || leftUntilCloseMillis.millisecondsLong < 0L - private var message: ContentMessage = initMessage + var message: ContentMessage = initMessage + private set val lastLocation: LiveLocation get() = message.content.location as LiveLocation From 02b5d282d3d751fa6909c0e7fe5cf1aa656b86ad Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Feb 2023 15:31:40 +0600 Subject: [PATCH 4/4] now it is possible to handle send content message in handleLiveLocation --- .../extensions/api/LiveFlowLocation.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt index aa168e30d1..cc4c1e14bf 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveFlowLocation.kt @@ -45,7 +45,8 @@ suspend fun TelegramBot.handleLiveLocation( disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, - allowSendingWithoutReply: Boolean? = null + allowSendingWithoutReply: Boolean? = null, + sentMessageDeferred: CompletableDeferred>? = null ) { var currentLiveLocationMessage: ContentMessage? = null val updateMessageJob = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) { @@ -73,7 +74,9 @@ suspend fun TelegramBot.handleLiveLocation( replyToMessageId, allowSendingWithoutReply, it.replyMarkup - ) + ).also { + sentMessageDeferred ?.complete(it) + } } else { edit( capturedLiveLocationMessage, @@ -102,7 +105,8 @@ suspend fun TelegramBot.handleLiveLocation( disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, - allowSendingWithoutReply: Boolean? = null + allowSendingWithoutReply: Boolean? = null, + sentMessageDeferred: CompletableDeferred>? = null ) { handleLiveLocation( chatId, @@ -121,7 +125,8 @@ suspend fun TelegramBot.handleLiveLocation( disableNotification, protectContent, replyToMessageId, - allowSendingWithoutReply + allowSendingWithoutReply, + sentMessageDeferred ) } @@ -139,7 +144,8 @@ suspend fun TelegramBot.handleLiveLocation( disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, - allowSendingWithoutReply: Boolean? = null + allowSendingWithoutReply: Boolean? = null, + sentMessageDeferred: CompletableDeferred>? = null ) { handleLiveLocation( chatId, @@ -154,6 +160,7 @@ suspend fun TelegramBot.handleLiveLocation( disableNotification, protectContent, replyToMessageId, - allowSendingWithoutReply + allowSendingWithoutReply, + sentMessageDeferred ) }