From b7c3f9f60722f86430ed45352973d143ec4566de Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 26 Nov 2023 02:06:30 +0600 Subject: [PATCH] pinned message in ExtendedOtherPartiesChat --- CHANGELOG.md | 2 ++ .../kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt | 5 ++++- .../inmo/tgbotapi/types/chat/ExtendedAbstracts.kt | 13 +++++++++---- .../inmo/tgbotapi/extensions/utils/ClassCastsNew.kt | 10 ++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b841162b0..83399a485f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Serialization`: `1.6.0` -> `1.6.1` * `Ktor`: `2.3.5` -> `2.3.6` * `MicroUtils`: `0.20.12` -> `0.20.15` +* `Core`: + * New abstraction `ExtendedOtherPartiesChat` with `pinnedMessage` ## 9.3.0 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 91d502f931..65256cb987 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 @@ -81,7 +81,10 @@ data class ExtendedPrivateChatImpl( @SerialName(emojiStatusCustomEmojiIdField) override val statusEmojiId: CustomEmojiId? = null, @SerialName(emojiStatusExpirationDateField) - override val statusEmojiExpiration: TelegramDate? = null + override val statusEmojiExpiration: TelegramDate? = null, + @SerialName(pinnedMessageField) + @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) + override val pinnedMessage: Message? = null, ) : ExtendedPrivateChat typealias ExtendedUser = ExtendedPrivateChatImpl 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 09ac9d6f4f..bf9e7cc122 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 @@ -17,7 +17,7 @@ sealed interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { } @Serializable(ExtendedChatSerializer.Companion::class) -sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername { +sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername, ExtendedOtherPartiesChat { val bio: String val hasPrivateForwards: Boolean val hasRestrictedVoiceAndVideoMessages: Boolean @@ -28,11 +28,9 @@ sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername { get() = hasPrivateForwards } -sealed interface ExtendedPublicChat : ExtendedChat, PublicChat { +sealed interface ExtendedPublicChat : ExtendedOtherPartiesChat, PublicChat { val description: String val inviteLink: String? - @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - val pinnedMessage: Message? val membersHidden: Boolean } @@ -68,6 +66,13 @@ sealed interface ExtendedChat : Chat { val chatPhoto: ChatPhoto? } + +@Serializable(ExtendedChatSerializer.Companion::class) +sealed interface ExtendedOtherPartiesChat : ExtendedChat { + @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) + val pinnedMessage: Message? +} + @Serializable(ExtendedChatSerializer.Companion::class) sealed interface ExtendedChatWithUsername : UsernameChat, ExtendedChat { val activeUsernames: List diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index 5dadba2ded..234934b60c 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -120,6 +120,7 @@ import dev.inmo.tgbotapi.types.chat.ExtendedChat import dev.inmo.tgbotapi.types.chat.ExtendedChatWithUsername import dev.inmo.tgbotapi.types.chat.ExtendedForumChat import dev.inmo.tgbotapi.types.chat.ExtendedGroupChat +import dev.inmo.tgbotapi.types.chat.ExtendedOtherPartiesChat import dev.inmo.tgbotapi.types.chat.ExtendedPrivateChat import dev.inmo.tgbotapi.types.chat.ExtendedPublicChat import dev.inmo.tgbotapi.types.chat.ExtendedSupergroupChat @@ -1965,6 +1966,15 @@ public inline fun Chat.extendedChatOrThrow(): ExtendedChat = this as public inline fun Chat.ifExtendedChat(block: (ExtendedChat) -> T): T? = extendedChatOrNull() ?.let(block) +public inline fun Chat.extendedOtherPartiesChatOrNull(): ExtendedOtherPartiesChat? = this as? + dev.inmo.tgbotapi.types.chat.ExtendedOtherPartiesChat + +public inline fun Chat.extendedOtherPartiesChatOrThrow(): ExtendedOtherPartiesChat = this as + dev.inmo.tgbotapi.types.chat.ExtendedOtherPartiesChat + +public inline fun Chat.ifExtendedOtherPartiesChat(block: (ExtendedOtherPartiesChat) -> T): T? = + extendedOtherPartiesChatOrNull() ?.let(block) + public inline fun Chat.extendedChatWithUsernameOrNull(): ExtendedChatWithUsername? = this as? dev.inmo.tgbotapi.types.chat.ExtendedChatWithUsername