This commit is contained in:
blankie 2024-09-27 20:30:43 +08:00 committed by GitHub
commit b60dfd92d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,6 +111,28 @@ int PinnedDialogsCount(
return result; return result;
} }
// Duplicated code from window/window_main_menu.cpp
[[nodiscard]] std::vector<not_null<Main::Account*>> OrderedAccounts() {
const auto order = Core::App().settings().accountsOrder();
auto accounts = ranges::views::all(
Core::App().domain().accounts()
) | ranges::views::transform([](const Main::Domain::AccountWithIndex &a) {
return not_null{ a.account.get() };
}) | ranges::to_vector;
ranges::stable_sort(accounts, [&](
not_null<Main::Account*> a,
not_null<Main::Account*> b) {
const auto aIt = a->sessionExists()
? ranges::find(order, a->session().uniqueId())
: end(order);
const auto bIt = b->sessionExists()
? ranges::find(order, b->session().uniqueId())
: end(order);
return aIt < bIt;
});
return accounts;
}
} // namespace } // namespace
struct InnerWidget::CollapsedRow { struct InnerWidget::CollapsedRow {
@ -4087,8 +4109,8 @@ void InnerWidget::setupShortcuts() {
} }
} }
const auto accounts = &Core::App().domain().accounts(); const auto accounts = OrderedAccounts();
if (const auto accountsCount = int(accounts->size())) { if (const auto accountsCount = int(accounts.size())) {
auto &&accountShortcuts = ranges::views::zip( auto &&accountShortcuts = ranges::views::zip(
Shortcuts::kShowAccount, Shortcuts::kShowAccount,
ranges::views::ints(0, ranges::unreachable)); ranges::views::ints(0, ranges::unreachable));
@ -4099,7 +4121,7 @@ void InnerWidget::setupShortcuts() {
: std::clamp(index, 0, accountsCount - 1); : std::clamp(index, 0, accountsCount - 1);
request->check(command) && request->handle([=] { request->check(command) && request->handle([=] {
if (select <= accountsCount) { if (select <= accountsCount) {
const auto account = (*accounts)[select].account.get(); const auto account = accounts[select];
if (account != &Core::App().domain().active()) { if (account != &Core::App().domain().active()) {
Core::App().domain().maybeActivate(account); Core::App().domain().maybeActivate(account);
} }