diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index b47a9f948..78e5e0593 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -1121,28 +1121,8 @@ bool AuthManager::load_state() { LOG(INFO) << "Ignore auth_state: api_id or api_hash changed"; return false; } - if (!db_state.state_timestamp_.is_in_past()) { - LOG(INFO) << "Ignore auth_state: timestamp in the future"; - return false; - } - auto state_timeout = [state = db_state.state_] { - switch (state) { - case State::WaitPassword: - case State::WaitRegistration: - return 86400; - case State::WaitEmailAddress: - case State::WaitEmailCode: - case State::WaitCode: - case State::WaitQrCodeConfirmation: - return 5 * 60; - default: - UNREACHABLE(); - return 0; - } - }(); - - if (Timestamp::at(db_state.state_timestamp_.at() + state_timeout).is_in_past()) { - LOG(INFO) << "Ignore auth_state: expired " << db_state.state_timestamp_.in(); + if (db_state.expires_at_ <= Time::now()) { + LOG(INFO) << "Ignore auth_state: expired"; return false; } diff --git a/td/telegram/AuthManager.h b/td/telegram/AuthManager.h index d6aeef3c3..0ae4d2d16 100644 --- a/td/telegram/AuthManager.h +++ b/td/telegram/AuthManager.h @@ -117,7 +117,7 @@ class AuthManager final : public NetActor { State state_; int32 api_id_; string api_hash_; - Timestamp state_timestamp_; + double expires_at_; // WaitEmailAddress and WaitEmailCode bool allow_apple_id_ = false; @@ -202,7 +202,23 @@ class AuthManager final : public NetActor { private: DbState(State state, int32 api_id, string &&api_hash) - : state_(state), api_id_(api_id), api_hash_(std::move(api_hash)), state_timestamp_(Timestamp::now()) { + : state_(state), api_id_(api_id), api_hash_(std::move(api_hash)) { + auto state_timeout = [state] { + switch (state) { + case State::WaitPassword: + case State::WaitRegistration: + return 86400; + case State::WaitEmailAddress: + case State::WaitEmailCode: + case State::WaitCode: + case State::WaitQrCodeConfirmation: + return 5 * 60; + default: + UNREACHABLE(); + return 0; + } + }(); + expires_at_ = Time::now() + state_timeout; } }; diff --git a/td/telegram/AuthManager.hpp b/td/telegram/AuthManager.hpp index 65225376e..c6cf496d1 100644 --- a/td/telegram/AuthManager.hpp +++ b/td/telegram/AuthManager.hpp @@ -70,7 +70,7 @@ void AuthManager::DbState::store(StorerT &storer) const { store(state_, storer); store(api_id_, storer); store(api_hash_, storer); - store_time(state_timestamp_.at(), storer); + store_time(expires_at_, storer); if (has_terms_of_service) { store(terms_of_service_, storer); @@ -133,9 +133,7 @@ void AuthManager::DbState::parse(ParserT &parser) { parse(state_, parser); parse(api_id_, parser); parse(api_hash_, parser); - double state_timestamp = 0.0; - parse_time(state_timestamp, parser); - state_timestamp_ = Timestamp::at(state_timestamp); + parse_time(expires_at_, parser); if (has_terms_of_service) { parse(terms_of_service_, parser);