From 6eaa9d699bb6d8bb0c12567001608bb3f5659c29 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 29 Aug 2020 12:08:37 +0600 Subject: [PATCH] crutch for inputmediaphoto --- CHANGELOG.md | 1 + .../TelegramBotAPI/requests/abstracts/InputFile.kt | 7 +++++++ .../TelegramBotAPI/types/InputMedia/InputMedia.kt | 1 + .../TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt | 6 ++---- .../TelegramBotAPI/types/InputMedia/InputMediaAudio.kt | 6 ++---- .../TelegramBotAPI/types/InputMedia/InputMediaDocument.kt | 6 ++---- .../TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt | 6 ++---- .../TelegramBotAPI/types/InputMedia/InputMediaVideo.kt | 6 ++---- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d29619fb..ad911fb841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * `MultipartRequestCallFactory` * `SimpleRequestCallFactory` * `MediaGroupMemberInputMedia` members now will not have `arguments` property due to redundancy and buggy of that + * Field `media` now is common for all `InputMedia` objects * `TelegramBotAPI-extensions-api`: * Extensions `TelegramBot#downloadFile` were added * `TelegramBotAPI-extensions-utils`: diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt index 3227b9d0fe..400b65d425 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFile.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts +import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.toInputMediaFileAttachmentName import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile import kotlinx.serialization.* import kotlinx.serialization.descriptors.* @@ -29,6 +30,12 @@ internal object InputFileSerializer : KSerializer { override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString()) } +internal val InputFile.asMediaData: String + get() = when (this) { + is FileId -> fileId + is MultipartFile -> fileId.toInputMediaFileAttachmentName() + } + // TODO:: add checks for files size /** * Contains info about file for sending diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMedia.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMedia.kt index 800795a2db..dbfe3df43e 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMedia.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMedia.kt @@ -9,4 +9,5 @@ fun String.toInputMediaFileAttachmentName() = "attach://$this" interface InputMedia { val type: String val file: InputFile + val media: String } \ No newline at end of file diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt index 068672984f..e44b6d64ec 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt @@ -22,8 +22,6 @@ data class InputMediaAnimation( override val type: String = "animation" @SerialName(mediaField) - val media: String = when (file) { - is FileId -> file.fileId - is MultipartFile -> file.fileId.toInputMediaFileAttachmentName() - } + override val media: String + init { media = file.fileId } // crutch until js compiling will be fixed } diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAudio.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAudio.kt index ad40fdf3ce..253a69974c 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAudio.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAudio.kt @@ -23,8 +23,6 @@ data class InputMediaAudio( override val type: String = "audio" @SerialName(mediaField) - val media: String = when (file) { - is FileId -> file.fileId - is MultipartFile -> file.fileId.toInputMediaFileAttachmentName() - } + override val media: String + init { media = file.fileId } // crutch until js compiling will be fixed } diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt index 2baf97971b..e99bffc69e 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt @@ -19,8 +19,6 @@ data class InputMediaDocument( override val type: String = "document" @SerialName(mediaField) - val media: String = when (file) { - is FileId -> file.fileId - is MultipartFile -> file.fileId.toInputMediaFileAttachmentName() - } + override val media: String + init { media = file.fileId } // crutch until js compiling will be fixed } diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt index 2f7ab24294..e772fb56c9 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaPhoto.kt @@ -23,10 +23,8 @@ data class InputMediaPhoto( override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) @SerialName(mediaField) - val media: String = when (file) { - is FileId -> file.fileId - is MultipartFile -> file.fileId.toInputMediaFileAttachmentName() - } + override val media: String + init { media = file.fileId } // crutch until js compiling will be fixed } fun PhotoSize.toInputMediaPhoto( diff --git a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt index a36dc51d58..0bf052921c 100644 --- a/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt +++ b/TelegramBotAPI-core/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaVideo.kt @@ -25,8 +25,6 @@ data class InputMediaVideo( override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) @SerialName(mediaField) - val media: String = when (file) { - is FileId -> file.fileId - is MultipartFile -> file.fileId.toInputMediaFileAttachmentName() - } + override val media: String + init { media = file.fileId } // crutch until js compiling will be fixed }