Add Td::do_run_request.

This commit is contained in:
levlam 2024-08-01 00:29:48 +03:00
parent 98a2dc2a45
commit a24af09922
4 changed files with 11 additions and 5 deletions

View File

@ -34,7 +34,7 @@
namespace td {
td_api::object_ptr<td_api::Object> SynchronousRequests::run_request(td_api::object_ptr<td_api::Function> function) {
td_api::object_ptr<td_api::Object> SynchronousRequests::run_request(td_api::object_ptr<td_api::Function> &&function) {
if (function == nullptr) {
return td_api::make_object<td_api::error>(400, "Request is empty");
}

View File

@ -15,7 +15,7 @@ namespace td {
class SynchronousRequests {
public:
static td_api::object_ptr<td_api::Object> run_request(td_api::object_ptr<td_api::Function> function);
static td_api::object_ptr<td_api::Object> run_request(td_api::object_ptr<td_api::Function> &&function);
static bool is_synchronous_request(const td_api::Function *function);

View File

@ -2598,7 +2598,7 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
run_request(id, std::move(function));
}
void Td::run_request(uint64 id, tl_object_ptr<td_api::Function> function) {
void Td::run_request(uint64 id, td_api::object_ptr<td_api::Function> 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<td_api::Function> 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<td_api::Function> &&function) {
downcast_call(*function, [this, id](auto &request) { this->on_request(id, request); });
}
@ -3138,7 +3142,7 @@ template <class T>
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;
}
}

View File

@ -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<td_api::Function> function);
void run_request(uint64 id, td_api::object_ptr<td_api::Function> function);
void do_run_request(uint64 id, td_api::object_ptr<td_api::Function> &&function);
void send_result(uint64 id, tl_object_ptr<td_api::Object> object);
void send_error(uint64 id, Status error);