1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

crutch for inputmediaphoto

This commit is contained in:
InsanusMokrassar 2020-08-29 12:08:37 +06:00
parent 6788c4d1dd
commit 6eaa9d699b
8 changed files with 19 additions and 20 deletions

View File

@ -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`:

View File

@ -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<InputFile> {
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

View File

@ -9,4 +9,5 @@ fun String.toInputMediaFileAttachmentName() = "attach://$this"
interface InputMedia {
val type: String
val file: InputFile
val media: String
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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(

View File

@ -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
}