diff --git a/CHANGELOG.md b/CHANGELOG.md index faa8596f01..4006c7c608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # TelegramBotAPI changelog +## 5.2.0 + +* `Versions`: + * `MicroUtils`: `0.16.8` -> `0.16.10` + ## 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 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" 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 ) } 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