1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-21 15:53:47 +00:00

improve ChannelContentMessage

This commit is contained in:
InsanusMokrassar 2024-08-14 23:09:16 +06:00
parent b7ff6a3061
commit 1dc9dc42fb
4 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.message.abstracts
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.chat.PreviewChat
interface WithSenderChatMessage {

View File

@ -17,8 +17,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
return when (sourceMessage) {
is ChannelContentMessage -> ChannelContentMessageImpl(
messageId = sourceMessage.messageId,
from = sourceMessage.from,
chat = sourceMessage.chat,
senderChat = sourceMessage.senderChat,
content = content,
date = sourceMessage.date,
editDate = sourceMessage.editDate,

View File

@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.abstracts.OptionallyFromUser
import dev.inmo.tgbotapi.abstracts.OptionallyWithUser
import dev.inmo.tgbotapi.abstracts.WithUser
import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode
import dev.inmo.tgbotapi.types.message.abstracts.WithSenderChatMessage
import dev.inmo.tgbotapi.utils.PreviewFeature
@PreviewFeature
@ -54,3 +55,13 @@ inline fun Any.withOptionalLanguageCodeOrNull(): WithOptionalLanguageCode? = thi
@PreviewFeature
inline fun Any.withOptionalLanguageCodeOrThrow(): WithOptionalLanguageCode = this as WithOptionalLanguageCode
@PreviewFeature
inline fun <T> Any.ifWithSenderChatMessage(block: (WithSenderChatMessage) -> T) =
withSenderChatMessageOrNull()?.let(block)
@PreviewFeature
inline fun Any.withSenderChatMessageOrNull(): WithSenderChatMessage? = this as? WithSenderChatMessage
@PreviewFeature
inline fun Any.withSenderChatMessageOrThrow(): WithSenderChatMessage = this as WithSenderChatMessage

View File

@ -25,8 +25,8 @@ import dev.inmo.tgbotapi.utils.RiskFeature
inline val Message.from: User?
get() = optionallyFromUserMessageOrNull() ?.from
@RiskFeature(RawFieldsUsageWarning)
inline val Message.sender_chat: PublicChat?
get() = asFromChannelGroupContentMessage() ?.senderChat
inline val Message.sender_chat: PreviewChat?
get() = withSenderChatMessageOrNull() ?.senderChat
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_from: User?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asUserForwardInfo() ?.from