From 9fea7390e82afede88e5c7b25ebd986ad55267db Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 15 Feb 2026 23:51:39 +0600 Subject: [PATCH] add support of extended chat id in private chats --- .../dev/inmo/tgbotapi/types/ChatIdentifier.kt | 2 +- .../dev/inmo/tgbotapi/types/chat/Abstracts.kt | 3 ++- .../dev/inmo/tgbotapi/types/chat/Extended.kt | 2 +- .../dev/inmo/tgbotapi/types/chat/Impls.kt | 2 +- .../inmo/tgbotapi/types/message/RawMessage.kt | 18 +++++++++++++----- 5 files changed, 18 insertions(+), 9 deletions(-) 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 b5ba8672c0..631d865a34 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 @@ -123,7 +123,7 @@ val RawChatId.userLink: String val UserId.userLink: String get() = chatId.userLink val User.userLink: String - get() = id.userLink + get() = id.toChatId().userLink typealias UserId = ChatId diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt index c204201b87..e4b1eccba8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Abstracts.kt @@ -13,7 +13,7 @@ sealed interface UsernameChat : Chat { @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(ChatSerializer::class) sealed interface PrivateChat : Chat, UsernameChat { - override val id: UserId + override val id: IdChatIdentifier val firstName: String val lastName: String } @@ -25,6 +25,7 @@ sealed interface PrivateUserChat : PrivateChat @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(ChatSerializer::class) sealed interface PrivateForumChat : PrivateUserChat, ForumChat { + override val id: IdChatIdentifier } @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") 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 3f9b289a7d..6b112dd805 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 @@ -183,7 +183,7 @@ data class ExtendedPrivateChatImpl( data class ExtendedPrivateForumChatImpl( @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @SerialName(idField) - override val id: UserId, + override val id: IdChatIdentifier, @SerialName(photoField) override val chatPhoto: ChatPhoto? = null, @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt index ca89d07620..fa07a4447a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Impls.kt @@ -38,7 +38,7 @@ data class PrivateChatImpl( data class PrivateForumChatImpl( @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @SerialName(idField) - override val id: UserId, + override val id: IdChatIdentifier, @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @SerialName(usernameField) override val username: Username? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 8abfd711fd..f1174560ea 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -750,14 +750,22 @@ internal data class RawMessage( is PreviewPrivateChat -> if (business_connection_id == null) { when { is_topic_message == true -> { + val chatId = ChatIdWithThreadId( + chat.id.chatId, + messageThreadId ?: error("Was detected forum private message, but message thread id was not found") + ) + val actualForumChat = when (chat) { + is PrivateForumChatImpl -> chat.copy(id = chatId) + is CommonUser -> chat + is CommonBot -> chat + is PrivateChatImpl -> chat + } PrivateForumContentMessageImpl( messageId = messageId, - from = checkedFrom ?: from - ?: error("Was detected common message, but owner (sender) of the message was not found"), - threadId = messageThreadId - ?: error("Was detected forum private message, but message thread id was not found"), + from = checkedFrom ?: from ?: error("Was detected common message, but owner (sender) of the message was not found"), + threadId = messageThreadId, threadCreatingInfo = forum_topic_created, - chat = chat, + chat = actualForumChat, content = content, date = date.asDate, editDate = edit_date?.asDate,