diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index 5bf03a6242..b89d7f60bc 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -16167,7 +16167,7 @@ public final class dev/inmo/tgbotapi/types/chat/ChannelChatImpl$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public abstract interface class dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/ForumChat { +public abstract interface class dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/SupergroupChat { public static final field Companion Ldev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat$Companion; public fun isDirectMessages ()Z } @@ -17028,7 +17028,7 @@ public final class dev/inmo/tgbotapi/types/chat/ExtendedChannelChatImpl$Companio public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public abstract interface class dev/inmo/tgbotapi/types/chat/ExtendedChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat, dev/inmo/tgbotapi/types/chat/ExtendedForumChat { +public abstract interface class dev/inmo/tgbotapi/types/chat/ExtendedChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat, dev/inmo/tgbotapi/types/chat/ExtendedSupergroupChat { public static final field Companion Ldev/inmo/tgbotapi/types/chat/ExtendedChannelDirectMessagesChat$Companion; public abstract fun getChannelChat ()Ldev/inmo/tgbotapi/types/chat/PreviewChannelChat; } @@ -17742,7 +17742,7 @@ public final class dev/inmo/tgbotapi/types/chat/PreviewChannelChat$DefaultImpls public static fun isDirectMessages (Ldev/inmo/tgbotapi/types/chat/PreviewChannelChat;)Z } -public abstract interface class dev/inmo/tgbotapi/types/chat/PreviewChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat, dev/inmo/tgbotapi/types/chat/PreviewForumChat { +public abstract interface class dev/inmo/tgbotapi/types/chat/PreviewChannelDirectMessagesChat : dev/inmo/tgbotapi/types/chat/ChannelDirectMessagesChat, dev/inmo/tgbotapi/types/chat/PreviewSupergroupChat { public static final field Companion Ldev/inmo/tgbotapi/types/chat/PreviewChannelDirectMessagesChat$Companion; } 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 1d3733d3e5..1ca52e01c6 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 @@ -55,7 +55,7 @@ sealed interface ForumChat : SupergroupChat @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(ChatSerializer::class) -sealed interface ChannelDirectMessagesChat : ForumChat { +sealed interface ChannelDirectMessagesChat : SupergroupChat { override val isDirectMessages: Boolean get() = true } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt index ad3d36725c..091ec86c5d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt @@ -77,16 +77,17 @@ object ChatSerializer : KSerializer { } catch (_: SerializationException) { val type = decodedJson[typeField] ?.jsonPrimitive ?.content ?.asChatType val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true + val isDirectMessages = decodedJson[isDirectMessagesField] ?.jsonPrimitive ?.booleanOrNull == true val original = decodedJson[originField] when (type) { ChatType.Sender -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) ChatType.Private -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) ChatType.Group -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson) - ChatType.Supergroup -> if (isForum) { - formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson) - } else { - formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) + ChatType.Supergroup -> when { + isForum -> formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson) + isDirectMessages -> formatter.decodeFromJsonElement(ChannelDirectMessagesChatImpl.serializer(), decodedJson) + else -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) } ChatType.Channel -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson) is ChatType.Unknown -> UnknownChatType( @@ -131,11 +132,10 @@ object PreviewChatSerializer : KSerializer { ChatType.Private -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson) ChatType.Group -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson) ChatType.Supergroup -> { - @Suppress("SimplifyBooleanWithConstants") when { - isForum == false -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) + isForum -> formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson) isChannelDirectMessages -> formatter.decodeFromJsonElement(ChannelDirectMessagesChatImpl.serializer(), decodedJson) - else -> formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson) + else -> formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson) } } ChatType.Channel -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson) @@ -187,11 +187,10 @@ sealed class ExtendedChatSerializer : KSerializer { ChatType.Private -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson) ChatType.Group -> formatter.decodeFromJsonElement(ExtendedGroupChatImpl.serializer(), decodedJson) ChatType.Supergroup -> { - @Suppress("SimplifyBooleanWithConstants") when { - isForum == false -> formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson) + isForum -> formatter.decodeFromJsonElement(ExtendedForumChatImpl.serializer(), decodedJson) isChannelDirectMessages -> formatter.decodeFromJsonElement(ExtendedChannelDirectMessagesChatImpl.serializer(), decodedJson) - else -> formatter.decodeFromJsonElement(ExtendedForumChatImpl.serializer(), decodedJson) + else -> formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson) } } ChatType.Channel -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson) 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 5c685b4d54..5a10c36ffb 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 @@ -116,7 +116,7 @@ sealed interface ExtendedForumChat : ExtendedSupergroupChat, ForumChat @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(PreviewChatSerializer::class) -sealed interface ExtendedChannelDirectMessagesChat : ExtendedForumChat, ChannelDirectMessagesChat { +sealed interface ExtendedChannelDirectMessagesChat : ExtendedSupergroupChat, ChannelDirectMessagesChat { val channelChat: PreviewChannelChat } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/PreviewAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/PreviewAbstracts.kt index 9f6bf1afe9..0e05c55d6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/PreviewAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/PreviewAbstracts.kt @@ -43,4 +43,4 @@ sealed interface PreviewForumChat : PreviewSupergroupChat, ForumChat @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(PreviewChatSerializer::class) -sealed interface PreviewChannelDirectMessagesChat : PreviewForumChat, ChannelDirectMessagesChat +sealed interface PreviewChannelDirectMessagesChat : PreviewSupergroupChat, ChannelDirectMessagesChat 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 09305c7bf5..f128acc89e 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 @@ -399,6 +399,55 @@ internal data class RawMessage( else -> null } when (chat) { + is PreviewChannelDirectMessagesChat -> { + if (direct_messages_topic == null) error("direct_messages_topic must be presented for ChannelDirectMessagesChat messages") + val chatId = ChatIdWithChannelDirectMessageThreadId( + chat.id.chatId, + direct_messages_topic.threadId + ) + val actualForumChat = when (chat) { + is ChannelDirectMessagesChatImpl -> chat.copy(id = chatId) + } + when (sender_chat) { + is PreviewChannelChat -> FromChannelChannelDirectMessagesContentMessageImpl( + chat = actualForumChat, + channel = sender_chat, + messageId = messageId, + date = date.asDate, + directMessageTopic = direct_messages_topic, + forwardOrigin = forward_origin, + editDate = edit_date ?.asDate, + hasProtectedContent = has_protected_content == true, + replyInfo = replyInfo, + replyMarkup = reply_markup, + content = content, + senderBot = via_bot, + authorSignature = author_signature, + mediaGroupId = media_group_id, + fromOffline = is_from_offline, + cost = paid_star_count, + ) + is PreviewGroupChat, + null -> CommonChannelDirectMessagesContentMessageImpl( + chat = actualForumChat, + messageId = messageId, + from = checkedFrom ?: from ?: error("It is expected that in direct channel messages from non anonymous channels user must be specified"), + date = date.asDate, + directMessageTopic = direct_messages_topic, + forwardOrigin = forward_origin, + editDate = edit_date ?.asDate, + hasProtectedContent = has_protected_content == true, + replyInfo = replyInfo, + replyMarkup = reply_markup, + content = content, + senderBot = via_bot, + mediaGroupId = media_group_id, + senderBoostsCount = sender_boost_count, + fromOffline = is_from_offline, + cost = paid_star_count, + ) + } + } is PreviewPublicChat -> when (chat) { is PreviewChannelChat -> if (is_paid_post) { ChannelContentMessageImpl( @@ -438,153 +487,6 @@ internal data class RawMessage( ) } is PreviewForumChat -> when(chat) { - is PreviewChannelDirectMessagesChat -> { - if (messageThreadId != null) { - val chatId = ChatIdWithThreadId( - chat.id.chatId, - messageThreadId - ) - val actualForumChat = when (chat) { - is ChannelDirectMessagesChatImpl -> chat.copy(id = chatId) - } - when (sender_chat) { - is PreviewChannelChat -> FromChannelChannelDirectMessagesContentMessageImpl( - chat = actualForumChat, - channel = sender_chat, - messageId = messageId, - date = date.asDate, - directMessageTopic = direct_messages_topic ?: error("direct_messages_topic must be presented for FromChannelChannelDirectMessagesContentMessage"), - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - authorSignature = author_signature, - mediaGroupId = media_group_id, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - is PreviewGroupChat, - null -> CommonChannelDirectMessagesContentMessageImpl( - chat = actualForumChat, - messageId = messageId, - from = checkedFrom ?: from ?: error("It is expected that in direct channel messages from non anonymous channels user must be specified"), - date = date.asDate, - directMessageTopic = direct_messages_topic ?: error("direct_messages_topic must be presented for CommonChannelDirectMessagesContentMessage"), - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - mediaGroupId = media_group_id, - senderBoostsCount = sender_boost_count, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - } - } else { - when (sender_chat) { - is PreviewChannelChat -> when { - is_automatic_forward == true -> ConnectedFromChannelGroupContentMessageImpl( - chat = chat, - channel = sender_chat, - messageId = messageId, - date = date.asDate, - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - authorSignature = author_signature, - mediaGroupId = media_group_id, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - direct_messages_topic != null -> CommonChannelDirectMessagesContentMessageImpl( - chat = when (chat) { - is ChannelDirectMessagesChatImpl -> chat.copy( - id = ChatIdWithChannelDirectMessageThreadId( - chat.id.chatId, - direct_messages_topic.threadId - ) - ) - }, - messageId = messageId, - from = checkedFrom ?: from ?: error("It is expected that in direct channel messages from non anonymous channels user must be specified"), - date = date.asDate, - directMessageTopic = direct_messages_topic ?: error("direct_messages_topic must be presented for CommonChannelDirectMessagesContentMessage"), - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - mediaGroupId = media_group_id, - senderBoostsCount = sender_boost_count, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - else -> UnconnectedFromChannelGroupContentMessageImpl( - chat = chat, - channel = sender_chat, - messageId = messageId, - date = date.asDate, - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - authorSignature = author_signature, - mediaGroupId = media_group_id, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - } - is GroupChat -> AnonymousGroupContentMessageImpl( - chat = chat, - messageId = messageId, - date = date.asDate, - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - authorSignature = author_signature, - mediaGroupId = media_group_id, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - null -> CommonGroupContentMessageImpl( - chat = chat, - messageId = messageId, - from = checkedFrom ?: from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), - date = date.asDate, - forwardOrigin = forward_origin, - editDate = edit_date ?.asDate, - hasProtectedContent = has_protected_content == true, - replyInfo = replyInfo, - replyMarkup = reply_markup, - content = content, - senderBot = via_bot, - mediaGroupId = media_group_id, - senderBoostsCount = sender_boost_count, - fromOffline = is_from_offline, - cost = paid_star_count, - ) - } - } - } is ForumChatImpl -> { if (messageThreadId != null) { val chatId = ChatIdWithThreadId(