mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fill edit and stop live location methods
This commit is contained in:
parent
e7bdc85279
commit
c7d5fdd2e0
@ -1,12 +1,13 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditChatMessageLiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.StopChatMessageLiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import com.soywiz.klock.DateTime
|
||||
import com.soywiz.klock.TimeSpan
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
@ -16,9 +17,7 @@ private val livePeriodDelayDouble = ((livePeriodLimit.last - 60L) * 1000L).toDou
|
||||
class LiveLocation internal constructor(
|
||||
private val scope: CoroutineScope,
|
||||
private val requestsExecutor: RequestsExecutor,
|
||||
private val chatId: ChatIdentifier,
|
||||
private val messageId: MessageIdentifier,
|
||||
location: Location
|
||||
initMessage: ContentMessage<LocationContent>
|
||||
) : Closeable {
|
||||
var isClosed: Boolean = false
|
||||
private set
|
||||
@ -26,8 +25,8 @@ class LiveLocation internal constructor(
|
||||
val leftUntilCloseMillis: TimeSpan
|
||||
get() = autoCloseTime - DateTime.now()
|
||||
private var updateJob: Job? = null
|
||||
var lastLocation: Location = location
|
||||
private set(value) {
|
||||
private var message: ContentMessage<LocationContent> = initMessage
|
||||
set(value) {
|
||||
field = value
|
||||
updateJob ?.cancel()
|
||||
updateJob = scope.launch {
|
||||
@ -37,9 +36,11 @@ class LiveLocation internal constructor(
|
||||
close()
|
||||
}
|
||||
}
|
||||
val lastLocation: Location
|
||||
get() = message.content.location
|
||||
|
||||
init {
|
||||
this.lastLocation = location // required to init updateJob
|
||||
message = initMessage // required to init updateJob
|
||||
}
|
||||
|
||||
suspend fun updateLocation(
|
||||
@ -47,15 +48,11 @@ class LiveLocation internal constructor(
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
): Location {
|
||||
if (!isClosed) {
|
||||
lastLocation = requestsExecutor.execute(
|
||||
EditChatMessageLiveLocation(
|
||||
chatId,
|
||||
messageId,
|
||||
location.latitude,
|
||||
location.longitude,
|
||||
replyMarkup
|
||||
)
|
||||
).content.location
|
||||
message = requestsExecutor.editLiveLocation(
|
||||
message,
|
||||
location,
|
||||
replyMarkup
|
||||
)
|
||||
return lastLocation
|
||||
} else {
|
||||
error("LiveLocation is closed")
|
||||
@ -69,12 +66,7 @@ class LiveLocation internal constructor(
|
||||
isClosed = true
|
||||
updateJob ?.cancel()
|
||||
scope.launch {
|
||||
requestsExecutor.execute(
|
||||
StopChatMessageLiveLocation(
|
||||
chatId,
|
||||
messageId
|
||||
)
|
||||
)
|
||||
requestsExecutor.stopLiveLocation(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,8 +95,6 @@ suspend fun RequestsExecutor.startLiveLocation(
|
||||
return LiveLocation(
|
||||
scope,
|
||||
this,
|
||||
chatId,
|
||||
locationMessage.messageId,
|
||||
locationMessage.content.location
|
||||
locationMessage
|
||||
)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
@ -29,3 +31,54 @@ data class EditChatMessageLiveLocation(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageLiveLocation(
|
||||
chatId, messageId, latitude, longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(chat.id, messageId, latitude, longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(message.chat, message.messageId, latitude, longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditChatMessageLiveLocation(
|
||||
chatId, messageId, location.latitude, location.longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
@ -20,3 +21,19 @@ data class EditInlineMessageLiveLocation(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
latitude: Double,
|
||||
longitude: Double,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
EditInlineMessageLiveLocation(
|
||||
inlineMessageId, latitude, longitude, replyMarkup
|
||||
)
|
||||
)
|
||||
suspend fun RequestsExecutor.editLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
location: Location,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup)
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditChatMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
@ -26,3 +28,25 @@ data class StopChatMessageLiveLocation(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
StopChatMessageLiveLocation(
|
||||
chatId, messageId, replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
chat: Chat,
|
||||
messageId: MessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopLiveLocation(chat.id, messageId, replyMarkup)
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
message: ContentMessage<LocationContent>,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = stopLiveLocation(message.chat, message.messageId, replyMarkup)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
@ -17,3 +18,12 @@ data class StopInlineMessageLiveLocation(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
suspend fun RequestsExecutor.stopLiveLocation(
|
||||
inlineMessageId: InlineMessageIdentifier,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = execute(
|
||||
StopInlineMessageLiveLocation(
|
||||
inlineMessageId, replyMarkup
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user