Add td_api::editStarSubscription.

This commit is contained in:
levlam 2024-07-25 23:13:00 +03:00
parent 597805c951
commit 3ba783158f
6 changed files with 53 additions and 0 deletions

View File

@ -11458,6 +11458,11 @@ assignAppStoreTransaction receipt:bytes purpose:StorePaymentPurpose = Ok;
//@purpose Transaction purpose
assignGooglePlayTransaction package_name:string store_product_id:string purchase_token:string purpose:StorePaymentPurpose = Ok;
//@description Cancels or reenables Telegram Star subscription to a channel
//@subscription_id Identifier of the subscription to change
//@is_canceled New value of is_canceled
editStarSubscription subscription_id:string is_canceled:Bool = Ok;
//@description Returns information about features, available to Business users @source Source of the request; pass null if the method is called from settings or some non-standard source
getBusinessFeatures source:BusinessFeature = BusinessFeatures;

View File

@ -407,6 +407,33 @@ class GetStarsSubscriptionsQuery final : public Td::ResultHandler {
}
};
class ChangeStarsSubscriptionQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit ChangeStarsSubscriptionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &subscription_id, bool is_canceled) {
send_query(G()->net_query_creator().create(telegram_api::payments_changeStarsSubscription(
telegram_api::payments_changeStarsSubscription::CANCELED_MASK,
telegram_api::make_object<telegram_api::inputPeerSelf>(), subscription_id, is_canceled)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_changeStarsSubscription>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class RefundStarsChargeQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -651,6 +678,10 @@ void StarManager::get_star_subscriptions(const string &offset, int32 limit,
td_->create_handler<GetStarsSubscriptionsQuery>(std::move(promise))->send(offset, limit);
}
void StarManager::edit_star_subscriptions(const string &subscription_id, bool is_canceled, Promise<Unit> &&promise) {
td_->create_handler<ChangeStarsSubscriptionQuery>(std::move(promise))->send(subscription_id, is_canceled);
}
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));

View File

@ -38,6 +38,8 @@ class StarManager final : public Actor {
void get_star_subscriptions(const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::starSubscriptions>> &&promise);
void edit_star_subscriptions(const string &subscription_id, bool is_canceled, Promise<Unit> &&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,

View File

@ -9113,11 +9113,19 @@ void Td::on_request(uint64 id, td_api::getStarTransactions &request) {
}
void Td::on_request(uint64 id, td_api::getStarSubscriptions &request) {
CHECK_IS_USER();
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::editStarSubscription &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.subscription_id_);
CREATE_OK_REQUEST_PROMISE();
star_manager_->edit_star_subscriptions(request.subscription_id_, request.is_canceled_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::canPurchaseFromStore &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1876,6 +1876,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::getStarSubscriptions &request);
void on_request(uint64 id, td_api::editStarSubscription &request);
void on_request(uint64 id, td_api::canPurchaseFromStore &request);
void on_request(uint64 id, td_api::assignAppStoreTransaction &request);

View File

@ -3467,6 +3467,11 @@ class CliClient final : public Actor {
string limit;
get_args(args, offset, limit);
send_request(td_api::make_object<td_api::getStarSubscriptions>(offset, as_limit(limit)));
} else if (op == "ess") {
string subscription_id;
bool is_canceled;
get_args(args, subscription_id, is_canceled);
send_request(td_api::make_object<td_api::editStarSubscription>(subscription_id, is_canceled));
} else if (op == "cpfs" || op == "cpfsb") {
UserId user_id;
string currency;