Skip to content

Commit

Permalink
Add Td::do_run_request.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 31, 2024
1 parent 98a2dc2 commit a24af09
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion td/telegram/SynchronousRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/SynchronousRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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); });
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion td/telegram/Td.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a24af09

Please sign in to comment.