From 541e00fa03d93fed604733bf88b0a5eccaf7e892 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Nov 2022 14:07:31 +0600 Subject: [PATCH] start rework --- .../api/InternalUtils/UpdatesUtils.kt | 24 +++ .../extensions/api/send/CopyMessages.kt | 14 +- .../tgbotapi/extensions/api/send/Replies.kt | 24 ++- .../api/send/RepliesWithChatsAndMessages.kt | 4 +- .../tgbotapi/extensions/api/send/Sends.kt | 8 +- .../api/send/media/SendMediaGroup.kt | 14 +- .../expectations/WaitContent.kt | 8 +- .../expectations/WaitContentMessage.kt | 8 +- .../expectations/WaitEditedContent.kt | 8 +- .../expectations/WaitEditedContentMessage.kt | 8 +- .../expectations/WaitMediaGroup.kt | 10 +- .../expectations/WaitMediaGroupMessages.kt | 10 +- .../triggers_handling/ContentTriggers.kt | 4 +- .../EditedContentTriggers.kt | 4 +- .../triggers_handling/MediaGroupTriggers.kt | 42 ++--- .../requests/send/media/SendMediaGroup.kt | 34 +++- .../types/message/ChannelMediaGroupMessage.kt | 4 +- .../types/message/CommonMediaGroupMessage.kt | 4 +- .../types/message/abstracts/CommonMessage.kt | 2 +- .../message/abstracts/MediaGroupMessage.kt | 4 +- .../PossiblySentViaBotCommonMessage.kt | 2 +- .../types/message/abstracts/PublicMessage.kt | 2 +- .../types/message/content/Abstracts.kt | 18 +- .../types/message/content/AbstractsMedia.kt | 28 ++- .../types/message/content/AudioContent.kt | 2 +- .../types/message/content/DocumentContent.kt | 2 +- .../message/content/MediaGroupContent.kt | 48 +++++ .../types/message/content/PhotoContent.kt | 2 +- .../types/message/content/Typealiases.kt | 8 +- .../types/message/content/VideoContent.kt | 2 +- .../ChannelPostMediaGroupUpdate.kt | 4 +- .../EditChannelPostMediaGroupUpdate.kt | 4 +- .../EditMessageMediaGroupUpdate.kt | 4 +- .../update/media_group/MediaGroupUpdate.kt | 6 +- .../media_group/MessageMediaGroupUpdate.kt | 4 +- .../MediaGroupContentMessageCreator.kt | 164 ++++++++++++++++++ .../tgbotapi/extensions/utils/ClassCasts.kt | 58 +++---- .../extensions/utils/ClassCastsNew.kt | 88 +++++----- .../extensions/utils/ContentCastsNew.kt | 6 +- .../tgbotapi/extensions/utils/WithContent.kt | 6 +- .../utils/shortcuts/FlowsUpdatesFilter.kt | 12 +- .../utils/shortcuts/MediaGroupsShortcuts.kt | 14 +- 42 files changed, 495 insertions(+), 227 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt index 3bc9a03bfa..01e9f0ff62 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt @@ -2,7 +2,31 @@ package dev.inmo.tgbotapi.extensions.api.InternalUtils import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.UpdateIdentifier +import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl +import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl +import dev.inmo.tgbotapi.types.message.UnconnectedFromChannelGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage +import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage +import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.abstracts.* import dev.inmo.tgbotapi.types.update.media_group.* diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt index 1673fd81ea..181213ca56 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessages.kt @@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.message.ParseMode import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate /** @@ -18,14 +18,14 @@ import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List>, + messages: List>, text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null -): List> { +): List> { val first = messages.first().content.toMediaGroupMemberTelegramMedia().let { if (text != null) { when (it) { @@ -57,7 +57,7 @@ suspend inline fun TelegramBot.copyMessages( */ suspend inline fun TelegramBot.copyMessages( toChat: Chat, - messages: List>, + messages: List>, text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, @@ -102,13 +102,13 @@ suspend inline fun TelegramBot.copyMessages( */ suspend inline fun TelegramBot.copyMessages( toChatId: ChatIdentifier, - messages: List>, + messages: List>, entities: TextSourcesList, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null -): List> { +): List> { val first = messages.first().content.toMediaGroupMemberTelegramMedia().let { when (it) { is TelegramMediaAudio -> TelegramMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb) @@ -136,7 +136,7 @@ suspend inline fun TelegramBot.copyMessages( */ suspend inline fun TelegramBot.copyMessages( toChat: Chat, - messages: List>, + messages: List>, entities: TextSourcesList, disableNotification: Boolean = false, protectContent: Boolean = false, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index e9f4fdeebe..d45ac32771 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -1027,18 +1027,16 @@ suspend fun TelegramBot.reply( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) { - execute( - content.createResend( - to.chat.id, - disableNotification, - protectContent, - to.messageId, - allowSendingWithoutReply, - replyMarkup - ) +) = execute( + content.createResend( + to.chat.id, + disableNotification, + protectContent, + to.messageId, + allowSendingWithoutReply, + replyMarkup ) -} +) /** * Will use [handleLiveLocation] with replying to [message] each time new message will be sent by live location update @@ -1219,7 +1217,7 @@ suspend fun TelegramBot.reply( allowSendingWithoutReply = allowSendingWithoutReply, replyMarkup = replyMarkup ) - is AudioMediaGroupContent -> reply( + is AudioMediaGroupPartContent -> reply( to = to, audio = content.media, text = text, @@ -1291,7 +1289,7 @@ suspend fun TelegramBot.reply( allowSendingWithoutReply = allowSendingWithoutReply, replyMarkup = replyMarkup ) - is AudioMediaGroupContent -> reply( + is AudioMediaGroupPartContent -> reply( to = to, audio = content.media, entities = entities, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt index 0a754e2c52..d88ffa5ad7 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt @@ -1298,7 +1298,7 @@ suspend fun TelegramBot.reply( allowSendingWithoutReply = allowSendingWithoutReply, replyMarkup = replyMarkup ) - is AudioMediaGroupContent -> reply( + is AudioMediaGroupPartContent -> reply( toChatId = toChatId, toMessageId = toMessageId, audio = content.media, @@ -1377,7 +1377,7 @@ suspend fun TelegramBot.reply( allowSendingWithoutReply = allowSendingWithoutReply, replyMarkup = replyMarkup ) - is AudioMediaGroupContent -> reply( + is AudioMediaGroupPartContent -> reply( toChatId = toChatId, toMessageId = toMessageId, audio = content.media, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt index 46305fbd0a..6eeeaaaaa1 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt @@ -1379,7 +1379,7 @@ suspend fun TelegramBot.send( @JvmName("sendMedaGroupByContent") suspend fun TelegramBot.send( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -1393,7 +1393,7 @@ suspend fun TelegramBot.send( @JvmName("sendMedaGroupByContent") suspend fun TelegramBot.send( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -1536,7 +1536,7 @@ suspend fun TelegramBot.send( @JvmName("sendVisualMediaGroupByContent") suspend fun TelegramBot.send( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -1549,7 +1549,7 @@ suspend fun TelegramBot.send( @JvmName("sendVisualMediaGroupByContent") suspend fun TelegramBot.send( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 70392452d5..d2dddf9e02 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -6,8 +6,8 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.chat.Chat -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent -import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent +import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.AudioContent import dev.inmo.tgbotapi.types.message.content.DocumentContent import dev.inmo.tgbotapi.utils.RiskFeature @@ -25,7 +25,7 @@ suspend fun TelegramBot.sendMediaGroup( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null ) = execute( - SendMediaGroup( + SendMediaGroup( chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply ) ) @@ -52,7 +52,7 @@ suspend fun TelegramBot.sendMediaGroup( @JvmName("sendMedaGroupByContent") suspend fun TelegramBot.sendMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -68,7 +68,7 @@ suspend fun TelegramBot.sendMediaGroup( @JvmName("sendMedaGroupByContent") suspend fun TelegramBot.sendMediaGroup( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -233,7 +233,7 @@ suspend fun TelegramBot.sendVisualMediaGroup( @JvmName("sendVisualMediaGroupByContent") suspend fun TelegramBot.sendVisualMediaGroup( chatId: ChatIdentifier, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, @@ -248,7 +248,7 @@ suspend fun TelegramBot.sendVisualMediaGroup( @JvmName("sendVisualMediaGroupByContent") suspend fun TelegramBot.sendVisualMediaGroup( chat: Chat, - media: List, + media: List, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 91bce4c17e..86028c62a8 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -66,12 +66,12 @@ suspend fun BehaviourContext.waitAudioMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) +) = waitContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitDocumentMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) +) = waitContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitMedia( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, @@ -81,12 +81,12 @@ suspend fun BehaviourContext.waitAnyMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) +) = waitContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitVisualMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) +) = waitContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitTextedMediaContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt index 9620795bf2..818da8ce2b 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt @@ -103,12 +103,12 @@ suspend fun BehaviourContext.waitAudioMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitMediaMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, @@ -118,12 +118,12 @@ suspend fun BehaviourContext.waitAnyMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitVisualMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitTextedMediaContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt index a552348dd8..7bac69114d 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContent.kt @@ -64,12 +64,12 @@ suspend fun BehaviourContext.waitEditedAudioMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedDocumentMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedMedia( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, @@ -79,12 +79,12 @@ suspend fun BehaviourContext.waitEditedAnyMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedVisualMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContent(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedTextedMediaContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContentMessage.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContentMessage.kt index c5204f68ec..f7c201374f 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContentMessage.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEditedContentMessage.kt @@ -81,12 +81,12 @@ suspend fun BehaviourContext.waitEditedAudioMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedDocumentMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedMediaMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, @@ -96,12 +96,12 @@ suspend fun BehaviourContext.waitEditedAnyMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedVisualMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, includeMediaGroups: Boolean = true -) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) +) = waitEditedContentMessage(initRequest, includeMediaGroups, errorFactory) suspend fun BehaviourContext.waitEditedTextedMediaContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt index 37260e9340..bc614d6962 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt @@ -14,7 +14,7 @@ typealias MediaGroupFilter = SimpleFilter>> @RiskFeature(lowLevelRiskFeatureMessage) -suspend inline fun BehaviourContext.buildMediaGroupWaiter( +suspend inline fun BehaviourContext.buildMediaGroupWaiter( initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null } ): Flow> = buildMediaGroupMessagesWaiter(initRequest, errorFactory).map { it.map { it.content } } @@ -22,19 +22,19 @@ suspend inline fun BehaviourContext.buildMediaGr suspend fun BehaviourContext.waitMediaGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupWaiter(initRequest, errorFactory) +) = buildMediaGroupWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitPlaylist( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupWaiter(initRequest, errorFactory) +) = buildMediaGroupWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitDocumentsGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupWaiter(initRequest, errorFactory) +) = buildMediaGroupWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitVisualGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupWaiter(initRequest, errorFactory) +) = buildMediaGroupWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitPhotoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroupMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroupMessages.kt index f75f8767b7..889e63de09 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroupMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroupMessages.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage import kotlinx.coroutines.flow.Flow @RiskFeature(lowLevelRiskFeatureMessage) -suspend inline fun BehaviourContext.buildMediaGroupMessagesWaiter( +suspend inline fun BehaviourContext.buildMediaGroupMessagesWaiter( initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null } ): Flow>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update -> @@ -26,19 +26,19 @@ suspend inline fun BehaviourContext.buildMediaGr suspend fun BehaviourContext.waitMediaGroupMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) +) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitPlaylistMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) +) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitDocumentsGroupMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) +) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitVisualGalleryMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) +) = buildMediaGroupMessagesWaiter(initRequest, errorFactory) suspend fun BehaviourContext.waitPhotoGalleryMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index e9a19d4d7d..4971de586e 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -287,7 +287,7 @@ suspend fun BC.onVenue( * data */ suspend fun BC.onAudioMediaGroup( - initialFilter: CommonMessageFilter? = null, + initialFilter: CommonMessageFilter? = null, subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver @@ -311,7 +311,7 @@ suspend fun BC.onAudioMediaGroup( * data */ suspend fun BC.onDocumentMediaGroupContent( - initialFilter: CommonMessageFilter? = null, + initialFilter: CommonMessageFilter? = null, subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt index e339c6f66f..0b6337d018 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EditedContentTriggers.kt @@ -222,7 +222,7 @@ suspend fun BC.onEditedVenue( * data */ suspend fun BC.onEditedAudioMediaGroup( - initialFilter: CommonMessageFilter? = null, + initialFilter: CommonMessageFilter? = null, subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver @@ -246,7 +246,7 @@ suspend fun BC.onEditedAudioMediaGroup( * data */ suspend fun BC.onEditedDocumentMediaGroupContent( - initialFilter: CommonMessageFilter? = null, + initialFilter: CommonMessageFilter? = null, subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver = MessageFilterByChat, markerFactory: MarkerFactory = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index 58efa0cee3..29a2cdad86 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -14,7 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature -internal suspend inline fun BC.buildMediaGroupTrigger( +internal suspend inline fun BC.buildMediaGroupTrigger( initialFilter: SimpleFilter>>? = null, noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, @@ -40,10 +40,10 @@ internal suspend inline fun BC.onMediaGroup( - initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, - markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> + initialFilter: SimpleFilter>>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -59,10 +59,10 @@ suspend fun BC.onMediaGroup( * data */ suspend fun BC.onPlaylist( - initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, - markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> + initialFilter: SimpleFilter>>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -78,10 +78,10 @@ suspend fun BC.onPlaylist( * data */ suspend fun BC.onDocumentsGroup( - initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, - markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> + initialFilter: SimpleFilter>>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -97,10 +97,10 @@ suspend fun BC.onDocumentsGroup( * data */ suspend fun BC.onVisualGallery( - initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, - markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> + initialFilter: SimpleFilter>>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = buildMediaGroupTrigger(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** @@ -116,10 +116,10 @@ suspend fun BC.onVisualGallery( * data */ suspend fun BC.onVisualMediaGroup( - initialFilter: SimpleFilter>>? = null, - subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, - markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, - scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> + initialFilter: SimpleFilter>>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver>, Update>? = MessagesFilterByChat, + markerFactory: MarkerFactory>, Any> = ByChatMediaGroupMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver>> ) = onVisualGallery(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index c19ff31c0f..f8b0dd4e0d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -7,21 +7,27 @@ import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.media.* import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent -import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent +import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.AudioContent import dev.inmo.tgbotapi.types.message.content.DocumentContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.extensions.asMediaGroupContent import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.buildJsonArray const val rawSendingMediaGroupsWarning = "Media groups contains restrictions related to combinations of media" + " types. Currently it is possible to combine photo + video OR audio OR documents" @RiskFeature(rawSendingMediaGroupsWarning) -fun SendMediaGroup( +fun SendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, @@ -107,10 +113,22 @@ inline fun SendVisualMediaGroup( protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null -) = SendMediaGroup(chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) +) = SendMediaGroup(chatId, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply) -private val messagesListSerializer: KSerializer>> - = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) +private object MessagesListSerializer: KSerializer> { + private val serializer = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass>()) + override val descriptor: SerialDescriptor = serializer.descriptor + + override fun deserialize(decoder: Decoder): PossiblySentViaBotCommonMessage { + val messages = serializer.deserialize(decoder) + return messages.asMediaGroupContent() + } + + override fun serialize(encoder: Encoder, value: PossiblySentViaBotCommonMessage) { + serializer.serialize(encoder, value.content.group.map { it.sourceMessage }) + } + +} @Serializable data class SendMediaGroupData internal constructor( @@ -125,7 +143,7 @@ data class SendMediaGroupData internal constructor( override val replyToMessageId: MessageId? = null, @SerialName(allowSendingWithoutReplyField) override val allowSendingWithoutReply: Boolean? = null -) : DataRequest>>, SendMessageRequest>> { +) : DataRequest>>, SendMessageRequest>> { @SerialName(mediaField) private val convertedMedia: String get() = buildJsonArray { @@ -138,7 +156,7 @@ data class SendMediaGroupData internal constructor( override fun method(): String = "sendMediaGroup" override val requestSerializer: SerializationStrategy<*> get() = serializer() - override val resultDeserializer: DeserializationStrategy>> + override val resultDeserializer: DeserializationStrategy>> get() = messagesListSerializer } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt index 859e4415b3..b700a98ba2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt @@ -7,9 +7,9 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.Message -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -data class ChannelMediaGroupMessage( +data class ChannelMediaGroupMessage( override val messageId: MessageId, override val chat: Chat, override val date: DateTime, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt index ea544158d6..e1a2f98172 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt @@ -6,9 +6,9 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -data class CommonMediaGroupMessage( +data class CommonMediaGroupMessage( override val messageId: MessageId, override val from: User, override val chat: Chat, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt index bca2700613..2068ab6c33 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/CommonMessage.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.content.MessageContent -interface CommonMessage : Message, +sealed interface CommonMessage : Message, PossiblyForwardedMessage, PossiblyEditedMessage, PossiblyReplyMessage, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt index faac6c32eb..44a8fc7591 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.MediaGroupIdentifier -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -interface MediaGroupMessage : CommonMessage { +interface MediaGroupMessage : CommonMessage { val mediaGroupId: MediaGroupIdentifier } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblySentViaBotCommonMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblySentViaBotCommonMessage.kt index 155b0fdc17..5b7574457d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblySentViaBotCommonMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblySentViaBotCommonMessage.kt @@ -2,4 +2,4 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.content.MessageContent -interface PossiblySentViaBotCommonMessage : CommonMessage, PossiblySentViaBot +sealed interface PossiblySentViaBotCommonMessage : CommonMessage, PossiblySentViaBot diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt index 18a4b904b6..21264b6db0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt @@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.message.content.MessageContent -interface PublicContentMessage : PossiblySentViaBotCommonMessage { +sealed interface PublicContentMessage : PossiblySentViaBotCommonMessage { override val chat: PublicChat } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt index c1cc0c0a44..305561fe2a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt @@ -15,10 +15,10 @@ sealed interface MessageContent: ResendableContent { companion object { @RiskFeature("This serialization module can be changed in near releases") fun serializationModule( - visualMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, - documentMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, - audioMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, - mediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, + visualMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, + documentMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, + audioMediaGroupContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, + mediaGroupPartContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, textedMediaContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, mediaContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, mediaCollectionContentAdditionalBuilder: PolymorphicModuleBuilder>.() -> Unit = {}, @@ -73,24 +73,24 @@ sealed interface MessageContent: ResendableContent { textedMediaContentAdditionalBuilder() } - polymorphic(MediaGroupContent::class) { + polymorphic(MediaGroupPartContent::class) { subclass(PhotoContent::class) subclass(AudioContent::class) subclass(DocumentContent::class) - mediaGroupContentAdditionalBuilder() + mediaGroupPartContentAdditionalBuilder() } - polymorphic(AudioMediaGroupContent::class) { + polymorphic(AudioMediaGroupPartContent::class) { subclass(AudioContent::class) audioMediaGroupContentAdditionalBuilder() } - polymorphic(DocumentMediaGroupContent::class) { + polymorphic(DocumentMediaGroupPartContent::class) { subclass(DocumentContent::class) documentMediaGroupContentAdditionalBuilder() } - polymorphic(VisualMediaGroupContent::class) { + polymorphic(VisualMediaGroupPartContent::class) { subclass(PhotoContent::class) subclass(VideoContent::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt index 3d31a732c1..3f5cc6adcc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt @@ -1,28 +1,44 @@ package dev.inmo.tgbotapi.types.message.content import dev.inmo.tgbotapi.abstracts.TextedInput +import dev.inmo.tgbotapi.types.MediaGroupIdentifier +import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.media.* +import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage +import kotlinx.serialization.Serializable -sealed interface AudioMediaGroupContent : MediaGroupContent { +sealed interface AudioMediaGroupPartContent : MediaGroupPartContent { override val media: AudioFile override fun toMediaGroupMemberTelegramMedia(): AudioMediaGroupMemberTelegramMedia } -sealed interface DocumentMediaGroupContent : MediaGroupContent { +sealed interface DocumentMediaGroupPartContent : MediaGroupPartContent { override val media: DocumentFile override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia } -sealed interface MediaGroupContent : TextedMediaContent { +sealed interface TextedMediaContent : MediaContent, TextedInput + +sealed interface MediaGroupCollectionContent : TextedMediaContent { + @Serializable + data class PartWrapper( + val messageId: MessageId, + val content: MediaGroupPartContent, + val sourceMessage: PossiblySentViaBotCommonMessage + ) + val group: List + val mediaGroupId: MediaGroupIdentifier +} + +sealed interface MediaGroupPartContent : TextedMediaContent { fun toMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia } -sealed interface TextedMediaContent : MediaContent, TextedInput - -sealed interface VisualMediaGroupContent : MediaGroupContent { +sealed interface VisualMediaGroupPartContent : MediaGroupPartContent { override fun toMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AudioContent.kt index 27498e173f..18e43a5d4a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AudioContent.kt @@ -17,7 +17,7 @@ data class AudioContent( override val media: AudioFile, override val text: String? = null, override val textSources: TextSourcesList = emptyList() -) : AudioMediaGroupContent { +) : AudioMediaGroupPartContent { override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DocumentContent.kt index 56c82a6028..2098468dae 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DocumentContent.kt @@ -19,7 +19,7 @@ data class DocumentContent( override val media: DocumentFile, override val text: String? = null, override val textSources: TextSourcesList = emptyList() -) : DocumentMediaGroupContent { +) : DocumentMediaGroupPartContent { override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt new file mode 100644 index 0000000000..6f2f59fbc1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/MediaGroupContent.kt @@ -0,0 +1,48 @@ +package dev.inmo.tgbotapi.types.message.content + +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.requests.send.media.SendMediaGroup +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MediaGroupIdentifier +import dev.inmo.tgbotapi.types.MessageId +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.files.TelegramMediaFile +import dev.inmo.tgbotapi.types.media.TelegramMedia +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.textsources.TextSource +import kotlinx.serialization.Serializable + +@Serializable +data class MediaGroupContent( + override val group: List, + override val mediaGroupId: MediaGroupIdentifier +) : MediaGroupCollectionContent { + val mainContent: MediaGroupPartContent + get() = group.first().content + override val media: TelegramMediaFile + get() = mainContent.media + + override val textSources: List + get() = mainContent.textSources + override val text: String? + get() = mainContent.text + + override fun asTelegramMedia(): TelegramMedia = mainContent.asTelegramMedia() + + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + protectContent: Boolean, + replyToMessageId: MessageId?, + allowSendingWithoutReply: Boolean?, + replyMarkup: KeyboardMarkup? + ): Request = SendMediaGroup( + chatId, + group.map { it.content.toMediaGroupMemberTelegramMedia() }, + disableNotification, + protectContent, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt index 2d134a3c61..b97b852e10 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt @@ -17,7 +17,7 @@ data class PhotoContent( override val mediaCollection: Photo, override val text: String? = null, override val textSources: TextSourcesList = emptyList() -) : MediaCollectionContent, VisualMediaGroupContent { +) : MediaCollectionContent, VisualMediaGroupPartContent { override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content") override fun createResend( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Typealiases.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Typealiases.kt index 397ffde08e..f14628d24e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Typealiases.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Typealiases.kt @@ -20,12 +20,12 @@ typealias VideoNoteMessage = CommonMessage typealias StickerMessage = CommonMessage typealias TextedMediaMessage = CommonMessage typealias VoiceMessage = CommonMessage -typealias MediaGroupMessage = CommonMessage -typealias AudioMediaGroupMessage = CommonMessage +typealias MediaGroupMessage = CommonMessage +typealias AudioMediaGroupMessage = CommonMessage typealias AudioMessage = CommonMessage -typealias DocumentMediaGroupMessage = CommonMessage +typealias DocumentMediaGroupMessage = CommonMessage typealias DocumentMessage = CommonMessage -typealias VisualMediaGroupMessage = CommonMessage +typealias VisualMediaGroupMessage = CommonMessage typealias VideoMessage = CommonMessage typealias PhotoMessage = CommonMessage typealias AnimationMessage = CommonMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt index ef160c455f..76e6a8d2b3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt @@ -17,7 +17,7 @@ data class VideoContent( override val media: VideoFile, override val text: String? = null, override val textSources: TextSourcesList = emptyList() -) : VisualMediaGroupContent { +) : VisualMediaGroupPartContent { override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/ChannelPostMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/ChannelPostMediaGroupUpdate.kt index 85414d9489..21e6f13a0d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/ChannelPostMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/ChannelPostMediaGroupUpdate.kt @@ -2,12 +2,12 @@ package dev.inmo.tgbotapi.types.update.media_group import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate data class ChannelPostMediaGroupUpdate( override val origins: List ) : SentMediaGroupUpdate { override val updateId: UpdateIdentifier = origins.last().updateId - override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } + override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditChannelPostMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditChannelPostMediaGroupUpdate.kt index eaee526558..9af30060a1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditChannelPostMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditChannelPostMediaGroupUpdate.kt @@ -2,12 +2,12 @@ package dev.inmo.tgbotapi.types.update.media_group import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate data class EditChannelPostMediaGroupUpdate( override val origin: EditChannelPostUpdate ) : EditMediaGroupUpdate { override val updateId: UpdateIdentifier = origin.updateId - override val data: MediaGroupMessage = origin.data as MediaGroupMessage + override val data: MediaGroupMessage = origin.data as MediaGroupMessage } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditMessageMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditMessageMediaGroupUpdate.kt index cf9dddbeb3..ebed49e6c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditMessageMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditMessageMediaGroupUpdate.kt @@ -2,12 +2,12 @@ package dev.inmo.tgbotapi.types.update.media_group import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.EditMessageUpdate data class EditMessageMediaGroupUpdate( override val origin: EditMessageUpdate ) : EditMediaGroupUpdate { override val updateId: UpdateIdentifier = origin.updateId - override val data: MediaGroupMessage = origin.data as MediaGroupMessage + override val data: MediaGroupMessage = origin.data as MediaGroupMessage } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MediaGroupUpdate.kt index 7f9b13358b..0b8fd8ce15 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MediaGroupUpdate.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.update.media_group import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.abstracts.* /** @@ -14,11 +14,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.* sealed interface MediaGroupUpdate : Update sealed interface SentMediaGroupUpdate: MediaGroupUpdate { - override val data: List> + override val data: List> val origins: List } sealed interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate { - override val data: MediaGroupMessage + override val data: MediaGroupMessage val origin: BaseMessageUpdate } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MessageMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MessageMediaGroupUpdate.kt index 329d75c8d3..d36b7f50d8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MessageMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MessageMediaGroupUpdate.kt @@ -2,12 +2,12 @@ package dev.inmo.tgbotapi.types.update.media_group import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate data class MessageMediaGroupUpdate( override val origins: List ) : SentMediaGroupUpdate { override val updateId: UpdateIdentifier = origins.last().updateId - override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } + override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt new file mode 100644 index 0000000000..06cb6aaaaa --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -0,0 +1,164 @@ +package dev.inmo.tgbotapi.utils.extensions + +import dev.inmo.tgbotapi.types.MediaGroupIdentifier +import dev.inmo.tgbotapi.types.message.AnonymousForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl +import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.FromChannelForumContentMessageImpl +import dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl +import dev.inmo.tgbotapi.types.message.UnconnectedFromChannelGroupContentMessageImpl +import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage +import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.FromChannelForumContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage +import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupContentMessage +import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent +import dev.inmo.tgbotapi.utils.RiskFeature + +@RiskFeature("This API is experimental and can be changed without any notice, use with caution") +fun List>.asMediaGroupContent( + mediaGroupIdentifier: MediaGroupIdentifier +): PossiblySentViaBotCommonMessage { + val content = MediaGroupContent( + map { MediaGroupCollectionContent.PartWrapper(it.messageId, it.content, it) }, + mediaGroupIdentifier + ) + return when (val sourceMessage = first()) { + is MediaGroupMessage -> TODO() + is ChannelContentMessage -> ChannelContentMessageImpl( + sourceMessage.messageId, + sourceMessage.chat, + content, + sourceMessage.date, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.forwardInfo, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + is PrivateContentMessage -> PrivateContentMessageImpl( + sourceMessage.messageId, + sourceMessage.user, + sourceMessage.chat, + content, + sourceMessage.date, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.forwardInfo, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + sourceMessage.senderBot + ) + is AnonymousGroupContentMessage -> AnonymousGroupContentMessageImpl( + sourceMessage.chat, + sourceMessage.messageId, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + is CommonGroupContentMessage -> CommonGroupContentMessageImpl( + sourceMessage.chat, + sourceMessage.messageId, + sourceMessage.user, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot + ) + is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl( + sourceMessage.chat, + sourceMessage.channel, + sourceMessage.messageId, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + is UnconnectedFromChannelGroupContentMessage -> UnconnectedFromChannelGroupContentMessageImpl( + sourceMessage.chat, + sourceMessage.channel, + sourceMessage.messageId, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + is AnonymousForumContentMessage -> AnonymousForumContentMessageImpl( + sourceMessage.chat, + sourceMessage.messageId, + sourceMessage.threadId, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + is CommonForumContentMessage -> CommonForumContentMessageImpl( + sourceMessage.chat, + sourceMessage.messageId, + sourceMessage.threadId, + sourceMessage.user, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot + ) + is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl( + sourceMessage.chat, + sourceMessage.channel, + sourceMessage.messageId, + sourceMessage.threadId, + sourceMessage.date, + sourceMessage.forwardInfo, + sourceMessage.editDate, + sourceMessage.hasProtectedContent, + sourceMessage.replyTo, + sourceMessage.replyMarkup, + content, + sourceMessage.senderBot, + sourceMessage.authorSignature + ) + } +} diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 0a9cfa3e83..293aaf0788 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -1038,16 +1038,16 @@ inline fun Message.requireChannelEventMessage(): ChannelEventMessage @PreviewFeature -inline fun Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage) -> T) = +inline fun Message.whenChannelMediaGroupMessage(block: (ChannelMediaGroupMessage) -> T) = asChannelMediaGroupMessage()?.let(block) @PreviewFeature -inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage? = - this as? ChannelMediaGroupMessage +inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage? = + this as? ChannelMediaGroupMessage @PreviewFeature -inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage = - this as ChannelMediaGroupMessage +inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage = + this as ChannelMediaGroupMessage @PreviewFeature inline fun Message.whenCommonGroupEventMessage(block: (CommonGroupEventMessage) -> T) = @@ -1062,16 +1062,16 @@ inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage @PreviewFeature -inline fun Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T) = +inline fun Message.whenCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T) = asCommonMediaGroupMessage()?.let(block) @PreviewFeature -inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage? = - this as? CommonMediaGroupMessage +inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage? = + this as? CommonMediaGroupMessage @PreviewFeature -inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage = - this as CommonMediaGroupMessage +inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage = + this as CommonMediaGroupMessage @PreviewFeature inline fun Message.whenCommonSupergroupEventMessage(block: (CommonSupergroupEventMessage) -> T) = @@ -1220,16 +1220,16 @@ inline fun Message.requireGroupContentMessage(): GroupContentMessage @PreviewFeature -inline fun Message.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) = +inline fun Message.whenMediaGroupMessage(block: (MediaGroupMessage) -> T) = asMediaGroupMessage()?.let(block) @PreviewFeature -inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = - this as? MediaGroupMessage +inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = + this as? MediaGroupMessage @PreviewFeature -inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = - this as MediaGroupMessage +inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = + this as MediaGroupMessage @PreviewFeature inline fun Message.whenPossiblyEditedMessage(block: (PossiblyEditedMessage) -> T) = @@ -2836,26 +2836,26 @@ inline fun ResendableContent.asVenueContent(): VenueContent? = this as? VenueCon inline fun ResendableContent.requireVenueContent(): VenueContent = this as VenueContent @PreviewFeature -inline fun ResendableContent.whenAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T) = +inline fun ResendableContent.whenAudioMediaGroupContent(block: (AudioMediaGroupPartContent) -> T) = asAudioMediaGroupContent()?.let(block) @PreviewFeature -inline fun ResendableContent.asAudioMediaGroupContent(): AudioMediaGroupContent? = this as? AudioMediaGroupContent +inline fun ResendableContent.asAudioMediaGroupContent(): AudioMediaGroupPartContent? = this as? AudioMediaGroupPartContent @PreviewFeature -inline fun ResendableContent.requireAudioMediaGroupContent(): AudioMediaGroupContent = this as AudioMediaGroupContent +inline fun ResendableContent.requireAudioMediaGroupContent(): AudioMediaGroupPartContent = this as AudioMediaGroupPartContent @PreviewFeature -inline fun ResendableContent.whenDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T) = +inline fun ResendableContent.whenDocumentMediaGroupContent(block: (DocumentMediaGroupPartContent) -> T) = asDocumentMediaGroupContent()?.let(block) @PreviewFeature -inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupContent? = - this as? DocumentMediaGroupContent +inline fun ResendableContent.asDocumentMediaGroupContent(): DocumentMediaGroupPartContent? = + this as? DocumentMediaGroupPartContent @PreviewFeature -inline fun ResendableContent.requireDocumentMediaGroupContent(): DocumentMediaGroupContent = - this as DocumentMediaGroupContent +inline fun ResendableContent.requireDocumentMediaGroupContent(): DocumentMediaGroupPartContent = + this as DocumentMediaGroupPartContent @PreviewFeature inline fun ResendableContent.whenMediaCollectionContent(block: (MediaCollectionContent) -> T) = @@ -2891,14 +2891,14 @@ inline fun ResendableContent.asMediaContent(): MediaContent? = this as? MediaCon inline fun ResendableContent.requireMediaContent(): MediaContent = this as MediaContent @PreviewFeature -inline fun ResendableContent.whenMediaGroupContent(block: (MediaGroupContent) -> T) = +inline fun ResendableContent.whenMediaGroupContent(block: (MediaGroupPartContent) -> T) = asMediaGroupContent()?.let(block) @PreviewFeature -inline fun ResendableContent.asMediaGroupContent(): MediaGroupContent? = this as? MediaGroupContent +inline fun ResendableContent.asMediaGroupContent(): MediaGroupPartContent? = this as? MediaGroupPartContent @PreviewFeature -inline fun ResendableContent.requireMediaGroupContent(): MediaGroupContent = this as MediaGroupContent +inline fun ResendableContent.requireMediaGroupContent(): MediaGroupPartContent = this as MediaGroupPartContent @PreviewFeature inline fun ResendableContent.whenMessageContent(block: (MessageContent) -> T) = asMessageContent()?.let(block) @@ -2910,14 +2910,14 @@ inline fun ResendableContent.asMessageContent(): MessageContent? = this as? Mess inline fun ResendableContent.requireMessageContent(): MessageContent = this as MessageContent @PreviewFeature -inline fun ResendableContent.whenVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T) = +inline fun ResendableContent.whenVisualMediaGroupContent(block: (VisualMediaGroupPartContent) -> T) = asVisualMediaGroupContent()?.let(block) @PreviewFeature -inline fun ResendableContent.asVisualMediaGroupContent(): VisualMediaGroupContent? = this as? VisualMediaGroupContent +inline fun ResendableContent.asVisualMediaGroupContent(): VisualMediaGroupPartContent? = this as? VisualMediaGroupPartContent @PreviewFeature -inline fun ResendableContent.requireVisualMediaGroupContent(): VisualMediaGroupContent = this as VisualMediaGroupContent +inline fun ResendableContent.requireVisualMediaGroupContent(): VisualMediaGroupPartContent = this as VisualMediaGroupPartContent @PreviewFeature inline fun ResendableContent.whenAnimationContent(block: (AnimationContent) -> T) = asAnimationContent()?.let(block) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index c2091ffb91..3f8b1f52ad 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -288,18 +288,18 @@ import dev.inmo.tgbotapi.types.message.abstracts.UnconnectedFromChannelGroupCont import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType import dev.inmo.tgbotapi.types.message.content.AnimationContent import dev.inmo.tgbotapi.types.message.content.AudioContent -import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.ContactContent import dev.inmo.tgbotapi.types.message.content.DiceContent import dev.inmo.tgbotapi.types.message.content.DocumentContent -import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.GameContent import dev.inmo.tgbotapi.types.message.content.InvoiceContent import dev.inmo.tgbotapi.types.message.content.LiveLocationContent import dev.inmo.tgbotapi.types.message.content.LocationContent import dev.inmo.tgbotapi.types.message.content.MediaCollectionContent import dev.inmo.tgbotapi.types.message.content.MediaContent -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.MessageContent import dev.inmo.tgbotapi.types.message.content.PhotoContent import dev.inmo.tgbotapi.types.message.content.PollContent @@ -311,7 +311,7 @@ import dev.inmo.tgbotapi.types.message.content.TextedMediaContent import dev.inmo.tgbotapi.types.message.content.VenueContent import dev.inmo.tgbotapi.types.message.content.VideoContent import dev.inmo.tgbotapi.types.message.content.VideoNoteContent -import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.VoiceContent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.textsources.BoldTextSource @@ -737,15 +737,15 @@ public inline fun commonGroupEventMessageOrNull() ?.let(block) public inline fun WithUser.commonMediaGroupMessageOrNull(): - CommonMediaGroupMessage? = this as? - dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage + CommonMediaGroupMessage? = this as? + dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage public inline fun WithUser.commonMediaGroupMessageOrThrow(): - CommonMediaGroupMessage = this as - dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage + CommonMediaGroupMessage = this as + dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage public inline fun - WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T): T? + WithUser.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T): T? = commonMediaGroupMessageOrNull() ?.let(block) public inline fun WithUser.commonSupergroupEventMessageOrNull(): @@ -2986,15 +2986,15 @@ public inline fun channelEventMessageOrNull() ?.let(block) public inline fun Message.channelMediaGroupMessageOrNull(): - ChannelMediaGroupMessage? = this as? - dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage + ChannelMediaGroupMessage? = this as? + dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage public inline fun Message.channelMediaGroupMessageOrThrow(): - ChannelMediaGroupMessage = this as - dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage + ChannelMediaGroupMessage = this as + dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage public inline fun - Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage) -> T): + Message.ifChannelMediaGroupMessage(block: (ChannelMediaGroupMessage) -> T): T? = channelMediaGroupMessageOrNull() ?.let(block) public inline fun Message.commonGroupEventMessageOrNull(): CommonGroupEventMessage? = @@ -3010,15 +3010,15 @@ public inline fun commonGroupEventMessageOrNull() ?.let(block) public inline fun Message.commonMediaGroupMessageOrNull(): - CommonMediaGroupMessage? = this as? - dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage + CommonMediaGroupMessage? = this as? + dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage public inline fun Message.commonMediaGroupMessageOrThrow(): - CommonMediaGroupMessage = this as - dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage + CommonMediaGroupMessage = this as + dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage public inline fun - Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T): T? + Message.ifCommonMediaGroupMessage(block: (CommonMediaGroupMessage) -> T): T? = commonMediaGroupMessageOrNull() ?.let(block) public inline fun Message.commonSupergroupEventMessageOrNull(): @@ -3325,15 +3325,15 @@ public inline fun Message.ifCommonForumContentMessage(block: (CommonForumContentMessage) -> T): T? = commonForumContentMessageOrNull() ?.let(block) -public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage? = this +public inline fun Message.mediaGroupMessageOrNull(): MediaGroupMessage? = this as? - dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage + dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -public inline fun Message.mediaGroupMessageOrThrow(): MediaGroupMessage = this as - dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +public inline fun Message.mediaGroupMessageOrThrow(): MediaGroupMessage = this as + dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage public inline fun - Message.ifMediaGroupMessage(block: (MediaGroupMessage) -> T): T? = + Message.ifMediaGroupMessage(block: (MediaGroupMessage) -> T): T? = mediaGroupMessageOrNull() ?.let(block) public inline fun Message.unknownMessageTypeOrNull(): UnknownMessageType? = this as? @@ -3459,33 +3459,33 @@ public inline fun ResendableContent.mediaContentOrThrow(): MediaContent = this a public inline fun ResendableContent.ifMediaContent(block: (MediaContent) -> T): T? = mediaContentOrNull() ?.let(block) -public inline fun ResendableContent.audioMediaGroupContentOrNull(): AudioMediaGroupContent? = this - as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent +public inline fun ResendableContent.audioMediaGroupContentOrNull(): AudioMediaGroupPartContent? = this + as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent -public inline fun ResendableContent.audioMediaGroupContentOrThrow(): AudioMediaGroupContent = this - as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent +public inline fun ResendableContent.audioMediaGroupContentOrThrow(): AudioMediaGroupPartContent = this + as dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent public inline fun - ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupContent) -> T): T? = + ResendableContent.ifAudioMediaGroupContent(block: (AudioMediaGroupPartContent) -> T): T? = audioMediaGroupContentOrNull() ?.let(block) -public inline fun ResendableContent.documentMediaGroupContentOrNull(): DocumentMediaGroupContent? = - this as? dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent +public inline fun ResendableContent.documentMediaGroupContentOrNull(): DocumentMediaGroupPartContent? = + this as? dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent -public inline fun ResendableContent.documentMediaGroupContentOrThrow(): DocumentMediaGroupContent = - this as dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent +public inline fun ResendableContent.documentMediaGroupContentOrThrow(): DocumentMediaGroupPartContent = + this as dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupPartContent public inline fun - ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupContent) -> T): T? = + ResendableContent.ifDocumentMediaGroupContent(block: (DocumentMediaGroupPartContent) -> T): T? = documentMediaGroupContentOrNull() ?.let(block) -public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupContent? = this as? - dev.inmo.tgbotapi.types.message.content.MediaGroupContent +public inline fun ResendableContent.mediaGroupContentOrNull(): MediaGroupPartContent? = this as? + dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupContent = this as - dev.inmo.tgbotapi.types.message.content.MediaGroupContent +public inline fun ResendableContent.mediaGroupContentOrThrow(): MediaGroupPartContent = this as + dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -public inline fun ResendableContent.ifMediaGroupContent(block: (MediaGroupContent) -> T): T? = +public inline fun ResendableContent.ifMediaGroupContent(block: (MediaGroupPartContent) -> T): T? = mediaGroupContentOrNull() ?.let(block) public inline fun ResendableContent.textedMediaContentOrNull(): TextedMediaContent? = this as? @@ -3497,14 +3497,14 @@ public inline fun ResendableContent.textedMediaContentOrThrow(): TextedMediaCont public inline fun ResendableContent.ifTextedMediaContent(block: (TextedMediaContent) -> T): T? = textedMediaContentOrNull() ?.let(block) -public inline fun ResendableContent.visualMediaGroupContentOrNull(): VisualMediaGroupContent? = this - as? dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent +public inline fun ResendableContent.visualMediaGroupContentOrNull(): VisualMediaGroupPartContent? = this + as? dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent -public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupContent = this - as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent +public inline fun ResendableContent.visualMediaGroupContentOrThrow(): VisualMediaGroupPartContent = this + as dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent public inline fun - ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupContent) -> T): T? = + ResendableContent.ifVisualMediaGroupContent(block: (VisualMediaGroupPartContent) -> T): T? = visualMediaGroupContentOrNull() ?.let(block) public inline fun ResendableContent.animationContentOrNull(): AnimationContent? = this as? diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentCastsNew.kt index 05cd19bd49..fa337b2360 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentCastsNew.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.MessageContent inline fun ContentMessage<*>.withContentOrNull() = if (content is T) { this as ContentMessage } else { null } @@ -37,5 +37,5 @@ inline fun AnonymousGroupContentMessage<*>.withCont inline fun CommonGroupContentMessage<*>.withContentOrNull() = if (content is T) { this as CommonGroupContentMessage } else { null } inline fun CommonGroupContentMessage<*>.withContentOrThrow() = withContentOrNull()!! -inline fun MediaGroupMessage<*>.withContentOrNull() = if (content is T) { this as MediaGroupMessage } else { null } -inline fun MediaGroupMessage<*>.withContentOrThrow() = withContentOrNull()!! +inline fun MediaGroupMessage<*>.withContentOrNull() = if (content is T) { this as MediaGroupMessage } else { null } +inline fun MediaGroupMessage<*>.withContentOrThrow() = withContentOrNull()!! diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt index 80dea0da67..9f632f078f 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.MessageContent inline fun ContentMessage<*>.withContent() = if (content is T) { this as ContentMessage } else { null } @@ -37,5 +37,5 @@ inline fun AnonymousGroupContentMessage<*>.requireW inline fun CommonGroupContentMessage<*>.withContent() = if (content is T) { this as CommonGroupContentMessage } else { null } inline fun CommonGroupContentMessage<*>.requireWithContent() = withContent()!! -inline fun MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage } else { null } -inline fun MediaGroupMessage<*>.requireWithContent() = withContent()!! +inline fun MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage } else { null } +inline fun MediaGroupMessage<*>.requireWithContent() = withContent()!! diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt index 4b3956f4ac..53d52cf338 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/FlowsUpdatesFilter.kt @@ -31,7 +31,7 @@ inline fun Flow.filterContent ): Flow> = asContentMessagesFlow().mapNotNull(filterForContentMessage()) @RiskFeature("This method is low-level") -inline fun Flow.filterMediaGroupMessages( +inline fun Flow.filterMediaGroupMessages( ): Flow>> = map { it.data.mapNotNull { message -> if (message.content is T) { @@ -69,7 +69,7 @@ inline fun FlowsUpdatesFilter.filterContentMessages( */ @Suppress("UNCHECKED_CAST") @RiskFeature(lowLevelRiskFeatureMessage) -inline fun FlowsUpdatesFilter.filterMediaGroupMessages( +inline fun FlowsUpdatesFilter.filterMediaGroupMessages( scopeToIncludeChannels: CoroutineScope? = null ): Flow>> { return (scopeToIncludeChannels ?.let { scope -> @@ -212,10 +212,10 @@ fun FlowsUpdatesFilter.voiceMessages( ) = filterContentMessages(scopeToIncludeChannels) -fun Flow.mediaGroupMessages() = filterMediaGroupMessages() +fun Flow.mediaGroupMessages() = filterMediaGroupMessages() fun FlowsUpdatesFilter.mediaGroupMessages( scopeToIncludeChannels: CoroutineScope? = null -) = filterMediaGroupMessages(scopeToIncludeChannels) +) = filterMediaGroupMessages(scopeToIncludeChannels) fun Flow.mediaGroupPhotosMessages() = filterMediaGroupMessages() fun FlowsUpdatesFilter.mediaGroupPhotosMessages( @@ -227,10 +227,10 @@ fun FlowsUpdatesFilter.mediaGroupVideosMessages( scopeToIncludeChannels: CoroutineScope? = null ) = filterMediaGroupMessages(scopeToIncludeChannels) -fun Flow.mediaGroupVisualMessages() = filterMediaGroupMessages() +fun Flow.mediaGroupVisualMessages() = filterMediaGroupMessages() fun FlowsUpdatesFilter.mediaGroupVisualMessages( scopeToIncludeChannels: CoroutineScope? = null -) = filterMediaGroupMessages(scopeToIncludeChannels) +) = filterMediaGroupMessages(scopeToIncludeChannels) fun Flow.mediaGroupAudioMessages() = filterMediaGroupMessages() fun FlowsUpdatesFilter.mediaGroupAudioMessages( diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt index f5c106d568..0d5866e68d 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt @@ -5,14 +5,14 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.message.ForwardInfo import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.content.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate -val List>.forwardInfo: ForwardInfo? +val List>.forwardInfo: ForwardInfo? get() = firstOrNull() ?.forwardInfo -val List>.replyTo: Message? +val List>.replyTo: Message? get() = firstOrNull() ?.replyTo -val List>.chat: Chat? +val List>.chat: Chat? get() = firstOrNull() ?.chat val List>.mediaGroupId: MediaGroupIdentifier? get() = firstOrNull() ?.mediaGroupId @@ -26,12 +26,12 @@ val SentMediaGroupUpdate.chat: Chat val SentMediaGroupUpdate.mediaGroupId: MediaGroupIdentifier get() = data.mediaGroupId!! -fun List>.createResend( +fun List>.createResend( chatId: ChatId, disableNotification: Boolean = false, protectContent: Boolean = false, replyTo: MessageId? = null -) = SendMediaGroup( +) = SendMediaGroup( chatId, map { it.content.toMediaGroupMemberTelegramMedia() }, disableNotification, @@ -39,7 +39,7 @@ fun List>.createResend( replyTo ) -fun List>.createResend( +fun List>.createResend( chat: Chat, disableNotification: Boolean = false, protectContent: Boolean = false,