From 9633b501120c7d64c77986f697b32cca3ecc64ae Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 9 Mar 2018 04:17:38 +0300 Subject: [PATCH] Postpone authorizationStateReady if my_id isn't known. GitOrigin-RevId: afa8d365f527672dc53424b03fff775a28569189 --- td/telegram/AuthManager.cpp | 19 ++++++++++++++++--- td/telegram/AuthManager.h | 2 ++ td/telegram/Td.cpp | 6 +++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 5d8ba2f0..a8ae8896 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -317,11 +317,13 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par if (my_id.is_valid()) { // just in case G()->shared_config().set_option_integer("my_id", my_id.get()); + update_state(State::Ok); } else { LOG(ERROR) << "Restore unknown my_id"; - ContactsManager::send_get_me_query(G()->td().get_actor_unsafe(), Auto()); + ContactsManager::send_get_me_query( + G()->td().get_actor_unsafe(), + PromiseCreator::lambda([this](Result result) { update_state(State::Ok); })); } - update_state(State::Ok); } else if (auth_str == "logout") { update_state(State::LoggingOut); } else { @@ -376,7 +378,11 @@ tl_object_ptr AuthManager::get_authorization_state_o } void AuthManager::get_state(uint64 query_id) { - send_closure(G()->td(), &Td::send_result, query_id, get_authorization_state_object(state_)); + if (state_ == State::None) { + pending_get_authorization_state_requests_.push_back(query_id); + } else { + send_closure(G()->td(), &Td::send_result, query_id, get_authorization_state_object(state_)); + } } void AuthManager::check_bot_token(uint64 query_id, string bot_token) { @@ -817,6 +823,13 @@ void AuthManager::update_state(State new_state, bool force) { state_ = new_state; send_closure(G()->td(), &Td::send_update, make_tl_object(get_authorization_state_object(state_))); + + if (!pending_get_authorization_state_requests_.empty()) { + auto query_ids = std::move(pending_get_authorization_state_requests_); + for (auto query_id : query_ids) { + send_closure(G()->td(), &Td::send_result, query_id, get_authorization_state_object(state_)); + } + } } } // namespace td diff --git a/td/telegram/AuthManager.h b/td/telegram/AuthManager.h index dfafbfb1..3d9264aa 100644 --- a/td/telegram/AuthManager.h +++ b/td/telegram/AuthManager.h @@ -168,6 +168,8 @@ class AuthManager : public NetActor { uint64 net_query_id_ = 0; NetQueryType net_query_type_; + vector pending_get_authorization_state_requests_; + void on_new_query(uint64 query_id); void on_query_error(Status status); void on_query_error(uint64 id, Status status); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 96f7cac2..10a32181 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -752,8 +752,7 @@ class GetMeRequest : public RequestActor<> { } public: - GetMeRequest(ActorShared td, uint64 request_id) - : RequestActor(std::move(td), request_id) { + GetMeRequest(ActorShared td, uint64 request_id) : RequestActor(std::move(td), request_id) { } }; @@ -4421,7 +4420,8 @@ Status Td::init(DbKey key) { send_closure(G()->td(), &Td::on_config_option_updated, name); } }; - send_closure(actor_id(this), &Td::send_update, + send_closure( + actor_id(this), &Td::send_update, make_tl_object("version", make_tl_object(tdlib_version))); G()->set_shared_config(