1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

rewrite hierarchy of forward info classes

This commit is contained in:
InsanusMokrassar 2022-08-04 22:45:26 +06:00
parent 8c51ca9d72
commit 69f658e4a8
4 changed files with 1342 additions and 825 deletions

View File

@ -7,57 +7,66 @@ import dev.inmo.tgbotapi.types.chat.User
sealed interface ForwardInfo { sealed interface ForwardInfo {
abstract val dateOfOriginal: TelegramDate abstract val dateOfOriginal: TelegramDate
}
data class AnonymousForwardInfo( data class ByAnonymous(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardInfo
data class UserForwardInfo(
override val dateOfOriginal: TelegramDate,
override val from: User
) : ForwardInfo, FromUser
sealed interface ForwardFromPublicChatInfo : ForwardInfo {
val chat: PublicChat
/**
* Represent forward info for the message sent by [channelChat] into some group
*/
data class SentByChannel(
override val dateOfOriginal: TelegramDate, override val dateOfOriginal: TelegramDate,
val channelChat: ChannelChat, val senderName: String
val signature: String? = null ) : ForwardInfo
) : ForwardFromPublicChatInfo {
override val chat: PublicChat
get() = channelChat
}
/** data class ByUser(
* Represent forward info for the message sent by [channelChat] into that channel
*/
data class FromChannel(
override val dateOfOriginal: TelegramDate, override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier, override val from: User
val channelChat: ChannelChat, ) : ForwardInfo, FromUser
val signature: String? = null
) : ForwardFromPublicChatInfo {
override val chat: PublicChat
get() = channelChat
}
data class FromSupergroup( sealed interface PublicChat : ForwardInfo {
override val dateOfOriginal: TelegramDate, val chat: dev.inmo.tgbotapi.types.chat.PublicChat
val group: SupergroupChat
) : ForwardFromPublicChatInfo { /**
override val chat: PublicChat * Represent forward info for the message sent by [channelChat] into some group
get() = group */
data class SentByChannel(
override val dateOfOriginal: TelegramDate,
val channelChat: ChannelChat,
val signature: String? = null
) : PublicChat {
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
get() = channelChat
}
/**
* Represent forward info for the message sent by [channelChat] into that channel
*/
data class FromChannel(
override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier,
val channelChat: ChannelChat,
val signature: String? = null
) : PublicChat {
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
get() = channelChat
}
data class FromSupergroup(
override val dateOfOriginal: TelegramDate,
val group: SupergroupChat
) : PublicChat {
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
get() = group
}
} }
} }
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromChannel", "dev.inmo.tgbotapi.types.message.FromChannel")) @Deprecated("Replaced", ReplaceWith("ForwardInfo.ByAnonymous", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
typealias ForwardFromChannelInfo = ForwardFromPublicChatInfo.FromChannel typealias AnonymousForwardInfo = ForwardInfo.ByAnonymous
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardFromPublicChatInfo")) @Deprecated("Replaced", ReplaceWith("ForwardInfo.ByUser", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
typealias ForwardFromSupergroupInfo = ForwardFromPublicChatInfo.FromSupergroup typealias UserForwardInfo = ForwardInfo.ByUser
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
typealias ForwardFromPublicChatInfo = ForwardInfo.PublicChat
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat.FromChannel", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
typealias ForwardFromChannelInfo = ForwardInfo.PublicChat.FromChannel
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
typealias ForwardFromSupergroupInfo = ForwardInfo.PublicChat.FromSupergroup

View File

@ -156,34 +156,39 @@ internal data class RawMessage(
} }
private val forwarded: ForwardInfo? by lazy { private val forwarded: ForwardInfo? by lazy {
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field forward_date
?: return@lazy null // According to the documentation, now any forwarded message contains this field
when { when {
forward_sender_name != null -> AnonymousForwardInfo( forward_sender_name != null -> ForwardInfo.ByAnonymous(
forward_date, forward_date,
forward_sender_name forward_sender_name
) )
forward_from_chat is ChannelChat -> if (forward_from_message_id == null) { forward_from_chat is ChannelChat -> if (forward_from_message_id == null) {
ForwardFromPublicChatInfo.SentByChannel( ForwardInfo.PublicChat.SentByChannel(
forward_date, forward_date,
forward_from_chat, forward_from_chat,
forward_signature forward_signature
) )
} else { } else {
ForwardFromPublicChatInfo.FromChannel( ForwardInfo.PublicChat.FromChannel(
forward_date, forward_date,
forward_from_message_id, forward_from_message_id,
forward_from_chat, forward_from_chat,
forward_signature forward_signature
) )
} }
forward_from_chat is SupergroupChat -> ForwardFromPublicChatInfo.FromSupergroup(
forward_from_chat is SupergroupChat -> ForwardInfo.PublicChat.FromSupergroup(
forward_date, forward_date,
forward_from_chat forward_from_chat
) )
forward_from != null -> UserForwardInfo(
forward_from != null -> ForwardInfo.ByUser(
forward_date, forward_date,
forward_from forward_from
) )
else -> null else -> null
} }
} }