1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

FromUserMessage

This commit is contained in:
InsanusMokrassar 2019-01-10 22:09:51 +08:00
parent 661a8dfa8a
commit 38d4010bc1
5 changed files with 58 additions and 15 deletions

View File

@ -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`

View File

@ -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

View File

@ -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<T: MessageContent>(
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<T: MessageContent>(
override val forwarded: ForwardedMessage?,
override val replyTo: Message?,
val paymentInfo: PaymentInfo?
) : Message, CommonMessage<T>
) : Message, CommonMessage<T>, FromUserMessage

View File

@ -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,

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.User
interface FromUserMessage {
val user: User
}