MediaCollectionContent as MediaContent

This commit is contained in:
InsanusMokrassar 2019-03-21 09:18:54 +08:00
parent bf3356bea9
commit 7d7a6ccf80
3 changed files with 10 additions and 5 deletions

View File

@ -44,6 +44,9 @@ for receivers.
* Removed deprecated method `T#toJsonWithoutNulls()`
* Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage`
will not contain `user` field (but `CommonMediaGroupMessage` will have)
* Now `MediaCollectionContent` is `MediaContent` (classes of this interface must choose best
media for present out)
* `PhotoContent` now choose biggest photo size from its collection as `media`
## 0.11.0

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstrac
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent {
val media: List<T>
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, MediaContent<T> {
val mediaCollection: List<T>
}

View File

@ -16,10 +16,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstract
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class PhotoContent(
override val media: List<PhotoSize>,
override val mediaCollection: List<PhotoSize>,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
@ -27,7 +29,7 @@ data class PhotoContent(
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPhoto(
chatId,
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"),
media.fileId,
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
disableNotification,
@ -36,7 +38,7 @@ data class PhotoContent(
)
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
media.fileId,
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode
)