diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 26efcd6c2..be81a4181 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -108,7 +108,13 @@ class GetUpdatesStateQuery : public Td::ResultHandler { }; class PingServerQuery : public Td::ResultHandler { + Promise> promise_; + public: + explicit PingServerQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + void send() { send_query(G()->net_query_creator().create(telegram_api::updates_getState())); } @@ -119,14 +125,11 @@ class PingServerQuery : public Td::ResultHandler { return on_error(id, result_ptr.move_as_error()); } - auto state = result_ptr.move_as_ok(); - CHECK(state->get_id() == telegram_api::updates_state::ID); - td->updates_manager_->on_server_pong(std::move(state)); + promise_.set_value(result_ptr.move_as_ok()); } void on_error(uint64 id, Status status) override { - status.ignore(); - td->updates_manager_->on_server_pong(nullptr); + promise_.set_error(std::move(status)); } }; @@ -1135,7 +1138,11 @@ void UpdatesManager::init_state() { } void UpdatesManager::ping_server() { - td_->create_handler()->send(); + auto promise = PromiseCreator::lambda([](Result> result) { + auto state = result.is_ok() ? result.move_as_ok() : nullptr; + send_closure(G()->updates_manager(), &UpdatesManager::on_server_pong, std::move(state)); + }); + td_->create_handler(std::move(promise))->send(); } void UpdatesManager::on_server_pong(tl_object_ptr &&state) { diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 5c9640cd8..810f37472 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -113,8 +113,6 @@ class UpdatesManager : public Actor { void ping_server(); - void on_server_pong(tl_object_ptr &&state); - bool running_get_difference() const { return running_get_difference_; } @@ -225,6 +223,8 @@ class UpdatesManager : public Actor { void on_get_updates_state(tl_object_ptr &&state, const char *source); + void on_server_pong(tl_object_ptr &&state); + void on_get_difference(tl_object_ptr &&difference_ptr); void process_get_difference_updates(vector> &&new_messages,