mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-18 06:13:47 +00:00
updates in LiveFlowLocation behaviours
This commit is contained in:
parent
dc5d8afe32
commit
ca1b196942
@ -50,22 +50,30 @@ suspend fun TelegramBot.handleLiveLocation(
|
|||||||
sentMessageFlow: FlowCollector<ContentMessage<LocationContent>>? = null
|
sentMessageFlow: FlowCollector<ContentMessage<LocationContent>>? = null
|
||||||
) {
|
) {
|
||||||
var currentLiveLocationMessage: ContentMessage<LocationContent>? = null
|
var currentLiveLocationMessage: ContentMessage<LocationContent>? = null
|
||||||
val updateMessageJob = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) {
|
val updateMessageJob = if (liveTimeMillis == indefiniteLivePeriodDelayMillis) { // do not launch refreshing of message for indefinite live locations
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(liveTimeMillis)
|
delay(liveTimeMillis)
|
||||||
// Remove previous location message info to resend live location message
|
// Remove previous location message info to resend live location message
|
||||||
currentLiveLocationMessage = null
|
currentLiveLocationMessage = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
locationsFlow.collect {
|
locationsFlow.collect {
|
||||||
val capturedLiveLocationMessage = currentLiveLocationMessage
|
val capturedLiveLocationMessage = currentLiveLocationMessage
|
||||||
if (capturedLiveLocationMessage == null) {
|
if (capturedLiveLocationMessage == null) {
|
||||||
updateMessageJob.start()
|
updateMessageJob ?.start()
|
||||||
currentLiveLocationMessage = send(
|
currentLiveLocationMessage = send(
|
||||||
chatId,
|
chatId,
|
||||||
it.latitude,
|
it.latitude,
|
||||||
it.longitude,
|
it.longitude,
|
||||||
ceil(liveTimeMillis.toDouble() / 1000).toInt(),
|
if (liveTimeMillis == indefiniteLivePeriodDelayMillis) {
|
||||||
|
LiveLocation.INDEFINITE_LIVE_PERIOD
|
||||||
|
} else {
|
||||||
|
ceil(liveTimeMillis.toDouble() / 1000).toInt()
|
||||||
|
},
|
||||||
it.horizontalAccuracy,
|
it.horizontalAccuracy,
|
||||||
it.heading,
|
it.heading,
|
||||||
it.proximityAlertRadius,
|
it.proximityAlertRadius,
|
||||||
@ -83,7 +91,6 @@ suspend fun TelegramBot.handleLiveLocation(
|
|||||||
message = capturedLiveLocationMessage,
|
message = capturedLiveLocationMessage,
|
||||||
latitude = it.latitude,
|
latitude = it.latitude,
|
||||||
longitude = it.longitude,
|
longitude = it.longitude,
|
||||||
livePeriod = null,
|
|
||||||
horizontalAccuracy = it.horizontalAccuracy,
|
horizontalAccuracy = it.horizontalAccuracy,
|
||||||
heading = it.heading,
|
heading = it.heading,
|
||||||
proximityAlertRadius = it.proximityAlertRadius,
|
proximityAlertRadius = it.proximityAlertRadius,
|
||||||
|
@ -23,7 +23,8 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
|
const val indefiniteLivePeriodDelayMillis = LiveLocation.INDEFINITE_LIVE_PERIOD * 1000L
|
||||||
|
const val defaultLivePeriodDelayMillis = indefiniteLivePeriodDelayMillis
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see startLiveLocation
|
* @see startLiveLocation
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types
|
package dev.inmo.tgbotapi.types
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.location.LiveLocation
|
||||||
import dev.inmo.tgbotapi.utils.BuiltinMimeTypes
|
import dev.inmo.tgbotapi.utils.BuiltinMimeTypes
|
||||||
|
|
||||||
typealias ForwardSignature = String
|
typealias ForwardSignature = String
|
||||||
@ -47,7 +48,7 @@ val pollOptionTextLength = 1 .. 100
|
|||||||
val pollQuestionTextLength = 1 .. 300
|
val pollQuestionTextLength = 1 .. 300
|
||||||
val pollOptionsLimit = 2 .. 10
|
val pollOptionsLimit = 2 .. 10
|
||||||
|
|
||||||
val livePeriodLimit = 60 .. 86400
|
val livePeriodLimit = 60 .. LiveLocation.INDEFINITE_LIVE_PERIOD
|
||||||
|
|
||||||
val inlineQueryAnswerResultsLimit = 0 .. 50
|
val inlineQueryAnswerResultsLimit = 0 .. 50
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user