Add td_api::getStarGiftPaymentOptions.

This commit is contained in:
levlam 2024-07-10 17:19:43 +03:00
parent aaddaab9c0
commit bb2b10f615
6 changed files with 66 additions and 0 deletions

View File

@ -11257,6 +11257,9 @@ getPremiumGiveawayInfo chat_id:int53 message_id:int53 = PremiumGiveawayInfo;
//@description Returns available options for Telegram Stars purchase //@description Returns available options for Telegram Stars purchase
getStarPaymentOptions = StarPaymentOptions; 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 //@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, //@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 //-or identifier of a channel chat with supergroupFullInfo.can_get_star_revenue_statistics == true

View File

@ -72,6 +72,45 @@ class GetStarsTopupOptionsQuery final : public Td::ResultHandler {
} }
}; };
class GetStarsGiftOptionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::starPaymentOptions>> promise_;
public:
explicit GetStarsGiftOptionsQuery(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise)
: promise_(std::move(promise)) {
}
void send(telegram_api::object_ptr<telegram_api::InputUser> 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<telegram_api::payments_getStarsGiftOptions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto results = result_ptr.move_as_ok();
vector<td_api::object_ptr<td_api::starPaymentOption>> options;
for (auto &result : results) {
options.push_back(td_api::make_object<td_api::starPaymentOption>(result->currency_, result->amount_,
StarManager::get_star_count(result->stars_),
result->store_product_, result->extended_));
}
promise_.set_value(td_api::make_object<td_api::starPaymentOptions>(std::move(options)));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetStarsTransactionsQuery final : public Td::ResultHandler { class GetStarsTransactionsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::starTransactions>> promise_; Promise<td_api::object_ptr<td_api::starTransactions>> promise_;
DialogId dialog_id_; DialogId dialog_id_;
@ -495,6 +534,16 @@ void StarManager::get_star_payment_options(Promise<td_api::object_ptr<td_api::st
td_->create_handler<GetStarsTopupOptionsQuery>(std::move(promise))->send(); td_->create_handler<GetStarsTopupOptionsQuery>(std::move(promise))->send();
} }
void StarManager::get_star_gift_payment_options(UserId user_id,
Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise) {
if (user_id == UserId()) {
td_->create_handler<GetStarsGiftOptionsQuery>(std::move(promise))->send(nullptr);
return;
}
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
td_->create_handler<GetStarsGiftOptionsQuery>(std::move(promise))->send(std::move(input_user));
}
void StarManager::get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset, void StarManager::get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset,
int32 limit, td_api::object_ptr<td_api::StarTransactionDirection> &&direction, int32 limit, td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
Promise<td_api::object_ptr<td_api::starTransactions>> &&promise) { Promise<td_api::object_ptr<td_api::starTransactions>> &&promise) {

View File

@ -29,6 +29,8 @@ class StarManager final : public Actor {
void get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise); void get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
void get_star_gift_payment_options(UserId user_id, Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
void get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset, int32 limit, void get_star_transactions(td_api::object_ptr<td_api::MessageSender> owner_id, const string &offset, int32 limit,
td_api::object_ptr<td_api::StarTransactionDirection> &&direction, td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
Promise<td_api::object_ptr<td_api::starTransactions>> &&promise); Promise<td_api::object_ptr<td_api::starTransactions>> &&promise);

View File

@ -9523,6 +9523,12 @@ void Td::on_request(uint64 id, const td_api::getStarPaymentOptions &request) {
star_manager_->get_star_payment_options(std::move(promise)); 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) { void Td::on_request(uint64 id, td_api::getStarTransactions &request) {
CLEAN_INPUT_STRING(request.offset_); CLEAN_INPUT_STRING(request.offset_);
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -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::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::getStarTransactions &request);
void on_request(uint64 id, td_api::canPurchaseFromStore &request); void on_request(uint64 id, td_api::canPurchaseFromStore &request);

View File

@ -3435,6 +3435,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getPremiumGiveawayInfo>(chat_id, message_id)); send_request(td_api::make_object<td_api::getPremiumGiveawayInfo>(chat_id, message_id));
} else if (op == "gspo") { } else if (op == "gspo") {
send_request(td_api::make_object<td_api::getStarPaymentOptions>()); send_request(td_api::make_object<td_api::getStarPaymentOptions>());
} else if (op == "gsgpo") {
UserId user_id;
get_args(args, user_id);
send_request(td_api::make_object<td_api::getStarGiftPaymentOptions>(user_id));
} else if (op == "gsta" || op == "gsti" || op == "gsto") { } else if (op == "gsta" || op == "gsti" || op == "gsto") {
string owner_id; string owner_id;
string offset; string offset;