From 159ea6f1ccb46327b63cdbb67c1131e45f222057 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:44:13 +0600 Subject: [PATCH] UnpinAllChatMessages --- CHANGELOG.md | 2 ++ .../chat/modify/UnpinAllChatMessages.kt | 28 +++++++++++++++++++ .../api/chat/modify/UnpinAllChatMessages.kt | 16 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e92639cc9..bebed0c44c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,10 @@ * New fields `ExtendedSupergroupChat#location` * New fields `AudioFile#fileName` and `VideoFile#fileName` * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` + * New request `UnpinAllChatMessages` * `API`: * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` + * New extensions `TelegramBot#unpinAllChatMessages` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..d5f8da23c3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,28 @@ +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.chatIdField +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an + * administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or + * 'can_edit_messages' admin right in a channel. + * + * @see PinChatMessage + * @see UnpinChatMessage + */ +@Serializable +data class UnpinAllChatMessages( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ChatRequest, SimpleRequest { + override fun method(): String = "unpinAllChatMessages" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..2385bda48e --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.extensions.api.chat.modify + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.modify.UnpinAllChatMessages +import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.unpinAllChatMessages( + chatId: ChatIdentifier +) = execute(UnpinAllChatMessages(chatId)) + +suspend fun TelegramBot.unpinAllChatMessages( + chat: Chat +) = unpinAllChatMessages(chat.id)