Restore unknown my_id in AuthManager.

GitOrigin-RevId: 00463e66676aba887ef3c12c7d8225ef224c0bc0
This commit is contained in:
levlam 2018-03-09 03:52:12 +03:00
parent 8ae5083073
commit 9fb92d8293
3 changed files with 13 additions and 3 deletions

View File

@ -18,6 +18,8 @@
#include "td/telegram/Td.h"
#include "td/telegram/UpdatesManager.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/crypto.h"
#include "td/utils/logging.h"
@ -315,6 +317,9 @@ 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());
} else {
LOG(ERROR) << "Restore unknown my_id";
ContactsManager::send_get_me_query(G()->td().get_actor_unsafe(), Auto());
}
update_state(State::Ok);
} else if (auth_str == "logout") {

View File

@ -7925,12 +7925,16 @@ ContactsManager::User *ContactsManager::get_user(UserId user_id) {
}
}
void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(make_tl_object<telegram_api::inputUserSelf>());
td->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
}
UserId ContactsManager::get_me(Promise<Unit> &&promise) {
auto my_id = get_my_id("get_me");
if (!have_user_force(my_id)) {
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(make_tl_object<telegram_api::inputUserSelf>());
td_->create_handler<GetUsersQuery>(std::move(promise))->send(std::move(users));
send_get_me_query(td_, std::move(promise));
return UserId();
}

View File

@ -336,6 +336,7 @@ class ContactsManager : public Actor {
bool have_min_user(UserId user_id) const;
bool have_user_force(UserId user_id);
static void send_get_me_query(Td *td, Promise<Unit> &&promise);
UserId get_me(Promise<Unit> &&promise);
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);
bool get_user_full(UserId user_id, Promise<Unit> &&promise);