mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-09-13 11:34:18 +00:00
Compare commits
8 Commits
8a6e06bbf0
...
99f95ffc40
| Author | SHA1 | Date | |
|---|---|---|---|
| 99f95ffc40 | |||
| a8ed162c9c | |||
| e5ea980347 | |||
| 4ce26c707e | |||
| 4343dbbde8 | |||
| cdecce96e7 | |||
|
|
40613e3418 | ||
|
|
016cfcb7cd |
@@ -2,6 +2,12 @@
|
||||
|
||||
## 15.1.1
|
||||
|
||||
* `API`:
|
||||
* Enabled an `explicit mode` for `API` module ([PR #876](https://github.com/InsanusMokrassar/ktgbotapi/pull/876))
|
||||
* `WebApps`:
|
||||
* Built-in `onClick` and `offClick` of `MainButton` become public ([PR #875](https://github.com/InsanusMokrassar/ktgbotapi/pull/875))
|
||||
* Old `MainButton.onClick` extension **has been removed** to avoid collisions of types
|
||||
|
||||
## 15.1.0
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||
|
||||
@@ -4689,7 +4689,12 @@ public abstract interface class dev/inmo/tgbotapi/requests/send/SendLocation : d
|
||||
public abstract fun method ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/requests/send/SendLocation$Companion {
|
||||
public final class dev/inmo/tgbotapi/requests/send/SendLocation$Companion : kotlinx/serialization/KSerializer {
|
||||
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/requests/send/SendLocation;
|
||||
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/requests/send/SendLocation;)V
|
||||
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
|
||||
public final fun serializer (Lkotlinx/serialization/KSerializer;)Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
@@ -4702,6 +4707,7 @@ public final class dev/inmo/tgbotapi/requests/send/SendLocation$DefaultImpls {
|
||||
public final class dev/inmo/tgbotapi/requests/send/SendLocation$Live : dev/inmo/tgbotapi/requests/send/SendLocation {
|
||||
public static final field Companion Ldev/inmo/tgbotapi/requests/send/SendLocation$Live$Companion;
|
||||
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;DDILjava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;Ldev/inmo/tgbotapi/types/MessageThreadId;Ljava/lang/String;ZZLjava/lang/String;Ldev/inmo/tgbotapi/types/ReplyParameters;Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;DDILjava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;Ldev/inmo/tgbotapi/types/MessageThreadId;Ljava/lang/String;ZZLjava/lang/String;Ldev/inmo/tgbotapi/types/ReplyParameters;Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun component1 ()Ldev/inmo/tgbotapi/types/ChatIdentifier;
|
||||
public final fun component10 ()Z
|
||||
public final fun component11 ()Z
|
||||
@@ -4760,6 +4766,7 @@ public final class dev/inmo/tgbotapi/requests/send/SendLocation$Live$Companion {
|
||||
public final class dev/inmo/tgbotapi/requests/send/SendLocation$Static : dev/inmo/tgbotapi/requests/send/SendLocation {
|
||||
public static final field Companion Ldev/inmo/tgbotapi/requests/send/SendLocation$Static$Companion;
|
||||
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;DDLdev/inmo/tgbotapi/types/MessageThreadId;Ljava/lang/String;ZZLjava/lang/String;Ldev/inmo/tgbotapi/types/ReplyParameters;Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/ChatIdentifier;DDLdev/inmo/tgbotapi/types/MessageThreadId;Ljava/lang/String;ZZLjava/lang/String;Ldev/inmo/tgbotapi/types/ReplyParameters;Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun component1 ()Ldev/inmo/tgbotapi/types/ChatIdentifier;
|
||||
public final fun component10 ()Ldev/inmo/tgbotapi/types/buttons/KeyboardMarkup;
|
||||
public final fun component2 ()D
|
||||
|
||||
@@ -11,6 +11,9 @@ import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializ
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
@@ -102,7 +105,7 @@ fun SendLiveLocation(
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@Serializable(SendLocation.Companion::class)
|
||||
sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<ContentMessage<T>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<T>>,
|
||||
PositionedSendMessageRequest<ContentMessage<T>>,
|
||||
@@ -113,7 +116,7 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
override fun method(): String = "sendLocation"
|
||||
|
||||
@Serializable
|
||||
data class Live internal constructor(
|
||||
data class Live (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
@@ -121,6 +124,8 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(livePeriodField)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val livePeriod: Seconds = LiveLocation.INDEFINITE_LIVE_PERIOD,
|
||||
@SerialName(horizontalAccuracyField)
|
||||
override val horizontalAccuracy: Meters? = null,
|
||||
@@ -129,8 +134,12 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
@SerialName(proximityAlertRadiusField)
|
||||
override val proximityAlertRadius: Meters? = null,
|
||||
@SerialName(messageThreadIdField)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val threadId: MessageThreadId? = chatId.threadId,
|
||||
@SerialName(businessConnectionIdField)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@@ -146,7 +155,7 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LiveLocationContent>>
|
||||
get() = liveResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = Live.serializer()
|
||||
get() = serializer()
|
||||
|
||||
init {
|
||||
if (livePeriod !in livePeriodLimit) {
|
||||
@@ -159,7 +168,7 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Static internal constructor(
|
||||
data class Static (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
@@ -167,8 +176,12 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
@SerialName(longitudeField)
|
||||
override val longitude: Double,
|
||||
@SerialName(messageThreadIdField)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val threadId: MessageThreadId? = chatId.threadId,
|
||||
@SerialName(businessConnectionIdField)
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@EncodeDefault
|
||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@@ -194,4 +207,98 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
companion object : KSerializer<SendLocation<*>> {
|
||||
@Serializable
|
||||
private class Surrogate(
|
||||
@SerialName(chatIdField)
|
||||
val chatId: ChatIdentifier,
|
||||
@SerialName(latitudeField)
|
||||
val latitude: Double,
|
||||
@SerialName(longitudeField)
|
||||
val longitude: Double,
|
||||
@SerialName(livePeriodField)
|
||||
val livePeriod: Seconds? = null,
|
||||
@SerialName(horizontalAccuracyField)
|
||||
val horizontalAccuracy: Meters? = null,
|
||||
@SerialName(headingField)
|
||||
val heading: Degrees? = null,
|
||||
@SerialName(proximityAlertRadiusField)
|
||||
val proximityAlertRadius: Meters? = null,
|
||||
@SerialName(messageThreadIdField)
|
||||
val threadId: MessageThreadId? = chatId.threadId,
|
||||
@SerialName(businessConnectionIdField)
|
||||
val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@SerialName(disableNotificationField)
|
||||
val disableNotification: Boolean = false,
|
||||
@SerialName(protectContentField)
|
||||
val protectContent: Boolean = false,
|
||||
@SerialName(messageEffectIdField)
|
||||
val effectId: EffectId? = null,
|
||||
@SerialName(replyParametersField)
|
||||
val replyParameters: ReplyParameters? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
val replyMarkup: KeyboardMarkup? = null
|
||||
)
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = Surrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): SendLocation<*> {
|
||||
val surrogate = Surrogate.serializer().deserialize(decoder)
|
||||
|
||||
return when (surrogate.livePeriod) {
|
||||
null -> Static(
|
||||
chatId = surrogate.chatId,
|
||||
latitude = surrogate.latitude,
|
||||
longitude = surrogate.longitude,
|
||||
threadId = surrogate.threadId,
|
||||
businessConnectionId = surrogate.businessConnectionId,
|
||||
disableNotification = surrogate.disableNotification,
|
||||
protectContent = surrogate.protectContent,
|
||||
effectId = surrogate.effectId,
|
||||
replyParameters = surrogate.replyParameters,
|
||||
replyMarkup = surrogate.replyMarkup
|
||||
)
|
||||
else -> Live(
|
||||
chatId = surrogate.chatId,
|
||||
latitude = surrogate.latitude,
|
||||
longitude = surrogate.longitude,
|
||||
livePeriod = surrogate.livePeriod,
|
||||
horizontalAccuracy = surrogate.horizontalAccuracy,
|
||||
heading = surrogate.heading,
|
||||
proximityAlertRadius = surrogate.proximityAlertRadius,
|
||||
threadId = surrogate.threadId,
|
||||
businessConnectionId = surrogate.businessConnectionId,
|
||||
disableNotification = surrogate.disableNotification,
|
||||
protectContent = surrogate.protectContent,
|
||||
effectId = surrogate.effectId,
|
||||
replyParameters = surrogate.replyParameters,
|
||||
replyMarkup = surrogate.replyMarkup
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: SendLocation<*>) {
|
||||
val surrogate = with(value) {
|
||||
Surrogate(
|
||||
chatId = chatId,
|
||||
latitude = latitude,
|
||||
longitude = longitude,
|
||||
livePeriod = livePeriod,
|
||||
horizontalAccuracy = horizontalAccuracy,
|
||||
heading = heading,
|
||||
proximityAlertRadius = proximityAlertRadius,
|
||||
threadId = threadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
effectId = effectId,
|
||||
replyParameters = replyParameters,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
}
|
||||
Surrogate.serializer().serialize(encoder, surrogate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,11 @@ external class MainButton {
|
||||
fun showProgress(leaveActive: Boolean = definedExternally): MainButton
|
||||
fun hideProgress(): MainButton
|
||||
|
||||
internal fun onClick(eventHandler: () -> Unit): MainButton
|
||||
internal fun offClick(eventHandler: () -> Unit): MainButton
|
||||
/**
|
||||
* **This method argument do not accept `this` [WebApp] object**
|
||||
*/
|
||||
fun onClick(eventHandler: () -> Unit): MainButton
|
||||
fun offClick(eventHandler: () -> Unit): MainButton
|
||||
|
||||
internal fun setParams(params: Json): MainButton
|
||||
}
|
||||
@@ -36,11 +39,6 @@ data class MainButtonParams(
|
||||
val isVisible: Boolean? = null
|
||||
)
|
||||
|
||||
fun MainButton.onClick(eventHandler: EventHandler) = onClick {
|
||||
val that = js("this").unsafeCast<WebApp>()
|
||||
that.eventHandler()
|
||||
}
|
||||
|
||||
fun MainButton.setParams(params: MainButtonParams) = setParams(
|
||||
json(
|
||||
*listOfNotNull(
|
||||
|
||||
Reference in New Issue
Block a user