diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt index 75a9bb3417..1b3c513631 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt @@ -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 { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt index b131db0432..f5afda775b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -17,8 +17,8 @@ fun List>.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, diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt index 1092af4617..5dd5444676 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNewAny.kt @@ -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 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 diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt index 5aaf7383a5..0a627f1aef 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt @@ -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