mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
optimise Photo#biggest, add MediaGroupContent#toMediaGroupMemberInputMedia
This commit is contained in:
parent
1518731786
commit
09cb429a59
@ -31,3 +31,4 @@
|
||||
* `MessageContent` now is `ResendableContent`
|
||||
* Now all media sending factories which contains `thumb` have default `null` value
|
||||
* `ChatIdentifier` classes now are `data` classes
|
||||
* Now `MediaGroupContent` interface contains `toMediaGroupMemberInputMedia` method for easily creating mirror input media
|
||||
|
@ -1,5 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
interface DuratedInputMedia : InputMedia {
|
||||
val duration: Int?
|
||||
val duration: Long?
|
||||
}
|
@ -20,7 +20,7 @@ data class InputMediaAnimation(
|
||||
@Optional
|
||||
override val height: Int? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
override val duration: Long? = null,
|
||||
@Transient
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia {
|
||||
|
@ -16,7 +16,7 @@ data class InputMediaAudio(
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
override val duration: Long? = null,
|
||||
@Optional
|
||||
val performer: String? = null,
|
||||
@Optional
|
||||
|
@ -20,7 +20,7 @@ data class InputMediaVideo(
|
||||
@Optional
|
||||
override val height: Int? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
override val duration: Long? = null,
|
||||
@Transient
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
|
||||
|
@ -7,14 +7,8 @@ import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
typealias Photo = List<PhotoSize>
|
||||
|
||||
fun Photo.biggest(): PhotoSize? {
|
||||
var biggest: PhotoSize = firstOrNull() ?: return null
|
||||
forEach {
|
||||
if (it.resolution > biggest.resolution) {
|
||||
biggest = it
|
||||
}
|
||||
}
|
||||
return biggest
|
||||
fun Photo.biggest(): PhotoSize? = maxBy {
|
||||
it.resolution
|
||||
}
|
||||
|
||||
object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
|
||||
|
@ -1,3 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
|
||||
|
||||
interface MediaGroupContent : MessageContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||
|
||||
interface MediaGroupContent : MessageContent {
|
||||
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
|
||||
}
|
@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaPhoto
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
||||
@ -32,4 +34,10 @@ data class PhotoContent(
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
|
||||
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
|
||||
toMarkdownCaption(),
|
||||
MarkdownParseMode
|
||||
)
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaVideo
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
||||
@ -36,4 +38,14 @@ data class VideoContent(
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaVideo(
|
||||
media.fileId,
|
||||
toMarkdownCaption(),
|
||||
MarkdownParseMode,
|
||||
media.width,
|
||||
media.height,
|
||||
media.duration,
|
||||
media.thumb ?.fileId
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user