1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 08:37:12 +00:00

RawChatId as value class

This commit is contained in:
InsanusMokrassar 2024-03-16 22:40:42 +06:00
parent ffba4e9cef
commit 8ca86b1e14
24 changed files with 153 additions and 55 deletions

View File

@ -16,6 +16,7 @@
* `UpdateIdentifier` has been renamed to `UpdateId` and now is `value class` * `UpdateIdentifier` has been renamed to `UpdateId` and now is `value class`
* `InlineMessageIdentifier` has been renamed to `InlineMessageId` 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` * `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 ## 10.1.2

View File

@ -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 fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (JLjava/lang/Object;)Z public static fun equals-impl (JLjava/lang/Object;)Z
public static final fun equals-impl0 (JJ)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 fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId;
public static fun getThreadId-S3HF-10 (J)Ldev/inmo/tgbotapi/types/MessageThreadId; public static fun getThreadId-S3HF-10 (J)Ldev/inmo/tgbotapi/types/MessageThreadId;
public fun hashCode ()I 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 fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (Lkotlin/Pair;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 static final fun equals-impl0 (Lkotlin/Pair;Lkotlin/Pair;)Z
public fun getChatId ()J public fun getChatId-iyD94Bc ()J
public static fun getChatId-impl (Lkotlin/Pair;)J public static fun getChatId-iyD94Bc (Lkotlin/Pair;)J
public final fun getChatIdWithThreadId ()Lkotlin/Pair; public final fun getChatIdWithThreadId ()Lkotlin/Pair;
public synthetic fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId; public synthetic fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId;
public fun getThreadId-hDmiKeI ()J 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 internalTgAppLinksBeginning Ljava/lang/String;
public static final field internalUserLinkBeginning 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 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 (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 getUserLink-HZVsHAI (J)Ljava/lang/String;
public static final fun toChatId (B)Ldev/inmo/tgbotapi/types/IdChatIdentifier; 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 (I)Ldev/inmo/tgbotapi/types/IdChatIdentifier;
public static final fun toChatId (J)J public static final fun toChatId (J)J
public static final fun toChatId (Ldev/inmo/tgbotapi/types/IdChatIdentifier;)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 toChatWithThreadId-krPZAoY (Ldev/inmo/tgbotapi/types/IdChatIdentifier;J)Ldev/inmo/tgbotapi/types/IdChatIdentifier;
public static final fun toUsername (Ljava/lang/String;)Ljava/lang/String; 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 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 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 abstract fun getThreadId-S3HF-10 ()Ldev/inmo/tgbotapi/types/MessageThreadId;
} }
public final class dev/inmo/tgbotapi/types/IdChatIdentifier$Companion { public final class dev/inmo/tgbotapi/types/IdChatIdentifier$Companion {
public final fun invoke-0UUUZLM (J)J public final fun invoke-0PTMirw (J)J
public final fun invoke-zFai7VQ (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ldev/inmo/tgbotapi/types/IdChatIdentifier; public final fun invoke-FNqv5JM (JLdev/inmo/tgbotapi/types/MessageThreadId;)Ldev/inmo/tgbotapi/types/IdChatIdentifier;
public final fun serializer ()Lkotlinx/serialization/KSerializer; 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 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 interface class dev/inmo/tgbotapi/types/ReplyInfo {
public abstract fun getMessageMeta-0CjidFs ()Lkotlin/Triple; 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 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/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;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 (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/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 (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/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-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/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; public static final fun mention-zv9neSE (JLjava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextMentionTextSource;
} }

View File

@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class CallbackQueryId( value class CallbackQueryId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated("Renamed", ReplaceWith("CallbackQueryId", "dev.inmo.tgbotapi.types.CallbackQueryId")) @Deprecated("Renamed", ReplaceWith("CallbackQueryId", "dev.inmo.tgbotapi.types.CallbackQueryId"))
typealias CallbackQueryIdentifier = CallbackQueryId typealias CallbackQueryIdentifier = CallbackQueryId

View File

@ -26,13 +26,13 @@ sealed interface ChatIdentifier
*/ */
@Serializable(ChatIdentifierSerializer::class) @Serializable(ChatIdentifierSerializer::class)
sealed interface IdChatIdentifier : ChatIdentifier { sealed interface IdChatIdentifier : ChatIdentifier {
abstract val chatId: Identifier abstract val chatId: RawChatId
val threadId: MessageThreadId? val threadId: MessageThreadId?
get() = null get() = null
companion object { companion object {
operator fun invoke(chatId: Identifier) = ChatId(chatId) operator fun invoke(chatId: RawChatId) = ChatId(chatId)
operator fun invoke(chatId: Identifier, threadId: MessageThreadId?) = threadId ?.let { operator fun invoke(chatId: RawChatId, threadId: MessageThreadId?) = threadId ?.let {
ChatIdWithThreadId(chatId, threadId) ChatIdWithThreadId(chatId, threadId)
} ?: ChatId(chatId) } ?: ChatId(chatId)
} }
@ -40,17 +40,17 @@ sealed interface IdChatIdentifier : ChatIdentifier {
@Serializable(ChatIdentifierSerializer::class) @Serializable(ChatIdentifierSerializer::class)
@JvmInline @JvmInline
value class ChatId(override val chatId: Identifier) : IdChatIdentifier value class ChatId(override val chatId: RawChatId) : IdChatIdentifier
@Serializable(ChatIdentifierSerializer::class) @Serializable(ChatIdentifierSerializer::class)
@JvmInline @JvmInline
value class ChatIdWithThreadId(val chatIdWithThreadId: Pair<Identifier, MessageThreadId>) : IdChatIdentifier { value class ChatIdWithThreadId(val chatIdWithThreadId: Pair<RawChatId, MessageThreadId>) : IdChatIdentifier {
override val chatId: Identifier override val chatId: RawChatId
get() = chatIdWithThreadId.first get() = chatIdWithThreadId.first
override val threadId: MessageThreadId override val threadId: MessageThreadId
get() = chatIdWithThreadId.second 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? val ChatIdentifier.threadId: MessageThreadId?
@ -67,7 +67,7 @@ fun IdChatIdentifier.toChatWithThreadId(threadId: MessageThreadId) = IdChatIdent
* https://core.telegram.org/bots/api#formatting-options * https://core.telegram.org/bots/api#formatting-options
*/ */
@Warning("This API have restrictions in Telegram System") @Warning("This API have restrictions in Telegram System")
val Identifier.userLink: String val RawChatId.userLink: String
get() = "$internalUserLinkBeginning$this" get() = "$internalUserLinkBeginning$this"
/** /**
* https://core.telegram.org/bots/api#formatting-options * https://core.telegram.org/bots/api#formatting-options
@ -80,9 +80,10 @@ val User.userLink: String
typealias UserId = ChatId typealias UserId = ChatId
fun Identifier.toChatId(): ChatId = ChatId(this) fun RawChatId.toChatId(): ChatId = ChatId(this)
fun Int.toChatId(): IdChatIdentifier = toLong().toChatId() fun Long.toChatId(): ChatId = ChatId(RawChatId(this))
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId() fun Int.toChatId(): IdChatIdentifier = RawChatId(toLong()).toChatId()
fun Byte.toChatId(): IdChatIdentifier = RawChatId(toLong()).toChatId()
@Serializable(ChatIdentifierSerializer::class) @Serializable(ChatIdentifierSerializer::class)
@JvmInline @JvmInline
@ -115,7 +116,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
val id = internalSerializer.deserialize(decoder) val id = internalSerializer.deserialize(decoder)
return id.longOrNull ?.let { return id.longOrNull ?.let {
ChatId(it) ChatId(RawChatId(it))
} ?: id.content.let { } ?: id.content.let {
if (!it.startsWith("@")) { if (!it.startsWith("@")) {
Username("@$it") Username("@$it")
@ -127,7 +128,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
override fun serialize(encoder: Encoder, value: ChatIdentifier) { override fun serialize(encoder: Encoder, value: ChatIdentifier) {
when (value) { when (value) {
is IdChatIdentifier -> encoder.encodeLong(value.chatId) is IdChatIdentifier -> encoder.encodeLong(value.chatId.long)
is Username -> encoder.encodeString(value.full) is Username -> encoder.encodeString(value.full)
} }
} }
@ -141,13 +142,13 @@ object FullChatIdentifierSerializer : KSerializer<ChatIdentifier> {
val id = internalSerializer.deserialize(decoder) val id = internalSerializer.deserialize(decoder)
return id.longOrNull ?.let { return id.longOrNull ?.let {
ChatId(it) ChatId(RawChatId(it))
} ?:let { } ?:let {
val splitted = id.content.split("/") val splitted = id.content.split("/")
if (splitted.size == 2) { if (splitted.size == 2) {
val (chatId, threadId) = splitted val (chatId, threadId) = splitted
ChatIdWithThreadId( ChatIdWithThreadId(
chatId.toLongOrNull() ?: return@let null, chatId.toLongOrNull() ?.let(::RawChatId) ?: return@let null,
threadId.toLongOrNull() ?.let(::MessageThreadId) ?: return@let null threadId.toLongOrNull() ?.let(::MessageThreadId) ?: return@let null
) )
} else { } else {
@ -164,7 +165,7 @@ object FullChatIdentifierSerializer : KSerializer<ChatIdentifier> {
override fun serialize(encoder: Encoder, value: ChatIdentifier) { override fun serialize(encoder: Encoder, value: ChatIdentifier) {
when (value) { when (value) {
is ChatId -> encoder.encodeLong(value.chatId) is ChatId -> encoder.encodeLong(value.chatId.long)
is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}") is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}")
is Username -> encoder.encodeString(value.full) is Username -> encoder.encodeString(value.full)
} }

View File

@ -9,7 +9,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline import kotlin.jvm.JvmInline
typealias Identifier = Long
typealias ForwardSignature = String typealias ForwardSignature = String
typealias ForwardSenderName = String typealias ForwardSenderName = String
typealias AuthorSignature = ForwardSignature typealias AuthorSignature = ForwardSignature

View File

@ -7,6 +7,10 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class InlineMessageId( value class InlineMessageId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated("Renamed", ReplaceWith("InlineMessageId", "dev.inmo.tgbotapi.types.InlineMessageId")) @Deprecated("Renamed", ReplaceWith("InlineMessageId", "dev.inmo.tgbotapi.types.InlineMessageId"))
typealias InlineMessageIdentifier = InlineMessageId typealias InlineMessageIdentifier = InlineMessageId

View File

@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class InlineQueryId( value class InlineQueryId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated("Renamed", ReplaceWith("InlineQueryId", "dev.inmo.tgbotapi.types.InlineQueryId")) @Deprecated("Renamed", ReplaceWith("InlineQueryId", "dev.inmo.tgbotapi.types.InlineQueryId"))
typealias InlineQueryIdentifier = InlineQueryId typealias InlineQueryIdentifier = InlineQueryId

View File

@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class MediaGroupId( value class MediaGroupId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated("Renamed", ReplaceWith("MediaGroupId", "dev.inmo.tgbotapi.types.MediaGroupId")) @Deprecated("Renamed", ReplaceWith("MediaGroupId", "dev.inmo.tgbotapi.types.MediaGroupId"))
typealias MediaGroupIdentifier = MediaGroupId typealias MediaGroupIdentifier = MediaGroupId

View File

@ -29,7 +29,11 @@ object MessageIdSerializer : KSerializer<MessageId> {
@JvmInline @JvmInline
value class MessageId( value class MessageId(
val long: Long val long: Long
) ) {
override fun toString(): String {
return long.toString()
}
}
fun Long.asTelegramMessageId() = MessageId(this) fun Long.asTelegramMessageId() = MessageId(this)

View File

@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class MessageThreadId( value class MessageThreadId(
val long: Long val long: Long
) ) {
override fun toString(): String {
return long.toString()
}
}

View File

@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class PreCheckoutQueryId( value class PreCheckoutQueryId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}

View File

@ -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

View File

@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class ShippingQueryId( value class ShippingQueryId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated("Renamed", ReplaceWith("ShippingQueryId", "dev.inmo.tgbotapi.types.ShippingQueryId")) @Deprecated("Renamed", ReplaceWith("ShippingQueryId", "dev.inmo.tgbotapi.types.ShippingQueryId"))
typealias ShippingQueryIdentifier = ShippingQueryId typealias ShippingQueryIdentifier = ShippingQueryId

View File

@ -7,7 +7,11 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class TgFileUniqueId( value class TgFileUniqueId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}
@Deprecated( @Deprecated(
"Renamed", "Renamed",
ReplaceWith("TgFileUniqueId", "dev.inmo.tgbotapi.types.TgFileUniqueId") ReplaceWith("TgFileUniqueId", "dev.inmo.tgbotapi.types.TgFileUniqueId")

View File

@ -14,6 +14,10 @@ value class UpdateId(
override fun compareTo(other: UpdateId): Int { override fun compareTo(other: UpdateId): Int {
return long.compareTo(other.long) return long.compareTo(other.long)
} }
override fun toString(): String {
return long.toString()
}
} }
@Deprecated("Renamed", ReplaceWith("UpdateId", "dev.inmo.tgbotapi.types.UpdateId")) @Deprecated("Renamed", ReplaceWith("UpdateId", "dev.inmo.tgbotapi.types.UpdateId"))

View File

@ -7,4 +7,8 @@ import kotlin.jvm.JvmInline
@JvmInline @JvmInline
value class WebAppQueryId( value class WebAppQueryId(
val string: String val string: String
) ) {
override fun toString(): String {
return string
}
}

View File

@ -31,9 +31,9 @@ inline fun mention(parts: TextSourcesList, userId: UserId) = mention(parts, Comm
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun UserId.mention(parts: TextSourcesList) = mention(parts, this) inline fun UserId.mention(parts: TextSourcesList) = mention(parts, this)
@Suppress("NOTHING_TO_INLINE") @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") @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") @Suppress("NOTHING_TO_INLINE")
inline fun mention(user: User, vararg parts: TextSource) = mention( inline fun mention(user: User, vararg parts: TextSource) = mention(
textSourcesOrElseTextSource(parts.toList()) { textSourcesOrElseTextSource(parts.toList()) {
@ -50,6 +50,6 @@ inline fun mention(text: String, userId: UserId) = mention(text, CommonUser(user
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun UserId.mention(text: String) = mention(text, this) inline fun UserId.mention(text: String) = mention(text, this)
@Suppress("NOTHING_TO_INLINE") @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") @Suppress("NOTHING_TO_INLINE")
inline fun Identifier.mention(text: String) = mention(text, this) inline fun RawChatId.mention(text: String) = mention(text, this)

View File

@ -43,7 +43,7 @@ sealed interface PollAnswer: FromUser {
companion object { companion object {
val defaultUser = CommonBot( val defaultUser = CommonBot(
UserId(136817688L), UserId(RawChatId.DefaultUserId),
"", "",
"", "",
Username("@Channel_Bot") Username("@Channel_Bot")

View File

@ -4,19 +4,19 @@ import dev.inmo.tgbotapi.TestsJsonFormat
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlin.test.* import kotlin.test.*
private const val chatIdentifierChatId: Identifier = 123L private val chatIdentifierChatId: RawChatId = RawChatId(123L)
private const val chatIdentifierLink = "tg://user?id=$chatIdentifierChatId" private val chatIdentifierLink = "tg://user?id=$chatIdentifierChatId"
private const val testUsername = "@Example" private const val testUsername = "@Example"
class ChatIdentifierTests { class ChatIdentifierTests {
@Test @Test
fun `Cast_from_Int_to_ChatId_is_working_correctly`() { fun `Cast_from_Int_to_ChatId_is_working_correctly`() {
val chatId = chatIdentifierChatId.toInt().toChatId() val chatId = chatIdentifierChatId.long.toInt().toChatId()
assertEquals(chatIdentifierChatId, chatId.chatId) assertEquals(chatIdentifierChatId, chatId.chatId)
} }
@Test @Test
fun `Cast_from_Byte_to_ChatId_is_working_correctly`() { fun `Cast_from_Byte_to_ChatId_is_working_correctly`() {
val chatId = chatIdentifierChatId.toByte().toChatId() val chatId = chatIdentifierChatId.long.toByte().toChatId()
assertEquals(chatIdentifierChatId, chatId.chatId) assertEquals(chatIdentifierChatId, chatId.chatId)
} }
@Test @Test

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents
import dev.inmo.tgbotapi.TestsJsonFormat import dev.inmo.tgbotapi.TestsJsonFormat
import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.RawChatId
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -43,6 +44,6 @@ class MigratedToSupergroupTest {
val data = message.data.supergroupEventMessageOrThrow() val data = message.data.supergroupEventMessageOrThrow()
val event = data.chatEvent.migratedToSupergroupOrThrow() val event = data.chatEvent.migratedToSupergroupOrThrow()
assertEquals(IdChatIdentifier(57005), event.migratedFrom) assertEquals(IdChatIdentifier(RawChatId(57005)), event.migratedFrom)
} }
} }

View File

@ -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 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-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 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 final fun makeChatLink-FNqv5JM (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 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 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 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
public static final fun makeInternalTgDeepLink-26ZnLnw (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 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 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 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 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 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/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-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; public static final fun makeLinkToMessage-jfrm6zs (Ljava/lang/String;JLdev/inmo/tgbotapi/types/MessageThreadId;)Ljava/lang/String;

View File

@ -10,7 +10,7 @@ import io.ktor.http.encodeURLQueryComponent
fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}" fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}"
fun makeInternalTgUsernameLink(username: String) = "${internalTgAppLinksBeginning}resolve?domain=$username" fun makeInternalTgUsernameLink(username: String) = "${internalTgAppLinksBeginning}resolve?domain=$username"
fun makeUserLink(userId: UserId) = userId.userLink 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, linkIdRedundantPartRegex,
"" ""
).let { bareId -> ).let { bareId ->
@ -54,7 +54,7 @@ fun makeLinkToMessage(
threadId: MessageThreadId? = null threadId: MessageThreadId? = null
): String = makeLinkToMessage(username.withoutAt, messageId, threadId) ): String = makeLinkToMessage(username.withoutAt, messageId, threadId)
fun makeLinkToMessage( fun makeLinkToMessage(
chatId: Identifier, chatId: RawChatId,
messageId: MessageId, messageId: MessageId,
threadId: MessageThreadId? = null threadId: MessageThreadId? = null
): String = chatId.toString().replace( ): String = chatId.toString().replace(

View File

@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.chat.CommonBot
import dev.inmo.tgbotapi.types.chat.CommonUser import dev.inmo.tgbotapi.types.chat.CommonUser
external interface WebAppUser { external interface WebAppUser {
val id: Identifier val id: RawChatId
@JsName(isBotField) @JsName(isBotField)
val isBot: Boolean? val isBot: Boolean?
@JsName(firstNameField) @JsName(firstNameField)