From 8ca86b1e14c9f3c7faccda7aa6796cf81943584b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 16 Mar 2024 22:40:42 +0600 Subject: [PATCH] RawChatId as value class --- CHANGELOG.md | 1 + tgbotapi.core/api/tgbotapi.core.api | 54 +++++++++++++++---- .../inmo/tgbotapi/types/CallbackQueryId.kt | 6 ++- .../dev/inmo/tgbotapi/types/ChatIdentifier.kt | 33 ++++++------ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 - .../inmo/tgbotapi/types/InlineMessageId.kt | 6 ++- .../dev/inmo/tgbotapi/types/InlineQueryId.kt | 6 ++- .../dev/inmo/tgbotapi/types/MediaGroupId.kt | 6 ++- .../dev/inmo/tgbotapi/types/MessageId.kt | 6 ++- .../inmo/tgbotapi/types/MessageThreadId.kt | 6 ++- .../inmo/tgbotapi/types/PreCheckoutQueryId.kt | 6 ++- .../dev/inmo/tgbotapi/types/RawChatId.kt | 20 +++++++ ...gQueryIdentifier.kt => ShippingQueryId.kt} | 6 ++- .../dev/inmo/tgbotapi/types/TgFileUniqueId.kt | 6 ++- .../dev/inmo/tgbotapi/types/UpdateId.kt | 4 ++ .../dev/inmo/tgbotapi/types/WebAppQueryId.kt | 6 ++- .../textsources/TextMentionTextSource.kt | 8 +-- .../inmo/tgbotapi/types/polls/PollAnswer.kt | 2 +- .../tgbotapi/types/ChatIdentifierTests.kt | 8 +-- .../ChatEvents/MigratedToSupergroupTest.kt | 3 +- tgbotapi.utils/api/tgbotapi.utils.api | 8 +-- .../utils/formatting/LinksFormatting.kt | 4 +- tgbotapi.webapps/api/tgbotapi.webapps.api | 0 .../dev/inmo/tgbotapi/webapps/WebAppUser.kt | 2 +- 24 files changed, 153 insertions(+), 55 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/{ShippingQueryIdentifier.kt => ShippingQueryId.kt} (69%) create mode 100644 tgbotapi.webapps/api/tgbotapi.webapps.api diff --git a/CHANGELOG.md b/CHANGELOG.md index bd186077d1..0f8d4ee619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * `UpdateIdentifier` has been renamed to `UpdateId` and now is `value class` * `InlineMessageIdentifier` has been renamed to `InlineMessageId` and now is `value class` * `ShippingQueryIdentifier` has been renamed to `ShippingQueryId` and now is `value class` + * `Identifier` has been renamed to `RawChatId` and now is `value class` ## 10.1.2 diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index e3e869ab7d..63716e5385 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -7165,7 +7165,7 @@ public final class dev/inmo/tgbotapi/types/ChatId : dev/inmo/tgbotapi/types/IdCh public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (JLjava/lang/Object;)Z public static final fun equals-impl0 (JJ)Z - public fun getChatId ()J + public fun getChatId-iyD94Bc ()J public fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId; public static fun getThreadId-S3HF-10 (J)Ldev/inmo/tgbotapi/types/MessageThreadId; public fun hashCode ()I @@ -7187,8 +7187,8 @@ public final class dev/inmo/tgbotapi/types/ChatIdWithThreadId : dev/inmo/tgbotap public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (Lkotlin/Pair;Ljava/lang/Object;)Z public static final fun equals-impl0 (Lkotlin/Pair;Lkotlin/Pair;)Z - public fun getChatId ()J - public static fun getChatId-impl (Lkotlin/Pair;)J + public fun getChatId-iyD94Bc ()J + public static fun getChatId-iyD94Bc (Lkotlin/Pair;)J public final fun getChatIdWithThreadId ()Lkotlin/Pair; public synthetic fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId; public fun getThreadId-hDmiKeI ()J @@ -7217,13 +7217,14 @@ public final class dev/inmo/tgbotapi/types/ChatIdentifierKt { public static final field internalTgAppLinksBeginning Ljava/lang/String; public static final field internalUserLinkBeginning Ljava/lang/String; public static final fun getThreadId (Ldev/inmo/tgbotapi/types/ChatIdentifier;)Ldev/inmo/tgbotapi/types/MessageThreadId; - public static final fun getUserLink (J)Ljava/lang/String; public static final fun getUserLink (Ldev/inmo/tgbotapi/types/chat/User;)Ljava/lang/String; + public static final fun getUserLink-0218hRU (J)Ljava/lang/String; public static final fun getUserLink-HZVsHAI (J)Ljava/lang/String; public static final fun toChatId (B)Ldev/inmo/tgbotapi/types/IdChatIdentifier; public static final fun toChatId (I)Ldev/inmo/tgbotapi/types/IdChatIdentifier; public static final fun toChatId (J)J public static final fun toChatId (Ldev/inmo/tgbotapi/types/IdChatIdentifier;)J + public static final fun toChatId-0218hRU (J)J public static final fun toChatWithThreadId-krPZAoY (Ldev/inmo/tgbotapi/types/IdChatIdentifier;J)Ldev/inmo/tgbotapi/types/IdChatIdentifier; public static final fun toUsername (Ljava/lang/String;)Ljava/lang/String; } @@ -8047,13 +8048,13 @@ public final class dev/inmo/tgbotapi/types/FullChatIdentifierSerializer : kotlin public abstract interface class dev/inmo/tgbotapi/types/IdChatIdentifier : dev/inmo/tgbotapi/types/ChatIdentifier { public static final field Companion Ldev/inmo/tgbotapi/types/IdChatIdentifier$Companion; - public abstract fun getChatId ()J + public abstract fun getChatId-iyD94Bc ()J public abstract fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId; } public final class dev/inmo/tgbotapi/types/IdChatIdentifier$Companion { - public final fun invoke-0UUUZLM (J)J - public final fun invoke-zFai7VQ (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ldev/inmo/tgbotapi/types/IdChatIdentifier; + public final fun invoke-0PTMirw (J)J + public final fun invoke-FNqv5JM (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ldev/inmo/tgbotapi/types/IdChatIdentifier; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -10113,6 +10114,37 @@ public final class dev/inmo/tgbotapi/types/PrimaryInviteLink$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class dev/inmo/tgbotapi/types/RawChatId { + public static final field Companion Ldev/inmo/tgbotapi/types/RawChatId$Companion; + public static final synthetic fun box-impl (J)Ldev/inmo/tgbotapi/types/RawChatId; + public static fun constructor-impl (J)J + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (JLjava/lang/Object;)Z + public static final fun equals-impl0 (JJ)Z + public final fun getLong ()J + public fun hashCode ()I + public static fun hashCode-impl (J)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (J)Ljava/lang/String; + public final synthetic fun unbox-impl ()J +} + +public final class dev/inmo/tgbotapi/types/RawChatId$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/RawChatId$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize-CjSOdp4 (Lkotlinx/serialization/encoding/Decoder;)J + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize-tJfg6EE (Lkotlinx/serialization/encoding/Encoder;J)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/RawChatId$Companion { + public final fun getDefaultUserId-iyD94Bc ()J + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public abstract interface class dev/inmo/tgbotapi/types/ReplyInfo { public abstract fun getMessageMeta-0CjidFs ()Lkotlin/Triple; } @@ -19795,17 +19827,17 @@ public final class dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSo } public final class dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSourceKt { - public static final fun mention (JLjava/lang/String;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; - public static final fun mention (JLjava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention (Ldev/inmo/tgbotapi/types/chat/User;Ljava/lang/String;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention (Ldev/inmo/tgbotapi/types/chat/User;Ljava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention (Ldev/inmo/tgbotapi/types/chat/User;[Ldev/inmo/tgbotapi/types/message/textsources/TextSource;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; - public static final fun mention (Ljava/lang/String;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention (Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/User;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; - public static final fun mention (Ljava/util/List;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention (Ljava/util/List;Ldev/inmo/tgbotapi/types/chat/User;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention-WiG6Fm4 (Ljava/lang/String;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention-WiG6Fm4 (Ljava/util/List;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; + public static final fun mention-tJfg6EE (Ljava/lang/String;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; + public static final fun mention-tJfg6EE (Ljava/util/List;J)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; + public static final fun mention-tafjJLY (JLjava/lang/String;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; + public static final fun mention-tafjJLY (JLjava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention-zv9neSE (JLjava/lang/String;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; public static final fun mention-zv9neSE (JLjava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource; } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQueryId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQueryId.kt index bfc45ac9a8..00943a7bdb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQueryId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQueryId.kt @@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline @JvmInline value class CallbackQueryId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated("Renamed", ReplaceWith("CallbackQueryId", "dev.inmo.tgbotapi.types.CallbackQueryId")) typealias CallbackQueryIdentifier = CallbackQueryId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 04220d6efa..6886e18f1b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -26,13 +26,13 @@ sealed interface ChatIdentifier */ @Serializable(ChatIdentifierSerializer::class) sealed interface IdChatIdentifier : ChatIdentifier { - abstract val chatId: Identifier + abstract val chatId: RawChatId val threadId: MessageThreadId? get() = null companion object { - operator fun invoke(chatId: Identifier) = ChatId(chatId) - operator fun invoke(chatId: Identifier, threadId: MessageThreadId?) = threadId ?.let { + operator fun invoke(chatId: RawChatId) = ChatId(chatId) + operator fun invoke(chatId: RawChatId, threadId: MessageThreadId?) = threadId ?.let { ChatIdWithThreadId(chatId, threadId) } ?: ChatId(chatId) } @@ -40,17 +40,17 @@ sealed interface IdChatIdentifier : ChatIdentifier { @Serializable(ChatIdentifierSerializer::class) @JvmInline -value class ChatId(override val chatId: Identifier) : IdChatIdentifier +value class ChatId(override val chatId: RawChatId) : IdChatIdentifier @Serializable(ChatIdentifierSerializer::class) @JvmInline -value class ChatIdWithThreadId(val chatIdWithThreadId: Pair) : IdChatIdentifier { - override val chatId: Identifier +value class ChatIdWithThreadId(val chatIdWithThreadId: Pair) : IdChatIdentifier { + override val chatId: RawChatId get() = chatIdWithThreadId.first override val threadId: MessageThreadId get() = chatIdWithThreadId.second - constructor(chatId: Identifier, threadId: MessageThreadId): this(chatId to threadId) + constructor(chatId: RawChatId, threadId: MessageThreadId): this(chatId to threadId) } val ChatIdentifier.threadId: MessageThreadId? @@ -67,7 +67,7 @@ fun IdChatIdentifier.toChatWithThreadId(threadId: MessageThreadId) = IdChatIdent * https://core.telegram.org/bots/api#formatting-options */ @Warning("This API have restrictions in Telegram System") -val Identifier.userLink: String +val RawChatId.userLink: String get() = "$internalUserLinkBeginning$this" /** * https://core.telegram.org/bots/api#formatting-options @@ -80,9 +80,10 @@ val User.userLink: String typealias UserId = ChatId -fun Identifier.toChatId(): ChatId = ChatId(this) -fun Int.toChatId(): IdChatIdentifier = toLong().toChatId() -fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId() +fun RawChatId.toChatId(): ChatId = ChatId(this) +fun Long.toChatId(): ChatId = ChatId(RawChatId(this)) +fun Int.toChatId(): IdChatIdentifier = RawChatId(toLong()).toChatId() +fun Byte.toChatId(): IdChatIdentifier = RawChatId(toLong()).toChatId() @Serializable(ChatIdentifierSerializer::class) @JvmInline @@ -115,7 +116,7 @@ object ChatIdentifierSerializer : KSerializer { val id = internalSerializer.deserialize(decoder) return id.longOrNull ?.let { - ChatId(it) + ChatId(RawChatId(it)) } ?: id.content.let { if (!it.startsWith("@")) { Username("@$it") @@ -127,7 +128,7 @@ object ChatIdentifierSerializer : KSerializer { override fun serialize(encoder: Encoder, value: ChatIdentifier) { when (value) { - is IdChatIdentifier -> encoder.encodeLong(value.chatId) + is IdChatIdentifier -> encoder.encodeLong(value.chatId.long) is Username -> encoder.encodeString(value.full) } } @@ -141,13 +142,13 @@ object FullChatIdentifierSerializer : KSerializer { val id = internalSerializer.deserialize(decoder) return id.longOrNull ?.let { - ChatId(it) + ChatId(RawChatId(it)) } ?:let { val splitted = id.content.split("/") if (splitted.size == 2) { val (chatId, threadId) = splitted ChatIdWithThreadId( - chatId.toLongOrNull() ?: return@let null, + chatId.toLongOrNull() ?.let(::RawChatId) ?: return@let null, threadId.toLongOrNull() ?.let(::MessageThreadId) ?: return@let null ) } else { @@ -164,7 +165,7 @@ object FullChatIdentifierSerializer : KSerializer { override fun serialize(encoder: Encoder, value: ChatIdentifier) { when (value) { - is ChatId -> encoder.encodeLong(value.chatId) + is ChatId -> encoder.encodeLong(value.chatId.long) is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}") is Username -> encoder.encodeString(value.full) } 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 008d1b56ea..6c35adb88e 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 @@ -9,7 +9,6 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlin.jvm.JvmInline -typealias Identifier = Long typealias ForwardSignature = String typealias ForwardSenderName = String typealias AuthorSignature = ForwardSignature diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineMessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineMessageId.kt index fa34bb16c3..766949d456 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineMessageId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineMessageId.kt @@ -7,6 +7,10 @@ import kotlin.jvm.JvmInline @JvmInline value class InlineMessageId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated("Renamed", ReplaceWith("InlineMessageId", "dev.inmo.tgbotapi.types.InlineMessageId")) typealias InlineMessageIdentifier = InlineMessageId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueryId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueryId.kt index f56330a1ba..333bc75e65 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueryId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueryId.kt @@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline @JvmInline value class InlineQueryId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated("Renamed", ReplaceWith("InlineQueryId", "dev.inmo.tgbotapi.types.InlineQueryId")) typealias InlineQueryIdentifier = InlineQueryId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MediaGroupId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MediaGroupId.kt index e70fa244c5..199b146135 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MediaGroupId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MediaGroupId.kt @@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline @JvmInline value class MediaGroupId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated("Renamed", ReplaceWith("MediaGroupId", "dev.inmo.tgbotapi.types.MediaGroupId")) typealias MediaGroupIdentifier = MediaGroupId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt index 710d200709..8ff441e44d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt @@ -29,7 +29,11 @@ object MessageIdSerializer : KSerializer { @JvmInline value class MessageId( val long: Long -) +) { + override fun toString(): String { + return long.toString() + } +} fun Long.asTelegramMessageId() = MessageId(this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageThreadId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageThreadId.kt index bdf55882c4..134be8f10f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageThreadId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageThreadId.kt @@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline @JvmInline value class MessageThreadId( val long: Long -) +) { + override fun toString(): String { + return long.toString() + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/PreCheckoutQueryId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/PreCheckoutQueryId.kt index ea3b88dc24..d40610d05c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/PreCheckoutQueryId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/PreCheckoutQueryId.kt @@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline @JvmInline value class PreCheckoutQueryId( val string: String -) \ No newline at end of file +) { + override fun toString(): String { + return string + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt new file mode 100644 index 0000000000..e8ccc5a40b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/RawChatId.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline + +@Serializable +@JvmInline +value class RawChatId( + val long: Long +) { + companion object { + val DefaultUserId = RawChatId(136817688L) // I do not know why, it is Telegram crutch + } + + override fun toString(): String { + return long.toString() + } +} +@Deprecated("Renamed", ReplaceWith("RawChatId", "dev.inmo.tgbotapi.types.RawChatId")) +typealias Identifier = RawChatId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryId.kt similarity index 69% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryIdentifier.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryId.kt index 3108fb6963..fd903d8b6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ShippingQueryId.kt @@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline @JvmInline value class ShippingQueryId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated("Renamed", ReplaceWith("ShippingQueryId", "dev.inmo.tgbotapi.types.ShippingQueryId")) typealias ShippingQueryIdentifier = ShippingQueryId \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TgFileUniqueId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TgFileUniqueId.kt index 2e3dfca5c9..886b861789 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TgFileUniqueId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/TgFileUniqueId.kt @@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline @JvmInline value class TgFileUniqueId( val string: String -) +) { + override fun toString(): String { + return string + } +} @Deprecated( "Renamed", ReplaceWith("TgFileUniqueId", "dev.inmo.tgbotapi.types.TgFileUniqueId") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/UpdateId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/UpdateId.kt index 1ee62183d4..9d5a3590b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/UpdateId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/UpdateId.kt @@ -14,6 +14,10 @@ value class UpdateId( override fun compareTo(other: UpdateId): Int { return long.compareTo(other.long) } + + override fun toString(): String { + return long.toString() + } } @Deprecated("Renamed", ReplaceWith("UpdateId", "dev.inmo.tgbotapi.types.UpdateId")) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/WebAppQueryId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/WebAppQueryId.kt index d82f4a360b..8651138594 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/WebAppQueryId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/WebAppQueryId.kt @@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline @JvmInline value class WebAppQueryId( val string: String -) \ No newline at end of file +) { + override fun toString(): String { + return string + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource.kt index e0298aec56..8a47d7c11d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource.kt @@ -31,9 +31,9 @@ inline fun mention(parts: TextSourcesList, userId: UserId) = mention(parts, Comm @Suppress("NOTHING_TO_INLINE") inline fun UserId.mention(parts: TextSourcesList) = mention(parts, this) @Suppress("NOTHING_TO_INLINE") -inline fun mention(parts: TextSourcesList, id: Identifier) = mention(parts, UserId(id)) +inline fun mention(parts: TextSourcesList, id: RawChatId) = mention(parts, UserId(id)) @Suppress("NOTHING_TO_INLINE") -inline fun Identifier.mention(parts: TextSourcesList) = mention(parts, this) +inline fun RawChatId.mention(parts: TextSourcesList) = mention(parts, this) @Suppress("NOTHING_TO_INLINE") inline fun mention(user: User, vararg parts: TextSource) = mention( textSourcesOrElseTextSource(parts.toList()) { @@ -50,6 +50,6 @@ inline fun mention(text: String, userId: UserId) = mention(text, CommonUser(user @Suppress("NOTHING_TO_INLINE") inline fun UserId.mention(text: String) = mention(text, this) @Suppress("NOTHING_TO_INLINE") -inline fun mention(text: String, id: Identifier) = mention(text, UserId(id)) +inline fun mention(text: String, id: RawChatId) = mention(text, UserId(id)) @Suppress("NOTHING_TO_INLINE") -inline fun Identifier.mention(text: String) = mention(text, this) +inline fun RawChatId.mention(text: String) = mention(text, this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt index 644196389e..50822a7ebc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt @@ -43,7 +43,7 @@ sealed interface PollAnswer: FromUser { companion object { val defaultUser = CommonBot( - UserId(136817688L), + UserId(RawChatId.DefaultUserId), "", "", Username("@Channel_Bot") diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt index 98fd148b1e..4ee9e13a07 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt @@ -4,19 +4,19 @@ import dev.inmo.tgbotapi.TestsJsonFormat import kotlinx.serialization.Serializable import kotlin.test.* -private const val chatIdentifierChatId: Identifier = 123L -private const val chatIdentifierLink = "tg://user?id=$chatIdentifierChatId" +private val chatIdentifierChatId: RawChatId = RawChatId(123L) +private val chatIdentifierLink = "tg://user?id=$chatIdentifierChatId" private const val testUsername = "@Example" class ChatIdentifierTests { @Test fun `Cast_from_Int_to_ChatId_is_working_correctly`() { - val chatId = chatIdentifierChatId.toInt().toChatId() + val chatId = chatIdentifierChatId.long.toInt().toChatId() assertEquals(chatIdentifierChatId, chatId.chatId) } @Test fun `Cast_from_Byte_to_ChatId_is_working_correctly`() { - val chatId = chatIdentifierChatId.toByte().toChatId() + val chatId = chatIdentifierChatId.long.toByte().toChatId() assertEquals(chatIdentifierChatId, chatId.chatId) } @Test diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt index d610b9cb28..3d7b4e90f6 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MigratedToSupergroupTest.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents import dev.inmo.tgbotapi.TestsJsonFormat import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.types.IdChatIdentifier +import dev.inmo.tgbotapi.types.RawChatId import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy import kotlin.test.Test import kotlin.test.assertEquals @@ -43,6 +44,6 @@ class MigratedToSupergroupTest { val data = message.data.supergroupEventMessageOrThrow() val event = data.chatEvent.migratedToSupergroupOrThrow() - assertEquals(IdChatIdentifier(57005), event.migratedFrom) + assertEquals(IdChatIdentifier(RawChatId(57005)), event.migratedFrom) } } diff --git a/tgbotapi.utils/api/tgbotapi.utils.api b/tgbotapi.utils/api/tgbotapi.utils.api index a95f43693f..992cd7f221 100644 --- a/tgbotapi.utils/api/tgbotapi.utils.api +++ b/tgbotapi.utils/api/tgbotapi.utils.api @@ -2836,8 +2836,8 @@ public final class dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting public static final fun getUsernameLink-hkcqQtM (Ljava/lang/String;)Ljava/lang/String; public static final fun link-752ER_0 (Ljava/lang/String;Ldev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; public static final fun link-kXE59pw (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; - public static final fun makeChatLink-zFai7VQ (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; - public static synthetic fun makeChatLink-zFai7VQ$default (JLdev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; + public static final fun makeChatLink-FNqv5JM (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; + public static synthetic fun makeChatLink-FNqv5JM$default (JLdev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; public static final fun makeDeepLink-26ZnLnw (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; public static final fun makeInternalTgDeepLink (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; public static final fun makeInternalTgDeepLink-26ZnLnw (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; @@ -2845,10 +2845,10 @@ public final class dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting public static final fun makeInternalTgUsernameLink (Ljava/lang/String;)Ljava/lang/String; public static final fun makeLink-752ER_0 (Ljava/lang/String;Ldev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; public static synthetic fun makeLink-752ER_0$default (Ljava/lang/String;Ldev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; - public static final fun makeLinkToMessage-QEgSB0w (JJLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; public static final fun makeLinkToMessage-QEgSB0w (Ljava/lang/String;JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; - public static synthetic fun makeLinkToMessage-QEgSB0w$default (JJLdev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; public static synthetic fun makeLinkToMessage-QEgSB0w$default (Ljava/lang/String;JLdev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; + public static final fun makeLinkToMessage-XnnF6FI (JJLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; + public static synthetic fun makeLinkToMessage-XnnF6FI$default (JJLdev/inmo/tgbotapi/types/MessageThreadId;ILjava/lang/Object;)Ljava/lang/String; public static final fun makeLinkToMessage-e-HACGs (Ldev/inmo/tgbotapi/types/IdChatIdentifier;J)Ljava/lang/String; public static final fun makeLinkToMessage-e-HACGs (Ldev/inmo/tgbotapi/types/chat/Chat;J)Ljava/lang/String; public static final fun makeLinkToMessage-jfrm6zs (Ljava/lang/String;JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String; diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index a158750400..09c1806c58 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -10,7 +10,7 @@ import io.ktor.http.encodeURLQueryComponent fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}" fun makeInternalTgUsernameLink(username: String) = "${internalTgAppLinksBeginning}resolve?domain=$username" fun makeUserLink(userId: UserId) = userId.userLink -fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = identifier.toString().replace( +fun makeChatLink(identifier: RawChatId, threadId: MessageThreadId? = null) = identifier.toString().replace( linkIdRedundantPartRegex, "" ).let { bareId -> @@ -54,7 +54,7 @@ fun makeLinkToMessage( threadId: MessageThreadId? = null ): String = makeLinkToMessage(username.withoutAt, messageId, threadId) fun makeLinkToMessage( - chatId: Identifier, + chatId: RawChatId, messageId: MessageId, threadId: MessageThreadId? = null ): String = chatId.toString().replace( diff --git a/tgbotapi.webapps/api/tgbotapi.webapps.api b/tgbotapi.webapps/api/tgbotapi.webapps.api new file mode 100644 index 0000000000..e69de29bb2 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 46d834af4c..4df597367a 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 @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.chat.CommonBot import dev.inmo.tgbotapi.types.chat.CommonUser external interface WebAppUser { - val id: Identifier + val id: RawChatId @JsName(isBotField) val isBot: Boolean? @JsName(firstNameField)