From a24af0992245f838f2b4b418a0a2d5fa9caa27b5 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 1 Aug 2024 00:29:48 +0300 Subject: [PATCH] Add Td::do_run_request. --- td/telegram/SynchronousRequests.cpp | 2 +- td/telegram/SynchronousRequests.h | 2 +- td/telegram/Td.cpp | 8 ++++++-- td/telegram/Td.h | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/td/telegram/SynchronousRequests.cpp b/td/telegram/SynchronousRequests.cpp index ac770a0db..53a37996b 100644 --- a/td/telegram/SynchronousRequests.cpp +++ b/td/telegram/SynchronousRequests.cpp @@ -34,7 +34,7 @@ namespace td { -td_api::object_ptr SynchronousRequests::run_request(td_api::object_ptr function) { +td_api::object_ptr SynchronousRequests::run_request(td_api::object_ptr &&function) { if (function == nullptr) { return td_api::make_object(400, "Request is empty"); } diff --git a/td/telegram/SynchronousRequests.h b/td/telegram/SynchronousRequests.h index d5349eca7..472c23d99 100644 --- a/td/telegram/SynchronousRequests.h +++ b/td/telegram/SynchronousRequests.h @@ -15,7 +15,7 @@ namespace td { class SynchronousRequests { public: - static td_api::object_ptr run_request(td_api::object_ptr function); + static td_api::object_ptr run_request(td_api::object_ptr &&function); static bool is_synchronous_request(const td_api::Function *function); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 570e96255..eb2f6e627 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2598,7 +2598,7 @@ void Td::request(uint64 id, tl_object_ptr function) { run_request(id, std::move(function)); } -void Td::run_request(uint64 id, tl_object_ptr function) { +void Td::run_request(uint64 id, td_api::object_ptr function) { if (set_parameters_request_id_ > 0) { pending_set_parameters_requests_.emplace_back(id, std::move(function)); return; @@ -2675,6 +2675,10 @@ void Td::run_request(uint64 id, tl_object_ptr function) { !is_preinitialization_request(function_id) && !is_authentication_request(function_id)) { return send_error_impl(id, make_error(401, "Unauthorized")); } + do_run_request(id, std::move(function)); +} + +void Td::do_run_request(uint64 id, td_api::object_ptr &&function) { downcast_call(*function, [this, id](auto &request) { this->on_request(id, request); }); } @@ -3138,7 +3142,7 @@ template void Td::complete_pending_preauthentication_requests(const T &func) { for (auto &request : pending_preauthentication_requests_) { if (request.second != nullptr && func(request.second->get_id())) { - downcast_call(*request.second, [this, id = request.first](auto &request) { this->on_request(id, request); }); + do_run_request(request.first, std::move(request.second)); request.second = nullptr; } } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index aaeefa432..ee030565a 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -343,7 +343,9 @@ class Td final : public Actor { void on_connection_state_changed(ConnectionState new_state); - void run_request(uint64 id, tl_object_ptr function); + void run_request(uint64 id, td_api::object_ptr function); + + void do_run_request(uint64 id, td_api::object_ptr &&function); void send_result(uint64 id, tl_object_ptr object); void send_error(uint64 id, Status error);