Take main DC and phone prefix from active account.

This commit is contained in:
John Preston 2020-06-29 22:14:16 +04:00
parent eff340deaf
commit 90f7f482ee
5 changed files with 27 additions and 7 deletions

View file

@ -18,7 +18,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "main/main_account.h" #include "main/main_account.h"
#include "main/main_domain.h" #include "main/main_domain.h"
#include "main/main_session.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "data/data_user.h"
#include "data/data_countries.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
@ -41,6 +44,20 @@ namespace {
using namespace ::Intro::details; using namespace ::Intro::details;
[[nodiscard]] QString ComputeNewAccountCountry() {
if (const auto parent
= Core::App().domain().maybeLastOrSomeAuthedAccount()) {
if (const auto session = parent->maybeSession()) {
const auto iso = ::Data::CountryISO2ByPhone(
session->user()->phone());
if (!iso.isEmpty()) {
return iso;
}
}
}
return Platform::SystemCountry();
}
} // namespace } // namespace
Widget::Widget( Widget::Widget(
@ -65,10 +82,11 @@ Widget::Widget(
rpl::single(true))) { rpl::single(true))) {
Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate()); Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate());
getNearestDC(); getData()->country = ComputeNewAccountCountry();
switch (point) { switch (point) {
case EnterPoint::Start: case EnterPoint::Start:
getNearestDC();
appendStep(new StartWidget(this, _account, getData())); appendStep(new StartWidget(this, _account, getData()));
break; break;
case EnterPoint::Phone: case EnterPoint::Phone:
@ -82,8 +100,6 @@ Widget::Widget(
fixOrder(); fixOrder();
getData()->country = Platform::SystemCountry();
_account->mtpValue( _account->mtpValue(
) | rpl::start_with_next([=](not_null<MTP::Instance*> instance) { ) | rpl::start_with_next([=](not_null<MTP::Instance*> instance) {
_api.emplace(instance); _api.emplace(instance);

View file

@ -236,7 +236,7 @@ rpl::producer<> Account::mtpNewSessionCreated() const {
return _mtpNewSessionCreated.events(); return _mtpNewSessionCreated.events();
} }
void Account::setLegacyMtpMainDcId(MTP::DcId mainDcId) { void Account::setMtpMainDcId(MTP::DcId mainDcId) {
Expects(!_mtp); Expects(!_mtp);
_mtpFields.mainDcId = mainDcId; _mtpFields.mainDcId = mainDcId;

View file

@ -82,8 +82,9 @@ public:
[[nodiscard]] rpl::producer<not_null<MTP::Instance*>> mtpValue() const; [[nodiscard]] rpl::producer<not_null<MTP::Instance*>> mtpValue() const;
// Set from legacy storage. // Set from legacy storage.
void setLegacyMtpMainDcId(MTP::DcId mainDcId);
void setLegacyMtpKey(std::shared_ptr<MTP::AuthKey> key); void setLegacyMtpKey(std::shared_ptr<MTP::AuthKey> key);
void setMtpMainDcId(MTP::DcId mainDcId);
void setSessionUserId(UserId userId); void setSessionUserId(UserId userId);
void setSessionFromStorage( void setSessionFromStorage(
std::unique_ptr<SessionSettings> data, std::unique_ptr<SessionSettings> data,

View file

@ -219,7 +219,9 @@ not_null<Main::Account*> Domain::add(MTP::Environment environment) {
static const auto cloneConfig = [](const MTP::Config &config) { static const auto cloneConfig = [](const MTP::Config &config) {
return std::make_unique<MTP::Config>(config); return std::make_unique<MTP::Config>(config);
}; };
static const auto accountConfig = [](not_null<Account*> account) { auto mainDcId = MTP::Instance::Fields::kNotSetMainDc;
const auto accountConfig = [&](not_null<Account*> account) {
mainDcId = account->mtp().mainDcId();
return cloneConfig(account->mtp().config()); return cloneConfig(account->mtp().config());
}; };
auto config = [&] { auto config = [&] {
@ -244,6 +246,7 @@ not_null<Main::Account*> Domain::add(MTP::Environment environment) {
.account = std::make_unique<Account>(this, _dataName, index) .account = std::make_unique<Account>(this, _dataName, index)
}); });
const auto account = _accounts.back().account.get(); const auto account = _accounts.back().account.get();
account->setMtpMainDcId(mainDcId);
_local->startAdded(account, std::move(config)); _local->startAdded(account, std::move(config));
watchSession(account); watchSession(account);
_accountsChanges.fire({}); _accountsChanges.fire({});

View file

@ -853,7 +853,7 @@ std::unique_ptr<Main::SessionSettings> Account::applyReadContext(
_owner->setLegacyMtpKey(std::move(key)); _owner->setLegacyMtpKey(std::move(key));
} }
if (context.mtpLegacyMainDcId) { if (context.mtpLegacyMainDcId) {
_owner->setLegacyMtpMainDcId(context.mtpLegacyMainDcId); _owner->setMtpMainDcId(context.mtpLegacyMainDcId);
_owner->setSessionUserId(context.mtpLegacyUserId); _owner->setSessionUserId(context.mtpLegacyUserId);
} }
} }