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:
parent
8c51ca9d72
commit
69f658e4a8
@ -7,57 +7,66 @@ import dev.inmo.tgbotapi.types.chat.User
|
||||
|
||||
sealed interface ForwardInfo {
|
||||
abstract val dateOfOriginal: TelegramDate
|
||||
}
|
||||
|
||||
data class AnonymousForwardInfo(
|
||||
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(
|
||||
data class ByAnonymous(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val channelChat: ChannelChat,
|
||||
val signature: String? = null
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val chat: PublicChat
|
||||
get() = channelChat
|
||||
}
|
||||
val senderName: String
|
||||
) : ForwardInfo
|
||||
|
||||
/**
|
||||
* Represent forward info for the message sent by [channelChat] into that channel
|
||||
*/
|
||||
data class FromChannel(
|
||||
data class ByUser(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val messageId: MessageIdentifier,
|
||||
val channelChat: ChannelChat,
|
||||
val signature: String? = null
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val chat: PublicChat
|
||||
get() = channelChat
|
||||
}
|
||||
override val from: User
|
||||
) : ForwardInfo, FromUser
|
||||
|
||||
data class FromSupergroup(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val group: SupergroupChat
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val chat: PublicChat
|
||||
get() = group
|
||||
sealed interface PublicChat : ForwardInfo {
|
||||
val chat: dev.inmo.tgbotapi.types.chat.PublicChat
|
||||
|
||||
/**
|
||||
* Represent forward info for the message sent by [channelChat] into some 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"))
|
||||
typealias ForwardFromChannelInfo = ForwardFromPublicChatInfo.FromChannel
|
||||
@Deprecated("Replaced", ReplaceWith("ForwardInfo.ByAnonymous", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||
typealias AnonymousForwardInfo = ForwardInfo.ByAnonymous
|
||||
|
||||
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardFromPublicChatInfo"))
|
||||
typealias ForwardFromSupergroupInfo = ForwardFromPublicChatInfo.FromSupergroup
|
||||
@Deprecated("Replaced", ReplaceWith("ForwardInfo.ByUser", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||
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
|
||||
|
@ -156,34 +156,39 @@ internal data class RawMessage(
|
||||
}
|
||||
|
||||
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 {
|
||||
forward_sender_name != null -> AnonymousForwardInfo(
|
||||
forward_sender_name != null -> ForwardInfo.ByAnonymous(
|
||||
forward_date,
|
||||
forward_sender_name
|
||||
)
|
||||
|
||||
forward_from_chat is ChannelChat -> if (forward_from_message_id == null) {
|
||||
ForwardFromPublicChatInfo.SentByChannel(
|
||||
ForwardInfo.PublicChat.SentByChannel(
|
||||
forward_date,
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
} else {
|
||||
ForwardFromPublicChatInfo.FromChannel(
|
||||
ForwardInfo.PublicChat.FromChannel(
|
||||
forward_date,
|
||||
forward_from_message_id,
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
}
|
||||
forward_from_chat is SupergroupChat -> ForwardFromPublicChatInfo.FromSupergroup(
|
||||
|
||||
forward_from_chat is SupergroupChat -> ForwardInfo.PublicChat.FromSupergroup(
|
||||
forward_date,
|
||||
forward_from_chat
|
||||
)
|
||||
forward_from != null -> UserForwardInfo(
|
||||
|
||||
forward_from != null -> ForwardInfo.ByUser(
|
||||
forward_date,
|
||||
forward_from
|
||||
)
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user