From ad453afba2142581b935295ad538ad373f22702c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Aug 2022 18:55:08 +0600 Subject: [PATCH 1/8] start 3.1.1 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6fcaa13d5..9a516fc1b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 3.1.1 + ## 3.1.0 **This update contains including of Bot API 6.2** diff --git a/gradle.properties b/gradle.properties index 6ca3ff5cb4..c0a1d7b5fe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=3.1.0 +library_version=3.1.1 From d4fe4e09fcdfe63e444df73118d7ffc2fb79aca7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Aug 2022 21:52:26 +0600 Subject: [PATCH 2/8] add support of Bot API 6.2 in webapp parts --- .../inmo/tgbotapi/webapps/AlertCallback.kt | 3 ++ .../inmo/tgbotapi/webapps/ConfirmCallback.kt | 3 ++ .../dev/inmo/tgbotapi/webapps/EventHandler.kt | 1 + .../dev/inmo/tgbotapi/webapps/EventType.kt | 1 + .../dev/inmo/tgbotapi/webapps/WebApp.kt | 29 ++++++++++++ .../dev/inmo/tgbotapi/webapps/WebAppUser.kt | 4 ++ .../webapps/popup/ClosePopupCallback.kt | 3 ++ .../tgbotapi/webapps/popup/PopupButton.kt | 45 +++++++++++++++++++ .../tgbotapi/webapps/popup/PopupParams.kt | 36 +++++++++++++++ 9 files changed, 125 insertions(+) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AlertCallback.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ConfirmCallback.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ClosePopupCallback.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AlertCallback.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AlertCallback.kt new file mode 100644 index 0000000000..8ed7e55b60 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AlertCallback.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps + +typealias AlertCallback = () -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ConfirmCallback.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ConfirmCallback.kt new file mode 100644 index 0000000000..4c9f85296b --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ConfirmCallback.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps + +typealias ConfirmCallback = (confirmed: Boolean) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt index e0e5dc7f37..f83d2fd7dc 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt @@ -5,3 +5,4 @@ import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo typealias EventHandler = WebApp.() -> Unit typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit +typealias PopupClosedEventHandler = WebApp.(String?) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt index a75b20218c..ff71329074 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt @@ -7,4 +7,5 @@ sealed class EventType(val typeName: String) { object BackButtonClicked : EventType("backButtonClicked") object SettingsButtonClicked : EventType("settingsButtonClicked") object InvoiceClosed : EventType("invoiceClosed") + object PopupClosed : EventType("popupClosed") } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index 365d07af4b..f983b5d4e4 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -3,6 +3,8 @@ package dev.inmo.tgbotapi.webapps import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo +import dev.inmo.tgbotapi.webapps.popup.ClosePopupCallback +import dev.inmo.tgbotapi.webapps.popup.PopupParams external class WebApp { val version: String @@ -24,6 +26,15 @@ external class WebApp { val viewportHeight: Float val viewportStableHeight: Float + + val isClosingConfirmationEnabled: Boolean + fun enableClosingConfirmation() + fun disableClosingConfirmation() + + fun showPopup(params: PopupParams, callback: ClosePopupCallback? = definedExternally) + fun showAlert(message: String, callback: AlertCallback? = definedExternally) + fun showConfirm(message: String, callback: ConfirmCallback? = definedExternally) + @JsName("MainButton") val mainButton: MainButton @@ -38,6 +49,8 @@ external class WebApp { internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit) @JsName("onEvent") internal fun onEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit) + @JsName("onEvent") + internal fun onEventWithPopupClosedInfo(type: String, callback: (String?) -> Unit) fun offEvent(type: String, callback: () -> Unit) @JsName("offEvent") @@ -100,6 +113,18 @@ fun WebApp.onEvent(type: EventType.InvoiceClosed, eventHandler: InvoiceClosedEve ) } +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onEvent(type: EventType.PopupClosed, eventHandler: PopupClosedEventHandler) = { it: String? -> + eventHandler(js("this").unsafeCast(), it) +}.also { + onEventWithPopupClosedInfo( + type.typeName, + callback = it + ) +} + /** * @return The callback which should be used in case you want to turn off events handling */ @@ -124,6 +149,10 @@ fun WebApp.onSettingsButtonClicked(eventHandler: EventHandler) = onEvent(EventTy * @return The callback which should be used in case you want to turn off events handling */ fun WebApp.onInvoiceClosed(eventHandler: InvoiceClosedEventHandler) = onEvent(EventType.InvoiceClosed, eventHandler) +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onPopupClosed(eventHandler: PopupClosedEventHandler) = onEvent(EventType.PopupClosed, eventHandler) fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData( initData, diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt index 92f7b87fd2..d2d7a1237b 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt @@ -17,10 +17,14 @@ external interface WebAppUser { val username: String? @JsName(languageCodeField) val languageCode: String? + val is_premium: Boolean? @JsName(photoUrlField) val photoUrl: String? } +val WebAppUser.isPremium + get() = is_premium == true + fun WebAppUser.asUser() = if (isBot == true) { CommonBot( UserId(id), diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ClosePopupCallback.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ClosePopupCallback.kt new file mode 100644 index 0000000000..17727bef69 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ClosePopupCallback.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps.popup + +typealias ClosePopupCallback = (id: String) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt new file mode 100644 index 0000000000..65f2513ef1 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt @@ -0,0 +1,45 @@ +package dev.inmo.tgbotapi.webapps.popup + +external class PopupButton( + id: String, + type: String, + text: String? = definedExternally +) { + val id: String + val type: String + val text: String? +} + +value class PopupButtonType( + val typeName: String +) { + companion object { + val Default = PopupButtonType("default") + val Ok = PopupButtonType("ok") + val Close = PopupButtonType("close") + val Cancel = PopupButtonType("cancel") + val Destructive = PopupButtonType("destructive") + } +} + +fun DefaultPopupButton( + id: String, + text: String +) = PopupButton(id, PopupButtonType.Default.typeName, text) + +fun OkPopupButton( + id: String +) = PopupButton(id, PopupButtonType.Ok.typeName) + +fun ClosePopupButton( + id: String +) = PopupButton(id, PopupButtonType.Close.typeName) + +fun CancelPopupButton( + id: String +) = PopupButton(id, PopupButtonType.Cancel.typeName) + +fun DestructivePopupButton( + id: String, + text: String +) = PopupButton(id, PopupButtonType.Destructive.typeName, text) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt new file mode 100644 index 0000000000..42f00aac22 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt @@ -0,0 +1,36 @@ +package dev.inmo.tgbotapi.webapps.popup + +external class PopupParams( + message: String, + title: String?, + buttons: Array +) { + val title: String? +} + +fun PopupParams( + message: String, + firstButton: PopupButton, + vararg otherButtons: PopupButton +) = PopupParams( + message, + null, + arrayOf( + firstButton, + *otherButtons + ) +) + +fun PopupParams( + title: String, + message: String, + firstButton: PopupButton, + vararg otherButtons: PopupButton +) = PopupParams( + message, + title, + arrayOf( + firstButton, + *otherButtons + ) +) From e10caa31714a15891551cc5afd0fbc278546fb63 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Aug 2022 21:56:25 +0600 Subject: [PATCH 3/8] add support of has_restricted_voice_and_video_messages --- .../src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 4 +++- .../kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 103f327380..0e1cf5f246 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -164,6 +164,7 @@ const val languageCodeField = "language_code" const val addedToAttachmentMenuField = "added_to_attachment_menu" const val isPremiumField = "is_premium" const val hasPrivateForwardsField = "has_private_forwards" +const val hasRestrictedVoiceAndVideoMessagesField = "has_restricted_voice_and_video_messages" const val canJoinGroupsField = "can_join_groups" const val canReadAllGroupMessagesField = "can_read_all_group_messages" const val supportInlineQueriesField = "supports_inline_queries" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index fed027677d..8a9b65a97d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -62,7 +62,9 @@ data class ExtendedPrivateChatImpl( @SerialName(bioField) override val bio: String = "", @SerialName(hasPrivateForwardsField) - override val hasPrivateForwards: Boolean = false + override val hasPrivateForwards: Boolean = false, + @SerialName(hasRestrictedVoiceAndVideoMessagesField) + override val hasRestrictedVoiceAndVideoMessages: Boolean ) : ExtendedPrivateChat typealias ExtendedUser = ExtendedPrivateChatImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index 26cf8115ae..6705d8203d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -19,6 +19,7 @@ sealed interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChat { val bio: String val hasPrivateForwards: Boolean + val hasRestrictedVoiceAndVideoMessages: Boolean val allowCreateUserIdLink: Boolean get() = hasPrivateForwards From e8a3b9383174e2465caa486a798ef041bc925104 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Aug 2022 22:11:55 +0600 Subject: [PATCH 4/8] Update Extended.kt --- .../commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 8a9b65a97d..01ead1be28 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -64,7 +64,7 @@ data class ExtendedPrivateChatImpl( @SerialName(hasPrivateForwardsField) override val hasPrivateForwards: Boolean = false, @SerialName(hasRestrictedVoiceAndVideoMessagesField) - override val hasRestrictedVoiceAndVideoMessages: Boolean + override val hasRestrictedVoiceAndVideoMessages: Boolean = false ) : ExtendedPrivateChat typealias ExtendedUser = ExtendedPrivateChatImpl From 69dde19543f5646d7cb5b502d316e6d4d548b9e4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Aug 2022 22:13:03 +0600 Subject: [PATCH 5/8] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a516fc1b5..bf70590d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 3.1.1 +* `Common`: + * Complete Bot API 6.2 implementation + ## 3.1.0 **This update contains including of Bot API 6.2** From a08d07f7b3fcb2752643f39334c515d08e1c1f2a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 15 Aug 2022 01:20:29 +0600 Subject: [PATCH 6/8] fixes in popup params and buttons --- .../dev/inmo/tgbotapi/webapps/WebApp.kt | 32 +++++++++++++++++-- .../tgbotapi/webapps/popup/PopupButton.kt | 32 ++++++++++++------- .../tgbotapi/webapps/popup/PopupParams.kt | 20 +++++++++--- 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index f983b5d4e4..6fa55a23af 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -3,8 +3,7 @@ package dev.inmo.tgbotapi.webapps import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo -import dev.inmo.tgbotapi.webapps.popup.ClosePopupCallback -import dev.inmo.tgbotapi.webapps.popup.PopupParams +import dev.inmo.tgbotapi.webapps.popup.* external class WebApp { val version: String @@ -158,3 +157,32 @@ fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).ch initData, initDataUnsafe.hash ) + +fun WebApp.showPopup( + message: String, + title: String?, + buttons: Array, + callback: ClosePopupCallback? = null +) = showPopup( + PopupParams( + message, + title, + buttons + ), + callback +) + +fun WebApp.showPopup( + message: String, + title: String?, + firstButton: PopupButton, + vararg otherButtons: PopupButton, + callback: ClosePopupCallback? = null +) = showPopup( + PopupParams( + message, + title, + arrayOf(firstButton, *otherButtons) + ), + callback +) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt index 65f2513ef1..992a70c1cb 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupButton.kt @@ -1,15 +1,25 @@ package dev.inmo.tgbotapi.webapps.popup -external class PopupButton( - id: String, - type: String, - text: String? = definedExternally -) { +import kotlin.js.json + +external interface PopupButton { val id: String - val type: String + val type: PopupButtonType val text: String? } +fun PopupButton( + id: String, + type: PopupButtonType, + text: String? = null +) = json( + *listOfNotNull( + "id" to id, + "type" to type.typeName, + ("text" to text).takeIf { text != null } + ).toTypedArray() +).unsafeCast() + value class PopupButtonType( val typeName: String ) { @@ -25,21 +35,21 @@ value class PopupButtonType( fun DefaultPopupButton( id: String, text: String -) = PopupButton(id, PopupButtonType.Default.typeName, text) +) = PopupButton(id, PopupButtonType.Default, text) fun OkPopupButton( id: String -) = PopupButton(id, PopupButtonType.Ok.typeName) +) = PopupButton(id, PopupButtonType.Ok) fun ClosePopupButton( id: String -) = PopupButton(id, PopupButtonType.Close.typeName) +) = PopupButton(id, PopupButtonType.Close) fun CancelPopupButton( id: String -) = PopupButton(id, PopupButtonType.Cancel.typeName) +) = PopupButton(id, PopupButtonType.Cancel) fun DestructivePopupButton( id: String, text: String -) = PopupButton(id, PopupButtonType.Destructive.typeName, text) +) = PopupButton(id, PopupButtonType.Destructive, text) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt index 42f00aac22..8fe40507cb 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/PopupParams.kt @@ -1,12 +1,24 @@ package dev.inmo.tgbotapi.webapps.popup -external class PopupParams( +import kotlin.js.json + +external interface PopupParams { + val message: String + val title: String? + val buttons: Array +} + +fun PopupParams( message: String, title: String?, buttons: Array -) { - val title: String? -} +) = json( + *listOfNotNull( + "message" to message, + "buttons" to buttons, + ("title" to title).takeIf { title != null } + ).toTypedArray() +).unsafeCast() fun PopupParams( message: String, From 78c224ffa85d5259937416f9938f4d629ec31dc7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 15 Aug 2022 01:21:10 +0600 Subject: [PATCH 7/8] fix on asUser fun --- .../src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt index d2d7a1237b..facd42061e 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppUser.kt @@ -38,6 +38,7 @@ fun WebAppUser.asUser() = if (isBot == true) { firstName, lastName ?: "", username ?.let(::Username), - languageCode ?.let(::IetfLanguageCode) + languageCode ?.let(::IetfLanguageCode), + isPremium = isPremium ) } From be7aaa784513509a347ebf9e4a99fbf49f9ff19f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 15 Aug 2022 01:29:24 +0600 Subject: [PATCH 8/8] fixes and improvements in webapps --- .../kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index 6fa55a23af..d31d1d6cf9 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -186,3 +186,17 @@ fun WebApp.showPopup( ), callback ) + +var WebApp.requireClosingConfirmation + get() = isClosingConfirmationEnabled + set(value) { + if (value) { + enableClosingConfirmation() + } else { + disableClosingConfirmation() + } + } + +fun WebApp.toggleClosingConfirmation() { + requireClosingConfirmation = !requireClosingConfirmation +}