mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
add BuiltInMimeTypes, ThumbedWithMimeTypeInlineQueryResult and buildMimeType factory
This commit is contained in:
parent
835b8b34f9
commit
ca784e67df
@ -55,6 +55,11 @@
|
||||
* Interface `PossiblySentViaBot` has been added
|
||||
* Currently, only `ChannelMessage` and `CommonMessageImpl` are implementing interface `PossiblySentViaBot`. It
|
||||
could be changed in future
|
||||
* Factory `buildMimeType` was added
|
||||
* `BuiltinMimeTypes` was added
|
||||
* Abstraction `ThumbedWithMimeTypeInlineQueryResult` with `thumbMimeType` field was added
|
||||
* `InlineQueryResultGif` and `InlineQueryResultMpeg4Gif` now extend `ThumbedWithMimeTypeInlineQueryResult`
|
||||
instead of `ThumbedInlineQueryResult`
|
||||
|
||||
### 0.27.5
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.BuiltinMimeTypes
|
||||
|
||||
typealias Identifier = Long
|
||||
typealias MessageIdentifier = Long
|
||||
typealias InlineQueryIdentifier = String
|
||||
@ -63,6 +65,12 @@ val quizPollExplanationLimit = explanationLimit
|
||||
|
||||
val openPeriodPollSecondsLimit = 5 .. 600
|
||||
|
||||
val telegramInlineModeGifPermittedMimeTypes = listOf(
|
||||
BuiltinMimeTypes.Image.Jpg,
|
||||
BuiltinMimeTypes.Image.Gif,
|
||||
BuiltinMimeTypes.Video.MP4
|
||||
)
|
||||
|
||||
const val chatIdField = "chat_id"
|
||||
const val messageIdField = "message_id"
|
||||
const val updateIdField = "update_id"
|
||||
@ -177,6 +185,7 @@ const val stickerFileIdField = "sticker_file_id"
|
||||
const val gameShortNameField = "game_short_name"
|
||||
|
||||
const val thumbUrlField = "thumb_url"
|
||||
const val thumbMimeTypeField = "thumb_mime_type"
|
||||
const val thumbWidthField = "thumb_width"
|
||||
const val thumbHeightField = "thumb_height"
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -18,6 +19,8 @@ data class InlineQueryResultGifImpl(
|
||||
override val url: String,
|
||||
@SerialName(thumbUrlField)
|
||||
override val thumbUrl: String,
|
||||
@SerialName(thumbMimeTypeField)
|
||||
override val thumbMimeType: MimeType? = null,
|
||||
@SerialName(gifWidthField)
|
||||
override val width: Int? = null,
|
||||
@SerialName(gifHeightField)
|
||||
@ -36,4 +39,10 @@ data class InlineQueryResultGifImpl(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultGif {
|
||||
override val type: String = inlineQueryResultGifType
|
||||
|
||||
init {
|
||||
if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) {
|
||||
error("Passed thumb mime type is not permitted in Telegram Bot API. Passed $thumbMimeType, but permitted $telegramInlineModeGifPermittedMimeTypes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -18,6 +19,8 @@ data class InlineQueryResultMpeg4GifImpl(
|
||||
override val url: String,
|
||||
@SerialName(thumbUrlField)
|
||||
override val thumbUrl: String,
|
||||
@SerialName(thumbMimeTypeField)
|
||||
override val thumbMimeType: MimeType? = null,
|
||||
@SerialName(mpeg4GifWidthField)
|
||||
override val width: Int? = null,
|
||||
@SerialName(mpeg4GifHeightField)
|
||||
@ -36,4 +39,10 @@ data class InlineQueryResultMpeg4GifImpl(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultMpeg4Gif {
|
||||
override val type: String = inlineQueryResultMpeg4GifType
|
||||
|
||||
init {
|
||||
if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) {
|
||||
error("Passed thumb mime type is not permitted in Telegram Bot API. Passed $thumbMimeType, but permitted $telegramInlineModeGifPermittedMimeTypes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||
|
||||
interface ThumbedInlineQueryResult : InlineQueryResult {
|
||||
val thumbUrl: String?
|
||||
}
|
||||
|
||||
interface ThumbedWithMimeTypeInlineQueryResult : ThumbedInlineQueryResult {
|
||||
val thumbMimeType: MimeType?
|
||||
}
|
@ -2,4 +2,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQue
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
|
||||
|
||||
interface InlineQueryResultGif : InlineQueryResultGifCommon, UrlInlineQueryResult, ThumbedInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
interface InlineQueryResultGif : InlineQueryResultGifCommon, UrlInlineQueryResult, ThumbedWithMimeTypeInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
@ -2,4 +2,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQue
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
|
||||
|
||||
interface InlineQueryResultMpeg4Gif : InlineQueryResultMpeg4GifCommon, UrlInlineQueryResult, ThumbedInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
||||
interface InlineQueryResultMpeg4Gif : InlineQueryResultMpeg4GifCommon, UrlInlineQueryResult, ThumbedWithMimeTypeInlineQueryResult, SizedInlineQueryResult, DuratedInlineResultQuery
|
@ -0,0 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
object BuiltinMimeTypes {
|
||||
object Image {
|
||||
val Jpg = buildMimeType("image/jpeg")
|
||||
val Gif = buildMimeType("image/gif")
|
||||
}
|
||||
object Video {
|
||||
val MP4 = buildMimeType("video/mp4")
|
||||
}
|
||||
}
|
@ -7,5 +7,7 @@ expect class MimeType {
|
||||
val raw: String
|
||||
}
|
||||
|
||||
expect fun buildMimeType(raw: String): MimeType
|
||||
|
||||
@Serializer(MimeType::class)
|
||||
internal expect object MimeTypeSerializer : KSerializer<MimeType>
|
||||
|
@ -23,7 +23,7 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
override fun deserialize(decoder: Decoder): MimeType {
|
||||
val mimeType = decoder.decodeString()
|
||||
return mimesCache.getOrPut(mimeType) {
|
||||
MimeType(mimeType)
|
||||
buildMimeType(mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,3 +31,5 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
encoder.encodeString(value.raw)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun buildMimeType(raw: String) = MimeType(raw)
|
||||
|
@ -24,3 +24,5 @@ internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||
encoder.encodeString(value.raw)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun buildMimeType(raw: String): MimeType = MimeType(raw)
|
||||
|
Loading…
Reference in New Issue
Block a user