diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ffdacbc3b..aa17df2e8 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -12,6 +12,7 @@ #include "td/telegram/AuthManager.h" #include "td/telegram/ConfigShared.h" +#include "td/telegram/DeviceTokenManager.h" #include "td/telegram/FileReferenceManager.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileType.h" @@ -220,6 +221,7 @@ class ResetAuthorizationsQuery : public Td::ResultHandler { bool result = result_ptr.move_as_ok(); LOG_IF(WARNING, !result) << "Failed to terminate all sessions"; + send_closure(td->device_token_manager_, &DeviceTokenManager::reregister_device); promise_.set_value(Unit()); } diff --git a/td/telegram/DeviceTokenManager.cpp b/td/telegram/DeviceTokenManager.cpp index d6b7093a2..c7c9b3e2f 100644 --- a/td/telegram/DeviceTokenManager.cpp +++ b/td/telegram/DeviceTokenManager.cpp @@ -268,6 +268,16 @@ void DeviceTokenManager::register_device(tl_object_ptr devi save_info(token_type); } +void DeviceTokenManager::reregister_device() { + for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) { + auto &token = tokens_[token_type]; + if (token.state == TokenInfo::State::Sync && !token.token.empty()) { + token.state = TokenInfo::State::Register; + } + } + loop(); +} + vector> DeviceTokenManager::get_encryption_keys() const { vector> result; for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) { @@ -318,7 +328,7 @@ void DeviceTokenManager::start_up() { token.token = serialized.substr(1); } LOG(INFO) << "GET device token " << token_type << "--->" << token; - if (token.state == TokenInfo::State::Sync) { + if (token.state == TokenInfo::State::Sync && !token.token.empty()) { token.state = TokenInfo::State::Register; } } diff --git a/td/telegram/DeviceTokenManager.h b/td/telegram/DeviceTokenManager.h index e03e338eb..91ea862ba 100644 --- a/td/telegram/DeviceTokenManager.h +++ b/td/telegram/DeviceTokenManager.h @@ -29,6 +29,8 @@ class DeviceTokenManager : public NetQueryCallback { void register_device(tl_object_ptr device_token_ptr, vector other_user_ids, Promise> promise); + void reregister_device(); + vector> get_encryption_keys() const; private: