Better load service notifications user.

GitOrigin-RevId: b98f1652ae0ca2afb506052b28413000dd6b2a74
This commit is contained in:
levlam 2018-03-27 03:12:32 +03:00
parent 2479353230
commit 0d69e77689
3 changed files with 35 additions and 15 deletions

View File

@ -709,7 +709,7 @@ void AuthManager::on_delete_account_result(NetQueryPtr &result) {
auto r_delete_account = fetch_result<telegram_api::account_deleteAccount>(result->ok()); auto r_delete_account = fetch_result<telegram_api::account_deleteAccount>(result->ok());
if (r_delete_account.is_ok()) { if (r_delete_account.is_ok()) {
if (!r_delete_account.ok()) { if (!r_delete_account.ok()) {
status = Status::Error(500, "Receive false as result of the request"); // status = Status::Error(500, "Receive false as result of the request");
} }
} else { } else {
status = r_delete_account.move_as_error(); status = r_delete_account.move_as_error();

View File

@ -3108,20 +3108,8 @@ void ContactsManager::set_my_online_status(bool is_online, bool send_update, boo
UserId ContactsManager::get_service_notifications_user_id() { UserId ContactsManager::get_service_notifications_user_id() {
UserId user_id(777000); UserId user_id(777000);
if (!have_user_force(user_id) || !have_user(user_id)) { if (!have_user_force(user_id)) {
int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK | LOG(FATAL) << "Failed to load service notification user";
telegram_api::user::LAST_NAME_MASK | telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK |
telegram_api::user::VERIFIED_MASK;
auto user = telegram_api::make_object<telegram_api::user>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, 777000, 1, "Telegram", "Updates", string(), "42777",
telegram_api::make_object<telegram_api::userProfilePhoto>(
3337190045231018,
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26779, 5859320227133863146),
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26781, -3695031185685824216)),
nullptr, 0, string(), string(), string());
on_get_user(std::move(user));
} }
return user_id; return user_id;
} }
@ -5276,6 +5264,33 @@ bool ContactsManager::have_user_force(UserId user_id) {
} }
ContactsManager::User *ContactsManager::get_user_force(UserId user_id) { ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
auto u = get_user_force_impl(user_id);
if (user_id == UserId(777000) && (u == nullptr || !u->is_received)) {
int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK |
telegram_api::user::LAST_NAME_MASK | telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK |
telegram_api::user::VERIFIED_MASK;
auto profile_photo = telegram_api::make_object<telegram_api::userProfilePhoto>(
3337190045231018,
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26779, 5859320227133863146),
telegram_api::make_object<telegram_api::fileLocation>(1, 702229962, 26781, -3695031185685824216));
if (G()->is_test_dc()) {
profile_photo = nullptr;
flags -= telegram_api::user::PHOTO_MASK;
}
auto user = telegram_api::make_object<telegram_api::user>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, 777000, 1, "Telegram", "Updates", string(), "42777", std::move(profile_photo),
nullptr, 0, string(), string(), string());
on_get_user(std::move(user));
u = get_user(user_id);
CHECK(u != nullptr && u->is_received);
}
return u;
}
ContactsManager::User *ContactsManager::get_user_force_impl(UserId user_id) {
if (!user_id.is_valid()) { if (!user_id.is_valid()) {
return nullptr; return nullptr;
} }
@ -7983,6 +7998,10 @@ bool ContactsManager::get_user(UserId user_id, int left_tries, Promise<Unit> &&p
return false; return false;
} }
if (user_id == UserId(777000)) {
get_user_force(user_id); // preload 777000 synchronously
}
// TODO support loading user from database and merging it with min-user in memory // TODO support loading user from database and merging it with min-user in memory
if (!have_min_user(user_id)) { if (!have_min_user(user_id)) {
// TODO UserLoader // TODO UserLoader

View File

@ -762,6 +762,7 @@ class ContactsManager : public Actor {
const User *get_user(UserId user_id) const; const User *get_user(UserId user_id) const;
User *get_user(UserId user_id); User *get_user(UserId user_id);
User *get_user_force(UserId user_id); User *get_user_force(UserId user_id);
User *get_user_force_impl(UserId user_id);
User *add_user(UserId user_id); User *add_user(UserId user_id);