1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

Merge pull request #140 from madhead/issues/139

Fix #139: Add "from" field to chat events
This commit is contained in:
InsanusMokrassar 2020-09-28 12:55:13 +06:00 committed by GitHub
commit 9916b3f469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 10 deletions

View File

@ -1,14 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.User
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.GroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.GroupEvent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.GroupEventMessage
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
data class GroupEventMessage( data class CommonGroupEventMessage(
override val messageId: MessageIdentifier, override val messageId: MessageIdentifier,
override val user: User,
override val chat: GroupChat, override val chat: GroupChat,
override val chatEvent: GroupEvent, override val chatEvent: GroupEvent,
override val date: DateTime override val date: DateTime
) : ChatEventMessage ) : GroupEventMessage

View File

@ -1,14 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.User
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.SupergroupEventMessage
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
data class SupergroupEventMessage( data class CommonSupergroupEventMessage(
override val messageId: MessageIdentifier, override val messageId: MessageIdentifier,
override val user: User,
override val chat: SupergroupChat, override val chat: SupergroupChat,
override val chatEvent: SupergroupEvent, override val chatEvent: SupergroupEvent,
override val date: DateTime override val date: DateTime
) : ChatEventMessage ) : SupergroupEventMessage

View File

@ -192,14 +192,16 @@ internal data class RawMessage(
try { try {
chatEvent?.let { chatEvent -> chatEvent?.let { chatEvent ->
when (chat) { when (chat) {
is SupergroupChat -> SupergroupEventMessage( is SupergroupChat -> CommonSupergroupEventMessage(
messageId, messageId,
from ?: error("Supergroup events are expected to contain 'from' field"),
chat, chat,
chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent), chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent),
date.asDate date.asDate
) )
is GroupChat -> GroupEventMessage( is GroupChat -> CommonGroupEventMessage(
messageId, messageId,
from ?: error("Supergroup events are expected to contain 'from' field"),
chat, chat,
chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent),
date.asDate date.asDate

View File

@ -0,0 +1,3 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
interface GroupEventMessage : ChatEventMessage, FromUserMessage

View File

@ -0,0 +1,3 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
interface SupergroupEventMessage : GroupEventMessage

View File

@ -17,5 +17,5 @@ fun <T : ChatEventMessage> Flow<ChatEventMessage>.divideBySource(contentType: KC
} }
fun Flow<ChatEventMessage>.onlyChannelEvents() = divideBySource(ChannelEventMessage::class) fun Flow<ChatEventMessage>.onlyChannelEvents() = divideBySource(ChannelEventMessage::class)
fun Flow<ChatEventMessage>.onlyGroupEvents() = divideBySource(GroupEventMessage::class) fun Flow<ChatEventMessage>.onlyGroupEvents() = divideBySource(CommonGroupEventMessage::class)
fun Flow<ChatEventMessage>.onlySupergroupEvents() = divideBySource(SupergroupEventMessage::class) fun Flow<ChatEventMessage>.onlySupergroupEvents() = divideBySource(CommonSupergroupEventMessage::class)