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

fix for media fields in input media

This commit is contained in:
InsanusMokrassar 2020-11-02 13:51:20 +06:00
parent bbc56fe94c
commit 957649603b
6 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaFileAttachmentName
import dev.inmo.tgbotapi.utils.StorageFile
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
@ -12,6 +11,14 @@ sealed class InputFile {
abstract val fileId: String
}
internal inline val InputFile.attachFileId
get() = "attach://$fileId"
internal inline val InputFile.fileIdToSend
get() = when (this) {
is FileId -> fileId
is MultipartFile -> attachFileId
}
// TODO:: add checks for file url/file id regex
/**
* Contains file id or file url
@ -30,12 +37,6 @@ 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

@ -23,5 +23,5 @@ data class InputMediaAnimation(
@SerialName(mediaField)
override val media: String
init { media = file.fileId } // crutch until js compiling will be fixed
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
}

View File

@ -30,7 +30,7 @@ data class InputMediaAudio(
@SerialName(mediaField)
override val media: String
init { media = file.fileId } // crutch until js compiling will be fixed
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
}
fun AudioFile.toInputMediaAudio(

View File

@ -24,7 +24,7 @@ data class InputMediaDocument(
@SerialName(mediaField)
override val media: String
init { media = file.fileId } // crutch until js compiling will be fixed
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
}
fun DocumentFile.toInputMediaDocument(

View File

@ -24,7 +24,7 @@ data class InputMediaPhoto(
@SerialName(mediaField)
override val media: String
init { media = file.fileId } // crutch until js compiling will be fixed
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
}
fun PhotoSize.toInputMediaPhoto(

View File

@ -26,5 +26,5 @@ data class InputMediaVideo(
@SerialName(mediaField)
override val media: String
init { media = file.fileId } // crutch until js compiling will be fixed
init { media = file.fileIdToSend } // crutch until js compiling will be fixed
}