From 919b1590e39d52189be8a76bb10f88e57340a853 Mon Sep 17 00:00:00 2001 From: vasya Date: Mon, 28 Jun 2021 20:30:12 +0300 Subject: [PATCH] add Update#sourceUser method --- .../utils/extensions/UpdateChatRetriever.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..8d2a4d5f17 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,8 @@ package dev.inmo.tgbotapi.extensions.utils.extensions +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 +26,20 @@ fun Update.sourceChat(): Chat? = when (this) { is ShippingQueryUpdate -> data.user else -> null } + +@PreviewFeature +fun Update.sourceUser(): User? = when (this) { + is MediaGroupUpdate -> when (this) { + is SentMediaGroupUpdate -> data.chat?.asUser() + is EditMediaGroupUpdate -> data.chat.asUser() + else -> null + } + is BaseMessageUpdate -> data.chat.asUser() + is InlineQueryUpdate -> data.from + is ChosenInlineResultUpdate -> data.user + is CallbackQueryUpdate -> data.user + is PreCheckoutQueryUpdate -> data.user + is PollAnswerUpdate -> data.user + is ShippingQueryUpdate -> data.user + else -> null +}