1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

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()` * Removed deprecated method `T#toJsonWithoutNulls()`
* Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage` * Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage`
will not contain `user` field (but `CommonMediaGroupMessage` will have) 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 ## 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 import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent { interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, MediaContent<T> {
val media: List<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 import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class PhotoContent( data class PhotoContent(
override val media: List<PhotoSize>, override val mediaCollection: List<PhotoSize>,
override val caption: String? = null, override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList() override val captionEntities: List<MessageEntity> = emptyList()
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent { ) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,
disableNotification: Boolean, disableNotification: Boolean,
@ -27,7 +29,7 @@ data class PhotoContent(
replyMarkup: KeyboardMarkup? replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPhoto( ): Request<RawMessage> = SendPhoto(
chatId, chatId,
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"), media.fileId,
toMarkdownCaptions().firstOrNull(), toMarkdownCaptions().firstOrNull(),
MarkdownParseMode, MarkdownParseMode,
disableNotification, disableNotification,
@ -36,7 +38,7 @@ data class PhotoContent(
) )
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto( override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"), media.fileId,
toMarkdownCaptions().firstOrNull(), toMarkdownCaptions().firstOrNull(),
MarkdownParseMode MarkdownParseMode
) )