diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt index c5b6685505..3ab043ed28 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.CallbackQuery +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.CallbackQueryIdentifier import dev.inmo.tgbotapi.types.User -sealed interface CallbackQuery { +sealed interface CallbackQuery : FromUser { val id: CallbackQueryIdentifier - val user: User val chatInstance: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt index dfd71fe71a..22a9def5f3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt @@ -5,4 +5,4 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent data class LeftChatMember( val user: User -): CommonEvent +) : CommonEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt index 742e184d96..dfdfe4a1a7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.payments +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.payments.abstracts.* import kotlinx.serialization.SerialName @@ -11,7 +12,7 @@ data class PreCheckoutQuery( @SerialName(idField) val id: PreCheckoutQueryId, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(currencyField) override val currency: Currency, @SerialName(totalAmountField) @@ -22,4 +23,4 @@ data class PreCheckoutQuery( val shippingOptionId: ShippingOptionIdentifier? = null, @SerialName(orderInfoField) val orderInfo: OrderInfo? = null -) : Currencied, Amounted +) : Currencied, Amounted, FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt index dfa1735728..7821211bf6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.payments +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,9 +10,9 @@ data class ShippingQuery( @SerialName(idField) val id: ShippingQueryIdentifier, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(invoicePayloadField) val invoicePayload: InvoicePayload, @SerialName(shippingAddressField) val shippingAddress: ShippingAddress -) +) : FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt index d0e32260af..c4ea74bfa0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.polls +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,7 +10,7 @@ data class PollAnswer( @SerialName(pollIdField) val pollId: PollIdentifier, @SerialName(userField) - val user: User, + override val user: User, @SerialName(optionIdsField) val chosen: List -) +) : FromUser diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index a425707050..b8901c90e6 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.requests.send.payments.SendInvoice import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.CallbackQuery.* @@ -3096,3 +3097,12 @@ inline fun CommonSendInvoiceData.asInputInvoiceMessageContent(): InputInvoiceMes @PreviewFeature inline fun CommonSendInvoiceData.requireInputInvoiceMessageContent(): InputInvoiceMessageContent = this as InputInvoiceMessageContent + +@PreviewFeature +inline fun Any.whenFromUser(block: (FromUser) -> T) = asFromUser() ?.let(block) + +@PreviewFeature +inline fun Any.asFromUser(): FromUser? = this as? FromUser + +@PreviewFeature +inline fun Any.requireFromUser(): FromUser = this as FromUser diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt index 153cbe2600..49493e952f 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/UpdateChatRetriever.kt @@ -1,6 +1,10 @@ package dev.inmo.tgbotapi.extensions.utils.extensions +import dev.inmo.tgbotapi.extensions.utils.asFromUser +import dev.inmo.tgbotapi.extensions.utils.asFromUserMessage +import dev.inmo.tgbotapi.extensions.utils.asUser import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat +import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* @@ -24,3 +28,6 @@ fun Update.sourceChat(): Chat? = when (this) { is ShippingQueryUpdate -> data.user else -> null } + +@PreviewFeature +fun Update.sourceUser(): User? = data.asFromUser()?.user ?: sourceChat()?.asUser()