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