From c7259e7699ca9a2d58410a4ccb47332351d3e272 Mon Sep 17 00:00:00 2001 From: madhead Date: Thu, 5 Nov 2020 02:26:52 +0300 Subject: [PATCH] Fix #175: Support for message_id field in unpinChatMessage method --- CHANGELOG.md | 1 + .../requests/chat/modify/UnpinChatMessage.kt | 6 +++++- .../api/chat/modify/UnpinChatMessage.kt | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48d33221d4..edb9298979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` * New request `UnpinAllChatMessages` + * New parameter for `unpinChatMessage` method: `messageId` * New dice type `FootballDiceAnimationType` * Limits for dices has been changed * `commonDiceResultLimit` has been deprecated diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt index 456d0649b9..868559b16d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt @@ -3,14 +3,18 @@ package dev.inmo.tgbotapi.requests.chat.modify import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chatIdField +import dev.inmo.tgbotapi.types.messageIdField import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @Serializable data class UnpinChatMessage( @SerialName(chatIdField) - override val chatId: ChatIdentifier + override val chatId: ChatIdentifier, + @SerialName(messageIdField) + val messageId: MessageIdentifier? = null ): ChatRequest, SimpleRequest { override fun method(): String = "unpinChatMessage" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt index de540d19d3..ada3cc7b95 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt @@ -3,12 +3,21 @@ package dev.inmo.tgbotapi.extensions.api.chat.modify import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.unpinChatMessage( - chatId: ChatIdentifier -) = execute(UnpinChatMessage(chatId)) + chatId: ChatIdentifier, + messageId: MessageIdentifier? = null +) = execute(UnpinChatMessage(chatId, messageId)) suspend fun TelegramBot.unpinChatMessage( - chat: PublicChat -) = unpinChatMessage(chat.id) + chat: Chat, + messageId: MessageIdentifier? = null +) = unpinChatMessage(chat.id, messageId) + +suspend fun TelegramBot.unpinChatMessage( + message: Message +) = unpinChatMessage(message.chat.id, message.messageId)