diff options
| author | levlam <levlam@telegram.org> | 2026-07-08 00:06:36 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-07-08 00:06:36 +0300 |
| commit | cb02d4b15624c5de7b306adc9c0dc9a85fb86372 (patch) | |
| tree | 03d4345b87f144fb000fffc134ec03dc5d638635 | |
| parent | 0c57fc0fe306bf35b541e1d66b852bf06c48b892 (diff) | |
Add td_api::updateUserSubscription.
| -rw-r--r-- | td/generate/scheme/td_api.tl | 8 | ||||
| -rw-r--r-- | td/telegram/UpdatesManager.cpp | 27 | ||||
| -rw-r--r-- | 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 <limits> @@ -3339,6 +3340,20 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up break; } case telegram_api::updateBotStarsSubscription::ID: { + auto update = move_tl_object_as<telegram_api::updateBotStarsSubscription>(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<int>(update->canceled_) + static_cast<int>(update->restored_) + + static_cast<int>(update->payment_failed_) != + 1u) { + LOG(ERROR) << "Receive invalid " << to_string(update); + break; + } + send_closure(G()->td(), &Td::send_update, + td_api::make_object<td_api::updateUserSubscription>( + 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<telegram_api::updateBotDeleteBusine add_pending_qts_update(std::move(update), qts, std::move(promise)); } +void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotStarsSubscription> update, + Promise<Unit> &&promise) { + auto qts = update->qts_; + add_pending_qts_update(std::move(update), qts, std::move(promise)); +} + void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStarsBalance> update, Promise<Unit> &&promise) { switch (update->balance_->get_id()) { case telegram_api::starsAmount::ID: @@ -5054,12 +5075,6 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateWebBrowserExcep // unsupported updates -void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotStarsSubscription> update, - Promise<Unit> &&promise) { - auto qts = update->qts_; - add_pending_qts_update(std::move(update), qts, std::move(promise)); -} - void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewStoryReaction> update, Promise<Unit> &&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<telegram_api::updateBotDeleteBusinessMessage> update, Promise<Unit> &&promise); + void on_update(tl_object_ptr<telegram_api::updateBotStarsSubscription> update, Promise<Unit> &&promise); + void on_update(tl_object_ptr<telegram_api::updateStarsBalance> update, Promise<Unit> &&promise); void on_update(tl_object_ptr<telegram_api::updateStarsRevenueStatus> update, Promise<Unit> &&promise); @@ -779,8 +781,6 @@ class UpdatesManager final : public Actor { // unsupported updates - void on_update(tl_object_ptr<telegram_api::updateBotStarsSubscription> update, Promise<Unit> &&promise); - void on_update(tl_object_ptr<telegram_api::updateNewStoryReaction> update, Promise<Unit> &&promise); void on_update(tl_object_ptr<telegram_api::updateEphemeralBotCallbackQuery> update, Promise<Unit> &&promise); |
