From 022e6f623ab88853949f1b48bc81bd2f70232eaf Mon Sep 17 00:00:00 2001 From: vasya Date: Tue, 29 Jun 2021 00:57:32 +0300 Subject: [PATCH] add FromUser interface to objects where field `user` is present --- .../dev/inmo/tgbotapi/types/CallbackQuery/CallbackQuery.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt | 5 +++-- .../ChosenInlineResult/RawChosenInlineResult.kt | 5 +++-- .../types/InlineQueries/abstracts/ChosenInlineResult.kt | 4 ++-- .../kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt | 5 +++-- .../inmo/tgbotapi/types/message/ChatEvents/LeftChatMember.kt | 5 +++-- .../dev/inmo/tgbotapi/types/payments/PreCheckoutQuery.kt | 5 +++-- .../kotlin/dev/inmo/tgbotapi/types/payments/ShippingQuery.kt | 5 +++-- .../kotlin/dev/inmo/tgbotapi/types/polls/PollAnswer.kt | 5 +++-- 9 files changed, 25 insertions(+), 18 deletions(-) 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/ChatMemberUpdated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt index 856e113ac0..e4ce566f49 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMemberUpdated.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember import dev.inmo.tgbotapi.types.chat.abstracts.Chat import kotlinx.serialization.SerialName @@ -10,7 +11,7 @@ data class ChatMemberUpdated( @SerialName(chatField) val chat: Chat, @SerialName(fromField) - val user: User, + override val user: User, @SerialName(dateField) val date: TelegramDate, @SerialName(oldChatMemberField) @@ -19,4 +20,4 @@ data class ChatMemberUpdated( val newChatMemberState: ChatMember, @SerialName(inviteLinkField) val inviteLink: ChatInviteLink? = null -) +) : FromUser diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt index 4db078be40..3eb1c7c78e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult import dev.inmo.tgbotapi.types.location.StaticLocation @@ -11,14 +12,14 @@ internal data class RawChosenInlineResult( @SerialName(resultIdField) val resultId: InlineQueryIdentifier, //chosen temporary, can be changed @SerialName(fromField) - val user: User, + override val user: User, @SerialName(queryField) val query: String, @SerialName(locationField) val location: StaticLocation? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null -) { +) : FromUser { val asChosenInlineResult: ChosenInlineResult by lazy { location ?.let { LocationChosenInlineResult(resultId, user, location, inlineMessageId, query) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt index 1d98928768..51a55025a9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/abstracts/ChosenInlineResult.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.InlineQueries.abstracts +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.* -interface ChosenInlineResult { +interface ChosenInlineResult : FromUser { val resultId: InlineQueryIdentifier //chosen temporary, can be changed - val user: User val inlineMessageId: InlineMessageIdentifier? val query: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt index 0d05b81f0e..c02ad3b67e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/GameHighScore.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.games +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 GameHighScore ( @SerialName(positionField) val position: Long, @SerialName(userField) - val user: User, + override val user: User, @SerialName(scoreField) val score: Long -) \ No newline at end of file +) : FromUser \ No newline at end of file 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..859a87cdd1 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 @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.message.ChatEvents +import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent data class LeftChatMember( - val user: User -): CommonEvent + override val user: User +): CommonEvent, FromUser 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