Add td_api::getStarSubscriptions.
This commit is contained in:
parent
070675b4cd
commit
597805c951
@ -811,6 +811,12 @@ starSubscriptionPricing period:int32 star_count:int53 = StarSubscriptionPricing;
|
||||
//@pricing The subscription plan
|
||||
starSubscription id:string chat_id:int53 expiration_date:int32 is_canceled:Bool pricing:starSubscriptionPricing = StarSubscription;
|
||||
|
||||
//@description Represents a list of Telegram Star subscriptions
|
||||
//@star_count The amount of owned Telegram Stars
|
||||
//@subscriptions List of subbscriptions for Telegram Stars
|
||||
//@next_offset The offset for the next request. If empty, then there are no more results
|
||||
starSubscriptions star_count:int53 subscriptions:vector<starSubscription> next_offset:string = StarSubscriptions;
|
||||
|
||||
|
||||
//@description Contains information about a product that can be paid with invoice
|
||||
//@title Product title
|
||||
@ -11434,6 +11440,11 @@ getStarGiftPaymentOptions user_id:int53 = StarPaymentOptions;
|
||||
//@limit The maximum number of transactions to return
|
||||
getStarTransactions owner_id:MessageSender direction:StarTransactionDirection offset:string limit:int32 = StarTransactions;
|
||||
|
||||
//@description Returns the list of Telegram Star subscriptions for the current user
|
||||
//@offset Offset of the first subscription to return as received from the previous request; use empty string to get the first chunk of results
|
||||
//@limit The maximum number of results to return
|
||||
getStarSubscriptions offset:string limit:int32 = StarSubscriptions;
|
||||
|
||||
//@description Checks whether an in-store purchase is possible. Must be called before any in-store purchase @purpose Transaction purpose
|
||||
canPurchaseFromStore purpose:StorePaymentPurpose = Ok;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "td/telegram/PasswordManager.h"
|
||||
#include "td/telegram/Photo.h"
|
||||
#include "td/telegram/ServerMessageId.h"
|
||||
#include "td/telegram/StarSubscription.h"
|
||||
#include "td/telegram/StatisticsManager.h"
|
||||
#include "td/telegram/StickersManager.h"
|
||||
#include "td/telegram/Td.h"
|
||||
@ -361,6 +362,51 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class GetStarsSubscriptionsQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::starSubscriptions>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetStarsSubscriptionsQuery(Promise<td_api::object_ptr<td_api::starSubscriptions>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &offset, int32 limit) {
|
||||
int32 flags = 0;
|
||||
send_query(G()->net_query_creator().create(telegram_api::payments_getStarsSubscriptions(
|
||||
flags, false /*ignored*/, telegram_api::make_object<telegram_api::inputPeerSelf>(), offset)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::payments_getStarsSubscriptions>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
LOG(DEBUG) << "Receive result for GetStarsSubscriptionsQuery: " << to_string(result);
|
||||
|
||||
td_->user_manager_->on_get_users(std::move(result->users_), "GetStarsSubscriptionsQuery");
|
||||
td_->chat_manager_->on_get_chats(std::move(result->chats_), "GetStarsSubscriptionsQuery");
|
||||
|
||||
vector<td_api::object_ptr<td_api::starSubscription>> subscriptions;
|
||||
for (auto &subscription : result->subscriptions_) {
|
||||
StarSubscription star_subscription(std::move(subscription));
|
||||
if (!star_subscription.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid subscription " << star_subscription;
|
||||
} else {
|
||||
subscriptions.push_back(star_subscription.get_star_subscription_object(td_));
|
||||
}
|
||||
}
|
||||
promise_.set_value(
|
||||
td_api::make_object<td_api::starSubscriptions>(StarManager::get_star_count(result->balance_, true),
|
||||
std::move(subscriptions), result->subscriptions_next_offset_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class RefundStarsChargeQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
@ -597,6 +643,14 @@ void StarManager::do_get_star_transactions(DialogId dialog_id, const string &off
|
||||
->send(dialog_id, offset, limit, std::move(direction));
|
||||
}
|
||||
|
||||
void StarManager::get_star_subscriptions(const string &offset, int32 limit,
|
||||
Promise<td_api::object_ptr<td_api::starSubscriptions>> &&promise) {
|
||||
if (limit < 0) {
|
||||
return promise.set_error(Status::Error(400, "Limit must be non-negative"));
|
||||
}
|
||||
td_->create_handler<GetStarsSubscriptionsQuery>(std::move(promise))->send(offset, limit);
|
||||
}
|
||||
|
||||
void StarManager::refund_star_payment(UserId user_id, const string &telegram_payment_charge_id,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(user_id));
|
||||
|
@ -35,6 +35,9 @@ class StarManager final : public Actor {
|
||||
td_api::object_ptr<td_api::StarTransactionDirection> &&direction,
|
||||
Promise<td_api::object_ptr<td_api::starTransactions>> &&promise);
|
||||
|
||||
void get_star_subscriptions(const string &offset, int32 limit,
|
||||
Promise<td_api::object_ptr<td_api::starSubscriptions>> &&promise);
|
||||
|
||||
void refund_star_payment(UserId user_id, const string &telegram_payment_charge_id, Promise<Unit> &&promise);
|
||||
|
||||
void get_star_revenue_statistics(const td_api::object_ptr<td_api::MessageSender> &owner_id, bool is_dark,
|
||||
|
@ -9112,6 +9112,12 @@ void Td::on_request(uint64 id, td_api::getStarTransactions &request) {
|
||||
std::move(request.direction_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getStarSubscriptions &request) {
|
||||
CLEAN_INPUT_STRING(request.offset_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
star_manager_->get_star_subscriptions(request.offset_, request.limit_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::canPurchaseFromStore &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1874,6 +1874,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::getStarTransactions &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getStarSubscriptions &request);
|
||||
|
||||
void on_request(uint64 id, td_api::canPurchaseFromStore &request);
|
||||
|
||||
void on_request(uint64 id, td_api::assignAppStoreTransaction &request);
|
||||
|
@ -3462,6 +3462,11 @@ class CliClient final : public Actor {
|
||||
}
|
||||
send_request(td_api::make_object<td_api::getStarTransactions>(as_message_sender(owner_id), std::move(direction),
|
||||
offset, as_limit(limit)));
|
||||
} else if (op == "gssu") {
|
||||
string offset;
|
||||
string limit;
|
||||
get_args(args, offset, limit);
|
||||
send_request(td_api::make_object<td_api::getStarSubscriptions>(offset, as_limit(limit)));
|
||||
} else if (op == "cpfs" || op == "cpfsb") {
|
||||
UserId user_id;
|
||||
string currency;
|
||||
|
Loading…
Reference in New Issue
Block a user