From cb02d4b15624c5de7b306adc9c0dc9a85fb86372 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 8 Jul 2026 00:06:36 +0300 Subject: Add td_api::updateUserSubscription. --- td/generate/scheme/td_api.tl | 8 ++++++++ td/telegram/UpdatesManager.cpp | 27 +++++++++++++++++++++------ td/telegram/UpdatesManager.h | 4 ++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 41b980d8e..80401949e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -10991,6 +10991,14 @@ updateNewCustomEvent event:string = Update; //@description A new incoming query; for bots only @id The query identifier @data JSON-serialized query data @timeout Query timeout updateNewCustomQuery id:int64 data:string timeout:int32 = Update; +//@description Subscription of a user to the bot was changed; for bots only +//@user_id Identifier of the user +//@payload Bot-specified subscription invoice payload +//@is_canceled True, if the subscription was canceled +//@is_restored True, if the subscription was restored +//@is_payment_failed True, if the payment for the subscription has failed +updateUserSubscription user_id:int53 payload:string is_canceled:Bool is_restored:Bool is_payment_failed:Bool = Update; + //@description A poll was updated; for bots only @poll New data about the poll updatePoll poll:poll = Update; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 9082fdefc..09562db8c 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -112,6 +112,7 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" +#include "td/utils/utf8.h" #include @@ -3339,6 +3340,20 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up break; } case telegram_api::updateBotStarsSubscription::ID: { + auto update = move_tl_object_as(update_ptr); + auto user_id = UserId(update->user_id_); + auto payload = update->payload_.as_slice().str(); + if (!user_id.is_valid() || !check_utf8(payload) || + static_cast(update->canceled_) + static_cast(update->restored_) + + static_cast(update->payment_failed_) != + 1u) { + LOG(ERROR) << "Receive invalid " << to_string(update); + break; + } + send_closure(G()->td(), &Td::send_update, + td_api::make_object( + td_->user_manager_->get_user_id_object(user_id, "updateUserSubscription"), payload, + update->canceled_, update->restored_, update->payment_failed_)); break; } default: @@ -5001,6 +5016,12 @@ void UpdatesManager::on_update(tl_object_ptr update, + Promise &&promise) { + auto qts = update->qts_; + add_pending_qts_update(std::move(update), qts, std::move(promise)); +} + void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { switch (update->balance_->get_id()) { case telegram_api::starsAmount::ID: @@ -5054,12 +5075,6 @@ void UpdatesManager::on_update(tl_object_ptr update, - Promise &&promise) { - auto qts = update->qts_; - add_pending_qts_update(std::move(update), qts, std::move(promise)); -} - void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { promise.set_value(Unit()); } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index aa6000812..6bb30d48d 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -767,6 +767,8 @@ class UpdatesManager final : public Actor { void on_update(tl_object_ptr update, Promise &&promise); + void on_update(tl_object_ptr update, Promise &&promise); + void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); @@ -779,8 +781,6 @@ class UpdatesManager final : public Actor { // unsupported updates - void on_update(tl_object_ptr update, Promise &&promise); - void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); -- cgit v1.2.3