From 7d0009039f09efb4d4262c78c565bec477c5c501 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 10:12:21 +0600 Subject: [PATCH] logical fixes --- .../requests/chat/modify/PinChatMessage.kt | 13 +++++-------- .../requests/chat/modify/SetChatPhoto.kt | 6 +++--- .../edit/ReplyMarkup/EditChatMessageReplyMarkup.kt | 9 +-------- .../requests/edit/caption/EditChatMessageCaption.kt | 13 +------------ .../requests/edit/media/EditChatMessageMedia.kt | 10 +--------- .../requests/edit/text/EditChatMessageText.kt | 12 +----------- 6 files changed, 12 insertions(+), 51 deletions(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index 2996b448d7..95e55c1e11 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -39,13 +39,10 @@ suspend fun RequestsExecutor.pinChatMessage( ) = pinChatMessage(chat.id, messageId, disableNotification) suspend fun RequestsExecutor.pinChatMessage( - chatId: ChatIdentifier, message: Message, disableNotification: Boolean = false -) = pinChatMessage(chatId, message.messageId, disableNotification) - -suspend fun RequestsExecutor.pinChatMessage( - chat: PublicChat, - message: Message, - disableNotification: Boolean = false -) = pinChatMessage(chat.id, message.messageId, disableNotification) +) = if (message.chat is PublicChat) { + pinChatMessage(message.chat.id, message.messageId, disableNotification) +} else { + error("It is possible to pin messages only in non one-to-one chats") +} diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt index 66104e00fa..5748b64d94 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/SetChatPhoto.kt @@ -26,12 +26,12 @@ data class SetChatPhoto ( override val paramsJson: JsonObject = toJson(serializer()) } -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setChatPhoto( chatId: ChatIdentifier, photo: MultipartFile ) = execute(SetChatPhoto(chatId, photo)) -suspend fun RequestsExecutor.setChatPermissions( +suspend fun RequestsExecutor.setChatPhoto( chat: PublicChat, photo: MultipartFile -) = setChatPermissions(chat.id, photo) +) = setChatPhoto(chat.id, photo) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt index 69be48676d..faf2077bf9 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/ReplyMarkup/EditChatMessageReplyMarkup.kt @@ -49,14 +49,7 @@ suspend fun RequestsExecutor.editMessageReplyMarkup( ) = editMessageReplyMarkup(chat.id, messageId, replyMarkup) suspend fun RequestsExecutor.editMessageReplyMarkup( - chatId: ChatId, message: Message, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageReplyMarkup(chatId, message.messageId, replyMarkup) - -suspend fun RequestsExecutor.editMessageReplyMarkup( - chat: Chat, - message: Message, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageReplyMarkup(chat.id, message.messageId, replyMarkup) +) = editMessageReplyMarkup(message.chat.id, message.messageId, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt index e3406789bd..bad04096ef 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/caption/EditChatMessageCaption.kt @@ -60,21 +60,10 @@ suspend fun RequestsExecutor.editMessageCaption( ) = editMessageCaption(chat.id, messageId, text, parseMode, replyMarkup) suspend fun RequestsExecutor.editMessageCaption( - chatId: ChatId, message: ContentMessage, text: String, parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null ): ContentMessage where T : CaptionedInput, T : MediaContent { - return editMessageCaption(chatId, message.messageId, text, parseMode, replyMarkup) -} - -suspend fun RequestsExecutor.editMessageCaption( - chat: Chat, - message: ContentMessage, - text: String, - parseMode: ParseMode? = null, - replyMarkup: InlineKeyboardMarkup? = null -): ContentMessage where T : CaptionedInput, T : MediaContent { - return editMessageCaption(chat.id, message.messageId, text, parseMode, replyMarkup) + return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt index e01842db23..d9c0f3194c 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/media/EditChatMessageMedia.kt @@ -63,15 +63,7 @@ suspend fun RequestsExecutor.editMessageMedia( ) = editMessageMedia(chat.id, messageId, media, replyMarkup) suspend fun RequestsExecutor.editMessageMedia( - chatId: ChatId, message: ContentMessage, media: InputMedia, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageMedia(chatId, message.messageId, media, replyMarkup) - -suspend fun RequestsExecutor.editMessageMedia( - chat: Chat, - message: ContentMessage, - media: InputMedia, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageMedia(chat.id, message.messageId, media, replyMarkup) +) = editMessageMedia(message.chat.id, message.messageId, media, replyMarkup) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt index b18c23259e..a64972caa2 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/text/EditChatMessageText.kt @@ -59,19 +59,9 @@ suspend fun RequestsExecutor.editMessageText( ) = editMessageText(chat.id, messageId, text, parseMode, disableWebPagePreview, replyMarkup) suspend fun RequestsExecutor.editMessageText( - chatId: ChatId, message: ContentMessage, text: String, parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(chatId, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) - -suspend fun RequestsExecutor.editMessageText( - chat: Chat, - message: ContentMessage, - text: String, - parseMode: ParseMode? = null, - disableWebPagePreview: Boolean? = null, - replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file +) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file