From fa04b6f280ae25978fc3fcce641fcf3d24c7d001 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 28 Sep 2023 17:54:03 +0300 Subject: [PATCH] Add storePaymentPurposePremiumGiftCodes. --- td/generate/scheme/td_api.tl | 9 ++++++++- td/telegram/Premium.cpp | 29 +++++++++++++++++++++++++++++ td/telegram/cli.cpp | 11 ++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0d63caeb4..962ff14f5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4366,9 +4366,16 @@ premiumState state:formattedText payment_options:vector boosted_chat_id:int53 currency:string amount:int53 = StorePaymentPurpose; + //@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. //-To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org diff --git a/td/telegram/Premium.cpp b/td/telegram/Premium.cpp index 210a1622b..9f45dfa74 100644 --- a/td/telegram/Premium.cpp +++ b/td/telegram/Premium.cpp @@ -14,6 +14,7 @@ #include "td/telegram/DocumentsManager.h" #include "td/telegram/Global.h" #include "td/telegram/MessageEntity.h" +#include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" #include "td/telegram/PremiumGiftOption.h" #include "td/telegram/SuggestedAction.h" @@ -116,6 +117,34 @@ static Result> get_input_s return make_tl_object(std::move(input_user), p->currency_, p->amount_); } + case td_api::storePaymentPurposePremiumGiftCodes::ID: { + auto p = static_cast(purpose.get()); + vector> input_users; + for (auto user_id : p->user_ids_) { + TRY_RESULT(input_user, td->contacts_manager_->get_input_user(UserId(user_id))); + input_users.push_back(std::move(input_user)); + } + if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) { + return Status::Error(400, "Invalid amount of the currency specified"); + } + telegram_api::object_ptr boost_input_peer; + if (p->boosted_chat_id_ != 0) { + DialogId dialog_id(p->boosted_chat_id_); + if (!td->messages_manager_->have_dialog_force(dialog_id, "storePaymentPurposePremiumGiftCodes")) { + return Status::Error(400, "Chat to boost not found"); + } + boost_input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); + if (boost_input_peer == nullptr) { + return Status::Error(400, "Can't access the chat"); + } + } + int32 flags = 0; + if (boost_input_peer != nullptr) { + flags |= telegram_api::inputStorePaymentPremiumGiftCode::BOOST_PEER_MASK; + } + return telegram_api::make_object( + flags, std::move(input_users), std::move(boost_input_peer), p->currency_, p->amount_); + } default: UNREACHABLE(); return nullptr; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index a3291a1fc..2766a74b7 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3092,17 +3092,22 @@ class CliClient final : public Actor { send_request(td_api::make_object()); } else if (op == "gprs") { send_request(td_api::make_object()); - } else if (op == "cppr") { + } else if (op == "cppr" || op == "cpprb") { UserId user_id; string currency; int64 amount; - get_args(args, user_id, currency, amount); + ChatId boosted_chat_id; + get_args(args, user_id, currency, amount, boosted_chat_id); if (currency.empty()) { send_request(td_api::make_object( td_api::make_object(false, false))); - } else { + } else if (op == "cppr") { send_request(td_api::make_object( td_api::make_object(user_id, currency, amount))); + } else { + send_request(td_api::make_object( + td_api::make_object(vector{user_id}, boosted_chat_id, + currency, amount))); } } else if (op == "atos") { send_request(td_api::make_object(args));