1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 12:08:43 +00:00

fixes in forward from public chat info

This commit is contained in:
InsanusMokrassar 2022-08-04 22:13:02 +06:00
parent 48c4a3156b
commit 8c51ca9d72
3 changed files with 72 additions and 34 deletions

View File

@ -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
}
data class ForwardFromChannelInfo( /**
* 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, override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier, val messageId: MessageIdentifier,
val channelChat: ChannelChat, val channelChat: ChannelChat,
val signature: String? = null val signature: String? = null
) : ForwardFromPublicChatInfo() { ) : ForwardFromPublicChatInfo {
override val chat: PublicChat override val chat: PublicChat
get() = channelChat get() = channelChat
} }
data class ForwardFromSupergroupInfo( data class FromSupergroup(
override val dateOfOriginal: TelegramDate, override val dateOfOriginal: TelegramDate,
val group: SupergroupChat val group: SupergroupChat
) : ForwardFromPublicChatInfo() { ) : ForwardFromPublicChatInfo {
override val chat: PublicChat override val chat: PublicChat
get() = group get() = group
}
} }
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromChannel", "dev.inmo.tgbotapi.types.message.FromChannel"))
typealias ForwardFromChannelInfo = ForwardFromPublicChatInfo.FromChannel
@Deprecated("Replaced", ReplaceWith("ForwardFromPublicChatInfo.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardFromPublicChatInfo"))
typealias ForwardFromSupergroupInfo = ForwardFromPublicChatInfo.FromSupergroup

View File

@ -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) {
ForwardFromPublicChatInfo.SentByChannel(
forward_date, forward_date,
forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"),
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
) )

View File

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