From fc07381efeaab1233abcc6116fb046bf44724bbf Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 15 Aug 2024 19:17:16 +0300 Subject: [PATCH] Move SetBotUpdatesStatusQuery to BotQueries.cpp. --- SplitSource.php | 1 + td/telegram/BotQueries.cpp | 30 ++++++++++++++++++++++++++++++ td/telegram/BotQueries.h | 2 ++ td/telegram/Requests.cpp | 29 ++--------------------------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/SplitSource.php b/SplitSource.php index c1301b01c..af151cce1 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -308,6 +308,7 @@ function split_file($file, $chunks, $undo) { 'BackgroundType' => 'BackgroundType', 'Birthdate' => 'Birthdate', 'BotMenuButton|[a-z_]*_menu_button' => 'BotMenuButton', + 'send_bot_custom_query|answer_bot_custom_query|set_bot_updates_status' => 'BotQueries', 'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager', 'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager', 'BusinessAwayMessage' => 'BusinessAwayMessage', diff --git a/td/telegram/BotQueries.cpp b/td/telegram/BotQueries.cpp index a992cd2b4..34f34a8f9 100644 --- a/td/telegram/BotQueries.cpp +++ b/td/telegram/BotQueries.cpp @@ -73,6 +73,31 @@ class AnswerCustomQueryQuery final : public Td::ResultHandler { } }; +class SetBotUpdatesStatusQuery final : public Td::ResultHandler { + public: + void send(int32 pending_update_count, const string &error_message) { + send_query( + G()->net_query_creator().create(telegram_api::help_setBotUpdatesStatus(pending_update_count, error_message))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + bool result = result_ptr.ok(); + LOG_IF(WARNING, !result) << "Set bot updates status has failed"; + } + + void on_error(Status status) final { + if (!G()->is_expected_error(status)) { + LOG(WARNING) << "Receive error for SetBotUpdatesStatusQuery: " << status; + } + status.ignore(); + } +}; + void send_bot_custom_query(Td *td, const string &method, const string ¶meters, Promise> &&promise) { td->create_handler(std::move(promise))->send(method, parameters); @@ -82,4 +107,9 @@ void answer_bot_custom_query(Td *td, int64 custom_query_id, const string &data, td->create_handler(std::move(promise))->send(custom_query_id, data); } +void set_bot_updates_status(Td *td, int32 pending_update_count, const string &error_message, Promise &&promise) { + td->create_handler()->send(pending_update_count, error_message); + promise.set_value(Unit()); +} + } // namespace td diff --git a/td/telegram/BotQueries.h b/td/telegram/BotQueries.h index 844e8ccf5..5364520b9 100644 --- a/td/telegram/BotQueries.h +++ b/td/telegram/BotQueries.h @@ -20,4 +20,6 @@ void send_bot_custom_query(Td *td, const string &method, const string ¶meter void answer_bot_custom_query(Td *td, int64 custom_query_id, const string &data, Promise &&promise); +void set_bot_updates_status(Td *td, int32 pending_update_count, const string &error_message, Promise &&promise); + } // namespace td diff --git a/td/telegram/Requests.cpp b/td/telegram/Requests.cpp index 3501b9dab..658118153 100644 --- a/td/telegram/Requests.cpp +++ b/td/telegram/Requests.cpp @@ -276,31 +276,6 @@ class GetRecentMeUrlsQuery final : public Td::ResultHandler { } }; -class SetBotUpdatesStatusQuery final : public Td::ResultHandler { - public: - void send(int32 pending_update_count, const string &error_message) { - send_query( - G()->net_query_creator().create(telegram_api::help_setBotUpdatesStatus(pending_update_count, error_message))); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(result_ptr.move_as_error()); - } - - bool result = result_ptr.ok(); - LOG_IF(WARNING, !result) << "Set bot updates status has failed"; - } - - void on_error(Status status) final { - if (!G()->is_expected_error(status)) { - LOG(WARNING) << "Receive error for SetBotUpdatesStatusQuery: " << status; - } - status.ignore(); - } -}; - class TestNetworkQuery final : public Td::ResultHandler { Promise promise_; @@ -7628,8 +7603,8 @@ void Requests::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) void Requests::on_request(uint64 id, td_api::setBotUpdatesStatus &request) { CHECK_IS_BOT(); CLEAN_INPUT_STRING(request.error_message_); - td_->create_handler()->send(request.pending_update_count_, request.error_message_); - send_closure(td_actor_, &Td::send_result, id, td_api::make_object()); + CREATE_OK_REQUEST_PROMISE(); + set_bot_updates_status(td_, request.pending_update_count_, request.error_message_, std::move(promise)); } void Requests::on_request(uint64 id, td_api::sendCustomRequest &request) {