From 1c6359f041c7c931ce4052a6c9de666730d40403 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Dec 2024 09:41:31 +0600 Subject: [PATCH] add a lot of things in web apps --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 6 ++++++ .../inmo/tgbotapi/webapps/HomeScreenStatus.kt | 8 ++++++++ .../kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 17 +++++++++++++++++ .../dev/inmo/tgbotapi/webapps/WebAppInitData.kt | 15 ++++++++++++--- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/HomeScreenStatus.kt 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 f333ce0ee4..8f63bf469c 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 @@ -40,6 +40,12 @@ value class GiftId( val string: String ) +@Serializable +@JvmInline +value class PreparedMessageId( + val string: String +) + val usernameRegex = Regex("@[\\w\\d_]+") val degreesLimit = 1 .. 360 diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/HomeScreenStatus.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/HomeScreenStatus.kt new file mode 100644 index 0000000000..e39ca9f371 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/HomeScreenStatus.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.webapps + +enum class HomeScreenStatus(val value: String) { + Unsupported("unsupported"), + Unknown("unknown"), + Added("added"), + Missed("missed"), +} 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 c782c821cd..1f8ad2407c 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 @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.webapps +import dev.inmo.tgbotapi.types.MessageId +import dev.inmo.tgbotapi.types.PreparedMessageId import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.webapps.biometric.BiometricManager import dev.inmo.tgbotapi.webapps.cloud.CloudStorage @@ -13,6 +15,8 @@ external class WebApp { val platform: String + val isActive: Boolean + val initData: String val initDataUnsafe: WebAppInitData @@ -52,6 +56,19 @@ external class WebApp { fun closeScanQrPopup() fun readTextFromClipboard(callback: TextReceivedCallback? = definedExternally) + val isFullscreen: Boolean + fun requestFullscreen() + fun exitFullscreen() + + val isOrientationLocked: Boolean + fun lockOrientation() + fun unlockOrientation() + + fun addToHomeScreen() + fun checkHomeScreenStatus(callback: (HomeScreenStatus) -> Unit = definedExternally) + + fun shareMessage(messageId: PreparedMessageId, callback: (Boolean) -> Unit = definedExternally) + @JsName("MainButton") val mainButton: BottomButton @JsName("SecondaryButton") diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt index 78c7528233..960a4360e5 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.webapps import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.ChatType external interface WebAppInitData { @JsName("query_id") @@ -9,6 +10,14 @@ external interface WebAppInitData { val user: WebAppUser? val receiver: WebAppUser? + val chat: WebAppChat + + @JsName("chat_type") + val chatType: ChatType? + + @JsName("chat_instance") + val chatInstance: String? + @JsName("start_param") val startParam: String? @@ -16,9 +25,9 @@ external interface WebAppInitData { val authDate: MilliSeconds @JsName("can_send_after") - val canSendAfter: MilliSeconds - - val chat: WebAppChat + val canSendAfter: MilliSeconds? val hash: String + + val signature: String }