diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d9a7ee126..025e61642 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -11257,6 +11257,9 @@ getPremiumGiveawayInfo chat_id:int53 message_id:int53 = PremiumGiveawayInfo; //@description Returns available options for Telegram Stars purchase getStarPaymentOptions = StarPaymentOptions; +//@description Returns available options for Telegram Stars gifting @user_id Identifier of the user that will receive Telegram Stars; pass 0 to get options for an unspecified user +getStarGiftPaymentOptions user_id:int53 = StarPaymentOptions; + //@description Returns the list of Telegram Star transactions for the specified owner //@owner_id Identifier of the owner of the Telegram Stars; can be the identifier of the current user, identifier of an owned bot, //-or identifier of a channel chat with supergroupFullInfo.can_get_star_revenue_statistics == true diff --git a/td/telegram/StarManager.cpp b/td/telegram/StarManager.cpp index b55c21295..d346bfae3 100644 --- a/td/telegram/StarManager.cpp +++ b/td/telegram/StarManager.cpp @@ -72,6 +72,45 @@ class GetStarsTopupOptionsQuery final : public Td::ResultHandler { } }; +class GetStarsGiftOptionsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetStarsGiftOptionsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(telegram_api::object_ptr input_user) { + int32 flags = 0; + if (input_user != nullptr) { + flags |= telegram_api::payments_getStarsGiftOptions::USER_ID_MASK; + } + send_query( + G()->net_query_creator().create(telegram_api::payments_getStarsGiftOptions(flags, std::move(input_user)))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto results = result_ptr.move_as_ok(); + vector> options; + for (auto &result : results) { + options.push_back(td_api::make_object(result->currency_, result->amount_, + StarManager::get_star_count(result->stars_), + result->store_product_, result->extended_)); + } + + promise_.set_value(td_api::make_object(std::move(options))); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetStarsTransactionsQuery final : public Td::ResultHandler { Promise> promise_; DialogId dialog_id_; @@ -495,6 +534,16 @@ void StarManager::get_star_payment_options(Promisecreate_handler(std::move(promise))->send(); } +void StarManager::get_star_gift_payment_options(UserId user_id, + Promise> &&promise) { + if (user_id == UserId()) { + td_->create_handler(std::move(promise))->send(nullptr); + return; + } + TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id)); + td_->create_handler(std::move(promise))->send(std::move(input_user)); +} + void StarManager::get_star_transactions(td_api::object_ptr owner_id, const string &offset, int32 limit, td_api::object_ptr &&direction, Promise> &&promise) { diff --git a/td/telegram/StarManager.h b/td/telegram/StarManager.h index 32420e221..29da88361 100644 --- a/td/telegram/StarManager.h +++ b/td/telegram/StarManager.h @@ -29,6 +29,8 @@ class StarManager final : public Actor { void get_star_payment_options(Promise> &&promise); + void get_star_gift_payment_options(UserId user_id, Promise> &&promise); + void get_star_transactions(td_api::object_ptr owner_id, const string &offset, int32 limit, td_api::object_ptr &&direction, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index dbe27974c..88090cd9b 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -9523,6 +9523,12 @@ void Td::on_request(uint64 id, const td_api::getStarPaymentOptions &request) { star_manager_->get_star_payment_options(std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getStarGiftPaymentOptions &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + star_manager_->get_star_gift_payment_options(UserId(request.user_id_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::getStarTransactions &request) { CLEAN_INPUT_STRING(request.offset_); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 6cedd7798..95882da56 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1879,6 +1879,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getStarPaymentOptions &request); + void on_request(uint64 id, const td_api::getStarGiftPaymentOptions &request); + void on_request(uint64 id, td_api::getStarTransactions &request); void on_request(uint64 id, td_api::canPurchaseFromStore &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index e8ad7c350..4509e6a72 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3435,6 +3435,10 @@ class CliClient final : public Actor { send_request(td_api::make_object(chat_id, message_id)); } else if (op == "gspo") { send_request(td_api::make_object()); + } else if (op == "gsgpo") { + UserId user_id; + get_args(args, user_id); + send_request(td_api::make_object(user_id)); } else if (op == "gsta" || op == "gsti" || op == "gsto") { string owner_id; string offset;