From f713585f171dca6e0ca19535756d721437d914c5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 23 Jan 2023 10:17:51 +0400 Subject: [PATCH] Remove non-authed account only without a window. --- Telegram/SourceFiles/main/main_domain.cpp | 33 +++++++++++++---------- Telegram/SourceFiles/main/main_domain.h | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/main/main_domain.cpp b/Telegram/SourceFiles/main/main_domain.cpp index 8dbe9fd4a..fa58bb795 100644 --- a/Telegram/SourceFiles/main/main_domain.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "export/export_settings.h" #include "window/notifications_manager.h" +#include "window/window_controller.h" #include "data/data_peer_values.h" // Data::AmPremiumValue. namespace Main { @@ -340,27 +341,32 @@ void Domain::watchSession(not_null account) { return !session; }) | rpl::start_with_next([=] { scheduleUpdateUnreadBadge(); - if (account == _active.current()) { - activateAuthedAccount(); - } + closeAccountWindows(account); crl::on_main(&Core::App(), [=] { removeRedundantAccounts(); }); }, account->lifetime()); } -void Domain::activateAuthedAccount() { - Expects(started()); - - if (_active.current()->sessionExists()) { - return; - } +void Domain::closeAccountWindows(not_null account) { + auto another = (Main::Account*)nullptr; for (auto i = _accounts.begin(); i != _accounts.end(); ++i) { - if (i->account->sessionExists()) { - activate(i->account.get()); - return; + const auto other = i->account.get(); + if (other == account) { + continue; + } else if (Core::App().separateWindowForAccount(other)) { + const auto that = Core::App().separateWindowForAccount(account); + if (that) { + that->close(); + } + } else if (!another + || (other->sessionExists() && !another->sessionExists())) { + another = other; } } + if (another) { + activate(another); + } } bool Domain::removePasscodeIfEmpty() { @@ -384,9 +390,8 @@ void Domain::removeRedundantAccounts() { Expects(started()); const auto was = _accounts.size(); - activateAuthedAccount(); for (auto i = _accounts.begin(); i != _accounts.end();) { - if (i->account.get() == _active.current() + if (Core::App().separateWindowForAccount(i->account.get()) || i->account->sessionExists()) { ++i; continue; diff --git a/Telegram/SourceFiles/main/main_domain.h b/Telegram/SourceFiles/main/main_domain.h index 5f4dabe00..62933e4fa 100644 --- a/Telegram/SourceFiles/main/main_domain.h +++ b/Telegram/SourceFiles/main/main_domain.h @@ -79,7 +79,7 @@ public: private: void activateAfterStarting(); - void activateAuthedAccount(); + void closeAccountWindows(not_null account); bool removePasscodeIfEmpty(); void removeRedundantAccounts(); void watchSession(not_null account);