mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
fixes in forward from public chat info
This commit is contained in:
parent
48c4a3156b
commit
8c51ca9d72
@ -5,38 +5,59 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
|
||||
sealed class ForwardInfo {
|
||||
sealed interface ForwardInfo {
|
||||
abstract val dateOfOriginal: TelegramDate
|
||||
}
|
||||
|
||||
data class AnonymousForwardInfo(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val senderName: String
|
||||
) : ForwardInfo()
|
||||
) : ForwardInfo
|
||||
|
||||
data class UserForwardInfo(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
override val from: User
|
||||
) : ForwardInfo(), FromUser
|
||||
) : ForwardInfo, FromUser
|
||||
|
||||
sealed class ForwardFromPublicChatInfo : ForwardInfo() {
|
||||
abstract val chat: PublicChat
|
||||
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,
|
||||
val channelChat: ChannelChat,
|
||||
val signature: String? = null
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val 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
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val chat: PublicChat
|
||||
get() = channelChat
|
||||
}
|
||||
|
||||
data class FromSupergroup(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val group: SupergroupChat
|
||||
) : ForwardFromPublicChatInfo {
|
||||
override val chat: PublicChat
|
||||
get() = group
|
||||
}
|
||||
}
|
||||
|
||||
data class ForwardFromChannelInfo(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val messageId: MessageIdentifier,
|
||||
val channelChat: ChannelChat,
|
||||
val signature: String? = null
|
||||
) : ForwardFromPublicChatInfo() {
|
||||
override val chat: PublicChat
|
||||
get() = channelChat
|
||||
}
|
||||
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromChannel", "dev.inmo.tgbotapi.types.message.FromChannel"))
|
||||
typealias ForwardFromChannelInfo = ForwardFromPublicChatInfo.FromChannel
|
||||
|
||||
data class ForwardFromSupergroupInfo(
|
||||
override val dateOfOriginal: TelegramDate,
|
||||
val group: SupergroupChat
|
||||
) : ForwardFromPublicChatInfo() {
|
||||
override val chat: PublicChat
|
||||
get() = group
|
||||
}
|
||||
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardFromPublicChatInfo"))
|
||||
typealias ForwardFromSupergroupInfo = ForwardFromPublicChatInfo.FromSupergroup
|
||||
|
@ -162,13 +162,21 @@ internal data class RawMessage(
|
||||
forward_date,
|
||||
forward_sender_name
|
||||
)
|
||||
forward_from_chat is ChannelChat -> ForwardFromChannelInfo(
|
||||
forward_date,
|
||||
forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"),
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
forward_from_chat is SupergroupChat -> ForwardFromSupergroupInfo(
|
||||
forward_from_chat is ChannelChat -> if (forward_from_message_id == null) {
|
||||
ForwardFromPublicChatInfo.SentByChannel(
|
||||
forward_date,
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
} else {
|
||||
ForwardFromPublicChatInfo.FromChannel(
|
||||
forward_date,
|
||||
forward_from_message_id,
|
||||
forward_from_chat,
|
||||
forward_signature
|
||||
)
|
||||
}
|
||||
forward_from_chat is SupergroupChat -> ForwardFromPublicChatInfo.FromSupergroup(
|
||||
forward_date,
|
||||
forward_from_chat
|
||||
)
|
||||
|
@ -3415,22 +3415,31 @@ inline fun ForwardInfo.forwardFromPublicChatInfoOrNull(): ForwardFromPublicChatI
|
||||
inline fun ForwardInfo.forwardFromPublicChatInfoOrThrow(): ForwardFromPublicChatInfo = this as ForwardFromPublicChatInfo
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ForwardInfo.ifForwardFromChannelInfo(block: (ForwardFromChannelInfo) -> T) = forwardFromChannelInfoOrNull() ?.let(block)
|
||||
inline fun <T> ForwardInfo.ifForwardFromChannelInfo(block: (ForwardFromPublicChatInfo.FromChannel) -> T) = forwardFromChannelInfoOrNull() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromChannelInfoOrNull(): ForwardFromChannelInfo? = this as? ForwardFromChannelInfo
|
||||
inline fun ForwardInfo.forwardFromChannelInfoOrNull(): ForwardFromPublicChatInfo.FromChannel? = this as? ForwardFromPublicChatInfo.FromChannel
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromChannelInfoOrThrow(): ForwardFromChannelInfo = this as ForwardFromChannelInfo
|
||||
inline fun ForwardInfo.forwardFromChannelInfoOrThrow(): ForwardFromPublicChatInfo.FromChannel = this as ForwardFromPublicChatInfo.FromChannel
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ForwardInfo.ifForwardFromSupergroupInfo(block: (ForwardFromSupergroupInfo) -> T) = forwardFromSupergroupInfoOrNull() ?.let(block)
|
||||
inline fun <T> ForwardInfo.ifForwardSentByChannelInfo(block: (ForwardFromPublicChatInfo.SentByChannel) -> T) = forwardSentByChannelInfoOrNull() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromSupergroupInfoOrNull(): ForwardFromSupergroupInfo? = this as? ForwardFromSupergroupInfo
|
||||
inline fun ForwardInfo.forwardSentByChannelInfoOrNull(): ForwardFromPublicChatInfo.SentByChannel? = this as? ForwardFromPublicChatInfo.SentByChannel
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromSupergroupInfoOrThrow(): ForwardFromSupergroupInfo = this as ForwardFromSupergroupInfo
|
||||
inline fun ForwardInfo.forwardSentByChannelInfoOrThrow(): ForwardFromPublicChatInfo.SentByChannel = this as ForwardFromPublicChatInfo.SentByChannel
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ForwardInfo.ifForwardFromSupergroupInfo(block: (ForwardFromPublicChatInfo.FromSupergroup) -> T) = forwardFromSupergroupInfoOrNull() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromSupergroupInfoOrNull(): ForwardFromPublicChatInfo.FromSupergroup? = this as? ForwardFromPublicChatInfo.FromSupergroup
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ForwardInfo.forwardFromSupergroupInfoOrThrow(): ForwardFromPublicChatInfo.FromSupergroup = this as ForwardFromPublicChatInfo.FromSupergroup
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> MessageContent.ifTextedInput(block: (TextedInput) -> T) = textedInputOrNull() ?.let(block)
|
||||
|
Loading…
Reference in New Issue
Block a user