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,20 +7,19 @@ import dev.inmo.tgbotapi.types.chat.User
sealed interface ForwardInfo {
abstract val dateOfOriginal: TelegramDate
}
data class AnonymousForwardInfo(
data class ByAnonymous(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardInfo
) : ForwardInfo
data class UserForwardInfo(
data class ByUser(
override val dateOfOriginal: TelegramDate,
override val from: User
) : ForwardInfo, FromUser
) : ForwardInfo, FromUser
sealed interface ForwardFromPublicChatInfo : ForwardInfo {
val chat: PublicChat
sealed interface PublicChat : ForwardInfo {
val chat: dev.inmo.tgbotapi.types.chat.PublicChat
/**
* Represent forward info for the message sent by [channelChat] into some group
@ -29,8 +28,8 @@ sealed interface ForwardFromPublicChatInfo : ForwardInfo {
override val dateOfOriginal: TelegramDate,
val channelChat: ChannelChat,
val signature: String? = null
) : ForwardFromPublicChatInfo {
override val chat: PublicChat
) : PublicChat {
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
get() = channelChat
}
@ -42,22 +41,32 @@ sealed interface ForwardFromPublicChatInfo : ForwardInfo {
val messageId: MessageIdentifier,
val channelChat: ChannelChat,
val signature: String? = null
) : ForwardFromPublicChatInfo {
override val chat: PublicChat
) : PublicChat {
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
get() = channelChat
}
data class FromSupergroup(
override val dateOfOriginal: TelegramDate,
val group: SupergroupChat
) : ForwardFromPublicChatInfo {
override val chat: PublicChat
) : 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

View File

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