Send updateOption("my_id") before authorizationStateReady.

GitOrigin-RevId: 73fdce38a87ffb6fcea8bfa8b059f83dcd510007
This commit is contained in:
levlam 2018-03-09 00:42:25 +03:00
parent b9b35ebe0a
commit 5986bb7df0
4 changed files with 33 additions and 21 deletions

View File

@ -311,6 +311,11 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par
if (is_bot_str == "true") {
is_bot_ = true;
}
auto my_id = ContactsManager::load_my_id();
if (my_id.is_valid()) {
// just in case
G()->shared_config().set_option_integer("my_id", my_id.get());
}
update_state(State::Ok);
} else if (auth_str == "logout") {
update_state(State::LoggingOut);
@ -716,8 +721,9 @@ void AuthManager::on_authorization(tl_object_ptr<telegram_api::auth_authorizatio
G()->td_db()->get_binlog_pmc()->set("auth_is_bot", "true");
}
G()->td_db()->get_binlog_pmc()->set("auth", "ok");
update_state(State::Ok);
state_ = State::Ok;
td->contacts_manager_->on_get_user(std::move(auth->user_), true);
update_state(State::Ok, true);
if (!td->contacts_manager_->get_my_id("on_authorization").is_valid()) {
LOG(ERROR) << "Server doesn't send proper authorization";
if (query_id_ != 0) {

View File

@ -2322,23 +2322,8 @@ const CSlice ContactsManager::INVITE_LINK_URLS[3] = {"t.me/joinchat/", "telegram
ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
upload_profile_photo_callback_ = std::make_shared<UploadProfilePhotoCallback>();
auto id_string = G()->td_db()->get_binlog_pmc()->get("my_id");
if (!id_string.empty()) {
UserId new_my_id(to_integer<int32>(id_string));
if (new_my_id.is_valid()) {
my_id_ = new_my_id;
G()->shared_config().set_option_integer("my_id", my_id_.get());
} else {
new_my_id = UserId(to_integer<int32>(Slice(id_string).substr(5)));
if (new_my_id.is_valid()) {
my_id_ = new_my_id;
G()->td_db()->get_binlog_pmc()->set("my_id", to_string(my_id_.get()));
G()->shared_config().set_option_integer("my_id", my_id_.get());
} else {
LOG(ERROR) << "Wrong my id = \"" << id_string << "\" stored in database";
}
}
}
my_id_ = load_my_id();
if (G()->parameters().use_chat_info_db) {
auto next_contacts_sync_date_string = G()->td_db()->get_binlog_pmc()->get("next_contacts_sync_date");
if (!next_contacts_sync_date_string.empty()) {
@ -2365,6 +2350,25 @@ void ContactsManager::tear_down() {
parent_.reset();
}
UserId ContactsManager::load_my_id() {
auto id_string = G()->td_db()->get_binlog_pmc()->get("my_id");
if (!id_string.empty()) {
UserId my_id(to_integer<int32>(id_string));
if (my_id.is_valid()) {
return my_id;
}
my_id = UserId(to_integer<int32>(Slice(id_string).substr(5)));
if (my_id.is_valid()) {
G()->td_db()->get_binlog_pmc()->set("my_id", to_string(my_id.get()));
return my_id;
}
LOG(ERROR) << "Wrong my id = \"" << id_string << "\" stored in database";
}
return UserId();
}
void ContactsManager::on_user_online_timeout_callback(void *contacts_manager_ptr, int64 user_id_long) {
auto contacts_manager = static_cast<ContactsManager *>(contacts_manager_ptr);
UserId user_id(narrow_cast<int32>(user_id_long));

View File

@ -59,6 +59,8 @@ class ContactsManager : public Actor {
public:
ContactsManager(Td *td, ActorShared<> parent);
static UserId load_my_id();
static UserId get_user_id(const tl_object_ptr<telegram_api::User> &user);
static ChatId get_chat_id(const tl_object_ptr<telegram_api::Chat> &chat);
static ChannelId get_channel_id(const tl_object_ptr<telegram_api::Chat> &chat);

View File

@ -4004,8 +4004,8 @@ void Td::on_config_option_updated(const string &name) {
} else if (is_internal_config_option(name)) {
return;
}
send_closure(actor_id(this), &Td::send_update,
make_tl_object<td_api::updateOption>(name, G()->shared_config().get_option_value(name)));
// send_closure was already used in the callback
send_update(make_tl_object<td_api::updateOption>(name, G()->shared_config().get_option_value(name)));
}
tl_object_ptr<td_api::ConnectionState> Td::get_connection_state_object(StateManager::State state) {
@ -4404,7 +4404,7 @@ Status Td::init(DbKey key) {
send_closure(G()->td(), &Td::on_config_option_updated, name);
}
};
send_update(
send_closure(actor_id(this), &Td::send_update,
make_tl_object<td_api::updateOption>("version", make_tl_object<td_api::optionValueString>(tdlib_version)));
G()->set_shared_config(