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 01e9f0ff62..b559d65f18 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,31 +2,6 @@ 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 bbdaa00039..2ab20d94bc 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,6 @@ import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageThreadId 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.MediaGroupPartContent import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt index 54845e4c3a..16e695fe1f 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.utils import dev.inmo.tgbotapi.extensions.api.InternalUtils.convertWithMediaGroupUpdates -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver 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 f7c201374f..9b39b1f911 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 @@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull import dev.inmo.tgbotapi.extensions.utils.withContent import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate import dev.inmo.tgbotapi.utils.RiskFeature 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 bc614d6962..5e38f5555e 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 @@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage 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 889e63de09..828a582942 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 @@ -4,7 +4,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull import dev.inmo.tgbotapi.extensions.utils.withContent import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage 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 29a2cdad86..5394ec31b4 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 @@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.utils.PreviewFeature diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt index 233d3f3a3b..e4e0a5838b 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MediaGroupMarkerFactories.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage object ByChatMediaGroupMarkerFactory : MarkerFactory>, Any> { override suspend fun invoke(data: List>) = data.chat ?: error("Data must not be empty") 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 34e376a1c4..cdca64dc56 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 @@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest 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.MediaGroupPartContent @@ -15,13 +14,16 @@ 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 dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage 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.JsonArray +import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.buildJsonArray +import kotlinx.serialization.json.jsonPrimitive 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" @@ -35,7 +37,7 @@ fun SendMediaGroup( protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null -): Request>> { +): Request> { if (media.size !in mediaCountInMediaGroup) { throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) } @@ -68,7 +70,7 @@ fun SendMediaGroup( data, SendMediaGroupFiles(files) ) - }) as Request>> + }) as Request> } /** @@ -126,7 +128,7 @@ private object MessagesListSerializer: KSerializer { val messages = serializer.deserialize(decoder) - return messages.asMediaGroupContent() + return messages.asMediaGroupMessage() } override fun serialize(encoder: Encoder, value: PossiblySentViaBotCommonMessage) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index bceec5ef4c..a9ff556602 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -151,6 +151,7 @@ const val chatIdField = "chat_id" const val senderChatIdField = "sender_chat_id" const val messageIdField = "message_id" const val messageThreadIdField = "message_thread_id" +const val mediaGroupIdField = "media_group_id" const val updateIdField = "update_id" const val fromChatIdField = "from_chat_id" const val disableWebPagePreviewField = "disable_web_page_preview" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt index a9ff456ec5..a53ce0f3c9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt @@ -19,5 +19,6 @@ data class ChannelContentMessageImpl( override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : ChannelContentMessage 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 deleted file mode 100644 index 4126168856..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ /dev/null @@ -1,25 +0,0 @@ -package dev.inmo.tgbotapi.types.message - -import com.soywiz.klock.DateTime -import dev.inmo.tgbotapi.types.MediaGroupIdentifier -import dev.inmo.tgbotapi.types.MessageId -import dev.inmo.tgbotapi.types.MessageThreadId -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.MediaGroupPartContent - -data class ChannelMediaGroupMessage( - override val messageId: MessageId, - override val threadId: MessageThreadId?, - override val chat: Chat, - override val date: DateTime, - override val mediaGroupId: MediaGroupIdentifier, - override val content: T, - override val editDate: DateTime?, - override val hasProtectedContent: Boolean, - override val forwardInfo: ForwardInfo?, - override val replyTo: Message?, - override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage 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 deleted file mode 100644 index f19fa0e779..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.inmo.tgbotapi.types.message - -import com.soywiz.klock.DateTime -import dev.inmo.tgbotapi.types.* -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.MediaGroupPartContent - -data class CommonMediaGroupMessage( - override val messageId: MessageId, - override val threadId: MessageThreadId?, - override val from: User, - override val chat: Chat, - override val date: DateTime, - override val mediaGroupId: MediaGroupIdentifier, - override val content: T, - override val editDate: DateTime?, - override val hasProtectedContent: Boolean, - override val forwardInfo: ForwardInfo?, - override val replyTo: Message?, - override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index f297b81df1..a3fd4d4dcc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -21,7 +21,8 @@ data class ConnectedFromChannelGroupContentMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : ConnectedFromChannelGroupContentMessage data class UnconnectedFromChannelGroupContentMessageImpl( @@ -36,7 +37,8 @@ data class UnconnectedFromChannelGroupContentMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : UnconnectedFromChannelGroupContentMessage data class AnonymousGroupContentMessageImpl( @@ -50,7 +52,8 @@ data class AnonymousGroupContentMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : AnonymousGroupContentMessage data class CommonGroupContentMessageImpl( @@ -64,7 +67,8 @@ data class CommonGroupContentMessageImpl( override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, - override val senderBot: CommonBot? + override val senderBot: CommonBot?, + override val mediaGroupId: MediaGroupIdentifier?, ) : CommonGroupContentMessage data class FromChannelForumContentMessageImpl( @@ -80,7 +84,8 @@ data class FromChannelForumContentMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : FromChannelForumContentMessage data class AnonymousForumContentMessageImpl( @@ -95,7 +100,8 @@ data class AnonymousForumContentMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, - override val authorSignature: AuthorSignature? + override val authorSignature: AuthorSignature?, + override val mediaGroupId: MediaGroupIdentifier?, ) : AnonymousForumContentMessage data class CommonForumContentMessageImpl( @@ -110,5 +116,6 @@ data class CommonForumContentMessageImpl( override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, - override val senderBot: CommonBot? + override val senderBot: CommonBot?, + override val mediaGroupId: MediaGroupIdentifier?, ) : CommonForumContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt index 300b2afc3f..aac98484a3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt @@ -21,5 +21,6 @@ data class PrivateContentMessageImpl( override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, - override val senderBot: CommonBot? + override val senderBot: CommonBot?, + override val mediaGroupId: MediaGroupIdentifier?, ) : PrivateContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 65f2635202..2e63c28a71 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -269,45 +269,7 @@ internal data class RawMessage( ) else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)") } - } ?: content?.let { content -> - media_group_id?.let { - val checkedContent = when (content) { - is PhotoContent -> content - is VideoContent -> content - is AudioContent -> content - is DocumentContent -> content - else -> error("Unsupported content for media group") - } - when (from) { - null -> ChannelMediaGroupMessage( - messageId, - messageThreadId, - chat, - date.asDate, - it, - checkedContent, - edit_date?.asDate, - has_protected_content == true, - forwarded, - reply_to_message?.asMessage, - reply_markup - ) - else -> CommonMediaGroupMessage( - messageId, - messageThreadId, - from, - chat, - date.asDate, - it, - checkedContent, - edit_date?.asDate, - has_protected_content == true, - forwarded, - reply_to_message?.asMessage, - reply_markup - ) - } - } ?: when (chat) { + } ?: content?.let { content -> when (chat) { is PublicChat -> when (chat) { is ChannelChat -> ChannelContentMessageImpl( messageId, @@ -320,7 +282,8 @@ internal data class RawMessage( reply_to_message?.asMessage, reply_markup, via_bot, - author_signature + author_signature, + media_group_id ) is ForumChat -> if (messageThreadId != null) { when (sender_chat) { @@ -337,7 +300,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) is GroupChat -> AnonymousForumContentMessageImpl( chat, @@ -351,7 +315,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) null -> CommonForumContentMessageImpl( chat, @@ -365,7 +330,8 @@ internal data class RawMessage( reply_to_message ?.asMessage, reply_markup, content, - via_bot + via_bot, + media_group_id ) } } else { @@ -383,7 +349,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) } else { UnconnectedFromChannelGroupContentMessageImpl( @@ -398,7 +365,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) } is GroupChat -> AnonymousGroupContentMessageImpl( @@ -412,7 +380,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) null -> CommonGroupContentMessageImpl( chat, @@ -425,7 +394,8 @@ internal data class RawMessage( reply_to_message ?.asMessage, reply_markup, content, - via_bot + via_bot, + media_group_id ) } } @@ -443,7 +413,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) } else { UnconnectedFromChannelGroupContentMessageImpl( @@ -458,7 +429,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) } is GroupChat -> AnonymousGroupContentMessageImpl( @@ -472,7 +444,8 @@ internal data class RawMessage( reply_markup, content, via_bot, - author_signature + author_signature, + media_group_id ) null -> CommonGroupContentMessageImpl( chat, @@ -485,7 +458,8 @@ internal data class RawMessage( reply_to_message ?.asMessage, reply_markup, content, - via_bot + via_bot, + media_group_id ) } } @@ -500,7 +474,8 @@ internal data class RawMessage( forwarded, reply_to_message?.asMessage, reply_markup, - via_bot + via_bot, + media_group_id ) else -> error("Unknown type of 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 2068ab6c33..7adf185282 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 @@ -7,4 +7,5 @@ sealed interface CommonMessage : Message, PossiblyEditedMessage, PossiblyReplyMessage, PossiblyMarkedUp, + PossiblyMediaGroupMessage, ContentMessage 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 deleted file mode 100644 index 9555501955..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.message.abstracts - -import dev.inmo.tgbotapi.types.MediaGroupIdentifier -import dev.inmo.tgbotapi.types.MessageThreadId -import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent - -interface MediaGroupMessage : CommonMessage { - val mediaGroupId: MediaGroupIdentifier - val threadId: MessageThreadId? -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyMediaGroupMessage.kt new file mode 100644 index 0000000000..fa865da83b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyMediaGroupMessage.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.MediaGroupIdentifier +import dev.inmo.tgbotapi.types.message.content.MessageContent + +interface PossiblyMediaGroupMessage : ContentMessage { + val mediaGroupId: MediaGroupIdentifier? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt index 23a14e9dcf..b5cbaa55b8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/ChannelPostUpdate.kt @@ -7,4 +7,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class ChannelPostUpdate( override val updateId: UpdateIdentifier, override val data: Message -) : BaseSentMessageUpdate +) : BaseSentMessageUpdate { + override fun copy(newData: Message): BaseSentMessageUpdate = copy(updateId, newData) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt index 86d02a25c4..9585386627 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MessageUpdate.kt @@ -7,4 +7,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate data class MessageUpdate( override val updateId: UpdateIdentifier, override val data: Message -) : BaseSentMessageUpdate +) : BaseSentMessageUpdate { + override fun copy(newData: Message) = copy(updateId, newData) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt index bc8493432f..65efc5e9eb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/abstracts/BaseSentMessageUpdate.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.update.abstracts -interface BaseSentMessageUpdate : BaseMessageUpdate +import dev.inmo.tgbotapi.types.message.abstracts.Message + +interface BaseSentMessageUpdate : BaseMessageUpdate { + fun copy(newData: Message): BaseSentMessageUpdate +} 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 deleted file mode 100644 index 21e6f13a0d..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/ChannelPostMediaGroupUpdate.kt +++ /dev/null @@ -1,13 +0,0 @@ -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.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 } -} 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 deleted file mode 100644 index 9af30060a1..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditChannelPostMediaGroupUpdate.kt +++ /dev/null @@ -1,13 +0,0 @@ -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.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 -} 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 deleted file mode 100644 index ebed49e6c5..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/EditMessageMediaGroupUpdate.kt +++ /dev/null @@ -1,13 +0,0 @@ -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.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 -} 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 deleted file mode 100644 index 0b8fd8ce15..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MediaGroupUpdate.kt +++ /dev/null @@ -1,24 +0,0 @@ -package dev.inmo.tgbotapi.types.update.media_group - -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent -import dev.inmo.tgbotapi.types.update.abstracts.* - -/** - * By default there is no instances of objects which could be deserialized from raw updates. If you want to get objects - * with this type, you should use something like [dev.inmo.tgbotapi.extensions.api.SetWebhookKt.includeWebhookInRoute] - * - * @see dev.inmo.tgbotapi.extensions.api.SetWebhookKt.includeWebhookInRoute - * @see dev.inmo.tgbotapi.extensions.api.updates.UpdatesPollingKt.startGettingOfUpdates - */ -sealed interface MediaGroupUpdate : Update - -sealed interface SentMediaGroupUpdate: MediaGroupUpdate { - override val data: List> - val origins: List -} - -sealed interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate { - 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 deleted file mode 100644 index d36b7f50d8..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/media_group/MessageMediaGroupUpdate.kt +++ /dev/null @@ -1,13 +0,0 @@ -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.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 } -} 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 index 06cb6aaaaa..e2524c74da 100644 --- 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 @@ -18,7 +18,6 @@ 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 @@ -28,15 +27,13 @@ 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 { +fun List>.asMediaGroupMessage(): PossiblySentViaBotCommonMessage { + val sourceMessage = first() val content = MediaGroupContent( map { MediaGroupCollectionContent.PartWrapper(it.messageId, it.content, it) }, - mediaGroupIdentifier + sourceMessage.mediaGroupId ?: error("Can't create media group message with the first message without media group id") ) - return when (val sourceMessage = first()) { - is MediaGroupMessage -> TODO() + return when (sourceMessage) { is ChannelContentMessage -> ChannelContentMessageImpl( sourceMessage.messageId, sourceMessage.chat, @@ -48,7 +45,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyTo, sourceMessage.replyMarkup, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) is PrivateContentMessage -> PrivateContentMessageImpl( sourceMessage.messageId, @@ -61,7 +59,8 @@ fun List>.asMediaGroupContent( sourceMessage.forwardInfo, sourceMessage.replyTo, sourceMessage.replyMarkup, - sourceMessage.senderBot + sourceMessage.senderBot, + sourceMessage.mediaGroupId ) is AnonymousGroupContentMessage -> AnonymousGroupContentMessageImpl( sourceMessage.chat, @@ -74,7 +73,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) is CommonGroupContentMessage -> CommonGroupContentMessageImpl( sourceMessage.chat, @@ -87,7 +87,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyTo, sourceMessage.replyMarkup, content, - sourceMessage.senderBot + sourceMessage.senderBot, + sourceMessage.mediaGroupId ) is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl( sourceMessage.chat, @@ -101,7 +102,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) is UnconnectedFromChannelGroupContentMessage -> UnconnectedFromChannelGroupContentMessageImpl( sourceMessage.chat, @@ -115,7 +117,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) is AnonymousForumContentMessage -> AnonymousForumContentMessageImpl( sourceMessage.chat, @@ -129,7 +132,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) is CommonForumContentMessage -> CommonForumContentMessageImpl( sourceMessage.chat, @@ -143,7 +147,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyTo, sourceMessage.replyMarkup, content, - sourceMessage.senderBot + sourceMessage.senderBot, + sourceMessage.mediaGroupId ) is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl( sourceMessage.chat, @@ -158,7 +163,8 @@ fun List>.asMediaGroupContent( sourceMessage.replyMarkup, content, sourceMessage.senderBot, - sourceMessage.authorSignature + sourceMessage.authorSignature, + sourceMessage.mediaGroupId ) } } 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 293aaf0788..a2e1c1dfba 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 @@ -34,7 +34,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.* -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.textsources.* 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 c12abfc23c..aa69edf531 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 @@ -221,7 +221,6 @@ 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.ChannelEventMessage -import dev.inmo.tgbotapi.types.message.ChannelMediaGroupMessage import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated @@ -255,7 +254,6 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatStarted import dev.inmo.tgbotapi.types.message.CommonForumContentMessageImpl import dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.CommonGroupEventMessage -import dev.inmo.tgbotapi.types.message.CommonMediaGroupMessage import dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage import dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl import dev.inmo.tgbotapi.types.message.ForwardInfo @@ -279,7 +277,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage import dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage 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 fa337b2360..51d5200ded 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 @@ -36,6 +36,3 @@ 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()!! diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt index 27439971cf..a0c36c0c35 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt @@ -1,21 +1,20 @@ package dev.inmo.tgbotapi.extensions.utils.updates +import dev.inmo.tgbotapi.extensions.utils.withContentOrNull import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.UpdateIdentifier -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage +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.* +import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage /** * @return If [this] is [SentMediaGroupUpdate] - [Update.updateId] of [last] element, or its own [Update.updateId] */ +@Deprecated("Redundant", ReplaceWith("updateId")) fun Update.lastUpdateIdentifier(): UpdateIdentifier { - return if (this is SentMediaGroupUpdate) { - origins.last().updateId - } else { - updateId - } + return updateId } /** @@ -24,7 +23,7 @@ fun Update.lastUpdateIdentifier(): UpdateIdentifier { * @see [Update.lastUpdateIdentifier] */ fun List.lastUpdateIdentifier(): UpdateIdentifier? { - return maxByOrNull { it.updateId } ?.lastUpdateIdentifier() + return maxByOrNull { it.updateId } ?.updateId } /** @@ -32,62 +31,40 @@ fun List.lastUpdateIdentifier(): UpdateIdentifier? { */ fun List.convertWithMediaGroupUpdates(): List { val resultUpdates = mutableListOf() - val mediaGroups = mutableMapOf>() + val mediaGroups = mutableMapOf>>>() + for (update in this) { - val data = (update.data as? MediaGroupMessage<*>) - if (data == null) { + val message = (update.data as? PossiblySentViaBotCommonMessage<*>) ?.withContentOrNull() + val mediaGroupId = message ?.mediaGroupId + if (message == null || mediaGroupId == null) { resultUpdates.add(update) continue } when (update) { - is BaseEditMessageUpdate -> resultUpdates.add( - update.toEditMediaGroupUpdate() - ) is BaseSentMessageUpdate -> { - mediaGroups.getOrPut(data.mediaGroupId) { + mediaGroups.getOrPut(mediaGroupId) { mutableListOf() - }.add(update) + }.add(update to message) } else -> resultUpdates.add(update) } } - mediaGroups.values.map { - it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate -> - resultUpdates.add(mediaGroupUpdate) - } + + mediaGroups.map { (_, updatesWithMessages) -> + val update = updatesWithMessages.maxBy { it.first.updateId }.first + resultUpdates.add( + update.copy(updatesWithMessages.map { it.second }.asMediaGroupMessage()) + ) } + resultUpdates.sortBy { it.updateId } return resultUpdates } -/** - * @receiver List of [BaseSentMessageUpdate] where [BaseSentMessageUpdate.data] is [MediaGroupMessage] and all messages - * have the same [MediaGroupMessage.mediaGroupId] - * @return [MessageMediaGroupUpdate] in case if [first] object of [this] is [MessageUpdate]. When [first] object is - * [ChannelPostUpdate] instance - will return [ChannelPostMediaGroupUpdate]. Otherwise will be returned null - */ -fun List.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let { - if (isEmpty()) { - return@let null - } - val resultList = sortedBy { it.updateId } - when (first()) { - is MessageUpdate -> MessageMediaGroupUpdate(resultList) - is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList) - else -> null - } -} - /** * @return [EditMessageMediaGroupUpdate] in case if [this] is [EditMessageUpdate]. When [this] object is * [EditChannelPostUpdate] instance - will return [EditChannelPostMediaGroupUpdate] * * @throws IllegalStateException */ -fun BaseEditMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate = (this as? EditMediaGroupUpdate) ?: let { - when (this) { - is EditMessageUpdate -> EditMessageMediaGroupUpdate(this) - is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this) - else -> error("Unsupported type of ${BaseEditMessageUpdate::class.simpleName}") - } -} +fun BaseEditMessageUpdate.toEditMediaGroupUpdate() = this diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt index c369e14c16..f4e43f6e6b 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver @@ -32,7 +32,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( launch { for (update in updatesChannel) { when (val data = update.data) { - is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) + is PossiblyMediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) else -> output(update) } } @@ -57,4 +57,4 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( */ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( output: UpdateReceiver -) = updateHandlerWithMediaGroupsAdaptation(output, 1000L) \ No newline at end of file +) = updateHandlerWithMediaGroupsAdaptation(output, 1000L)