diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index ede80af6f..ba1ffae8a 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -456,13 +456,6 @@ void Application::logout(Main::Account *account) { account->logOut(); } else { accounts().resetWithForgottenPasscode(); - - if (Global::LocalPasscode()) { - Global::SetLocalPasscode(false); - Global::RefLocalPasscodeChanged().notify(); - } - Core::App().unlockPasscode(); - Core::App().unlockTerms(); } } diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index 0b854a474..cb51e9620 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -460,9 +460,8 @@ void Account::loggedOut() { window->tempDirDelete(Local::ClearManagerAll); } destroySession(); + Core::App().unlockTerms(); local().reset(); - Local::reset(); - cSetOtherOnline(0); } diff --git a/Telegram/SourceFiles/main/main_accounts.cpp b/Telegram/SourceFiles/main/main_accounts.cpp index 519cbe5b8..bb0049887 100644 --- a/Telegram/SourceFiles/main/main_accounts.cpp +++ b/Telegram/SourceFiles/main/main_accounts.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "storage/storage_accounts.h" #include "storage/localstorage.h" +#include "facades.h" namespace Main { @@ -73,6 +74,7 @@ void Accounts::activateAfterStarting() { } activate(_activeIndex); + removePasscodeIfEmpty(); } const base::flat_map> &Accounts::list() const { @@ -131,7 +133,7 @@ void Accounts::watchSession(not_null account) { account->startMtp(); account->sessionChanges( ) | rpl::filter([=](Session *session) { - return !session && _accounts.size() > 1; + return !session; // removeRedundantAccounts may remove passcode lock. }) | rpl::start_with_next([=](Session *session) { if (account == _active.current()) { activateAuthedAccount(); @@ -156,6 +158,20 @@ void Accounts::activateAuthedAccount() { } } +bool Accounts::removePasscodeIfEmpty() { + if (_accounts.size() != 1 || _active.current()->sessionExists()) { + return false; + } + Local::reset(); + if (!Global::LocalPasscode()) { + return false; + } + // We completely logged out, remove the passcode if it was there. + Core::App().unlockPasscode(); + _local->setPasscode(QByteArray()); + return true; +} + void Accounts::removeRedundantAccounts() { Expects(started()); @@ -169,7 +185,8 @@ void Accounts::removeRedundantAccounts() { } i = _accounts.erase(i); } - if (_accounts.size() != was) { + + if (!removePasscodeIfEmpty() && _accounts.size() != was) { scheduleWriteAccounts(); } } diff --git a/Telegram/SourceFiles/main/main_accounts.h b/Telegram/SourceFiles/main/main_accounts.h index 50b21f19a..555472cf8 100644 --- a/Telegram/SourceFiles/main/main_accounts.h +++ b/Telegram/SourceFiles/main/main_accounts.h @@ -51,6 +51,7 @@ public: private: void activateAfterStarting(); void activateAuthedAccount(); + bool removePasscodeIfEmpty(); void removeRedundantAccounts(); void watchSession(not_null account); void scheduleWriteAccounts(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index dabaca6e3..1baca05b8 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -358,6 +358,32 @@ MainWidget::MainWidget( Core::UpdateChecker checker; checker.start(); } + + auto &api = session().api(); + api.requestNotifySettings(MTP_inputNotifyUsers()); + api.requestNotifySettings(MTP_inputNotifyChats()); + api.requestNotifySettings(MTP_inputNotifyBroadcasts()); + + cSetOtherOnline(0); + session().user()->loadUserpic(); + + auto &local = session().local(); + local.readInstalledStickers(); + local.readFeaturedStickers(); + local.readRecentStickers(); + local.readFavedStickers(); + local.readSavedGifs(); + auto &data = session().data(); + if (const auto availableAt = local.readExportSettings().availableAt) { + data.suggestStartExport(availableAt); + } + auto &stickers = data.stickers(); + stickers.notifyUpdated(); + stickers.notifySavedGifsUpdated(); + + _history->start(); + + Core::App().checkStartUrl(); } MainWidget::~MainWidget() = default; @@ -2498,7 +2524,7 @@ void MainWidget::updateWindowAdaptiveLayout() { // dialogs widget to provide a wide enough chat history column. // Don't shrink the column on the first call, when window is inited. if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn - && _started && _controller->widget()->positionInited()) { + && _controller->widget()->positionInited()) { //auto chatWidth = layout.chatWidth; //if (_history->willSwitchToTabbedSelectorWithWidth(chatWidth)) { // auto thirdColumnWidth = _history->tabbedSelectorSectionWidth(); @@ -2547,39 +2573,6 @@ void MainWidget::searchInChat(Dialogs::Key chat) { } } -void MainWidget::start() { - auto &api = session().api(); - api.requestNotifySettings(MTP_inputNotifyUsers()); - api.requestNotifySettings(MTP_inputNotifyChats()); - api.requestNotifySettings(MTP_inputNotifyBroadcasts()); - - cSetOtherOnline(0); - session().user()->loadUserpic(); - - _started = true; - auto &local = session().local(); - local.readInstalledStickers(); - local.readFeaturedStickers(); - local.readRecentStickers(); - local.readFavedStickers(); - local.readSavedGifs(); - auto &data = session().data(); - if (const auto availableAt = local.readExportSettings().availableAt) { - data.suggestStartExport(availableAt); - } - auto &stickers = data.stickers(); - stickers.notifyUpdated(); - stickers.notifySavedGifsUpdated(); - - _history->start(); - - Core::App().checkStartUrl(); -} - -bool MainWidget::started() { - return _started; -} - void MainWidget::openPeerByName( const QString &username, MsgId msgId, diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 5489c8e96..6c9033a3e 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -118,15 +118,12 @@ public: void showAnimated(const QPixmap &bgAnimCache, bool back = false); - void start(); - void openPeerByName( const QString &name, MsgId msgId = ShowAtUnreadMsgId, const QString &startToken = QString(), FullMsgId clickFromMessageId = FullMsgId()); - bool started(); void activate(); void windowShown(); @@ -349,8 +346,7 @@ private: void handleHistoryBack(); - not_null _controller; - bool _started = false; + const not_null _controller; Ui::Animations::Simple _a_show; bool _showBack = false; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 13f93956f..07b286109 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -197,15 +197,17 @@ void MainWindow::clearWidgetsHook() { destroyLayer(); _mediaPreview.destroy(); _main.destroy(); - _passcodeLock.destroy(); _intro.destroy(); + if (!Core::App().passcodeLocked()) { + _passcodeLock.destroy(); + } } QPixmap MainWindow::grabInner() { - if (_intro) { - return Ui::GrabWidget(_intro); - } else if (_passcodeLock) { + if (_passcodeLock) { return Ui::GrabWidget(_passcodeLock); + } else if (_intro) { + return Ui::GrabWidget(_intro); } else if (_main) { return Ui::GrabWidget(_main); } @@ -242,10 +244,14 @@ void MainWindow::clearPasscodeLock() { if (_intro) { auto bg = grabInner(); _passcodeLock.destroy(); + _intro->show(); + updateControlsGeometry(); _intro->showAnimated(bg, true); } else if (_main) { auto bg = grabInner(); _passcodeLock.destroy(); + _main->show(); + updateControlsGeometry(); _main->showAnimated(bg, true); Core::App().checkStartUrl(); } @@ -257,14 +263,17 @@ void MainWindow::setupIntro() { clearWidgets(); _intro.create(bodyWidget(), &account()); - updateControlsGeometry(); - - if (animated) { - _intro->showAnimated(bg); + if (_passcodeLock) { + _intro->hide(); } else { - setInnerFocus(); + _intro->show(); + updateControlsGeometry(); + if (animated) { + _intro->showAnimated(bg); + } else { + setInnerFocus(); + } } - fixOrder(); } @@ -275,18 +284,19 @@ void MainWindow::setupMain() { auto bg = animated ? grabInner() : QPixmap(); clearWidgets(); - _main.create(bodyWidget(), sessionController()); - _main->show(); - updateControlsGeometry(); - - if (animated) { - _main->showAnimated(bg); + if (_passcodeLock) { + _main->hide(); } else { - _main->activate(); + _main->show(); + updateControlsGeometry(); + if (animated) { + _main->showAnimated(bg); + } else { + _main->activate(); + } + Core::App().checkStartUrl(); } - _main->start(); - fixOrder(); } @@ -663,7 +673,10 @@ void MainWindow::showLogoutConfirmation() { ? &sessionController()->session().account() : nullptr; const auto weak = base::make_weak(account); - const auto callback = crl::guard(weak, [=] { + const auto callback = [=] { + if (account && !weak) { + return; + } if (account && account->sessionExists() && account->session().data().exportInProgress()) { @@ -674,7 +687,7 @@ void MainWindow::showLogoutConfirmation() { } else { Core::App().logout(account); } - }); + }; Ui::show(Box( tr::lng_sure_logout(tr::now), tr::lng_settings_logout(tr::now), diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 5a3987b0c..0f52c1e79 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -543,6 +543,7 @@ void Account::reset() { _cacheBigFileTotalTimeLimit = Database::Settings().totalTimeLimit; _mapChanged = true; writeMap(); + writeMtpData(); crl::async([base = _basePath, names = std::move(names)] { for (const auto &name : names) { diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index 64953f444..7ae4b9199 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -149,9 +149,8 @@ void PasscodeLockWidget::submit() { } const auto passcode = _passcode->text().toUtf8(); - const auto controller = window()->sessionController(); auto &accounts = Core::App().accounts(); - const auto correct = controller + const auto correct = accounts.started() ? accounts.local().checkPasscode(passcode) : (accounts.start(passcode) != Storage::StartResult::IncorrectPasscode);