diff --git a/CHANGELOG b/CHANGELOG index 2491f7630a..6739fcfd36 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,3 +6,9 @@ * Add implementation of `MediaGroupMessage` * Add generating of `MediaGroupMessage` in `RawMessage` +## 0.8.2 + +* Add `FromUserMessage` which must be implemented in all messages realisations which have `user` field +* Add `CommonMediaGroupMessage` which in fact extension of `MediaGroupMessage` with implementation of `FromUserMessage` +* `CommonMessageImpl` now implementing `FromUserMessage` + diff --git a/build.gradle b/build.gradle index 38a59e822b..ffb34b4a61 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.8.1" +project.version = "0.8.2" project.group = "com.github.insanusmokrassar" buildscript { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt new file mode 100644 index 0000000000..d91fc439a3 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent +import org.joda.time.DateTime + +data class CommonMediaGroupMessage( + override val messageId: MessageIdentifier, + override val user: User, + override val chat: Chat, + override val date: DateTime, + override val mediaGroupId: MediaGroupIdentifier, + override val content: MediaGroupContent +) : Message, MediaGroupMessage, FromUserMessage diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt index 570e048407..a926995cd7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt @@ -3,15 +3,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.User import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import org.joda.time.DateTime data class CommonMessageImpl( override val messageId: MessageIdentifier, - val user: User, + override val user: User, override val chat: Chat, override val content: T, override val date: DateTime, @@ -19,4 +18,4 @@ data class CommonMessageImpl( override val forwarded: ForwardedMessage?, override val replyTo: Message?, val paymentInfo: PaymentInfo? -) : Message, CommonMessage \ No newline at end of file +) : Message, CommonMessage, FromUserMessage \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 2599172aec..4c7694a24b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -208,17 +208,31 @@ data class RawMessage( } ?: content ?.let { content -> media_group_id ?.let { - MediaGroupMessage( - messageId, - chat, - date.asDate, - it, - when (content) { - is PhotoContent -> content - is VideoContent -> content - else -> throw IllegalStateException("Unsupported content for media group") - } - ) + when (from) { + null -> MediaGroupMessage( + messageId, + chat, + date.asDate, + it, + when (content) { + is PhotoContent -> content + is VideoContent -> content + else -> throw IllegalStateException("Unsupported content for media group") + } + ) + else -> CommonMediaGroupMessage( + messageId, + from, + chat, + date.asDate, + it, + when (content) { + is PhotoContent -> content + is VideoContent -> content + else -> throw IllegalStateException("Unsupported content for media group") + } + ) + } } ?: when (chat) { is ChannelChat -> ChannelMessage( messageId, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/FromUserMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/FromUserMessage.kt new file mode 100644 index 0000000000..5145e00383 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/FromUserMessage.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.User + +interface FromUserMessage { + val user: User +} \ No newline at end of file