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