diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index a2cce5a84..1aa3c6580 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -111,6 +111,28 @@ int PinnedDialogsCount( return result; } +// Duplicated code from window/window_main_menu.cpp +[[nodiscard]] std::vector> 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 a, + not_null 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 struct InnerWidget::CollapsedRow { @@ -4087,8 +4109,8 @@ void InnerWidget::setupShortcuts() { } } - const auto accounts = &Core::App().domain().accounts(); - if (const auto accountsCount = int(accounts->size())) { + const auto accounts = OrderedAccounts(); + if (const auto accountsCount = int(accounts.size())) { auto &&accountShortcuts = ranges::views::zip( Shortcuts::kShowAccount, ranges::views::ints(0, ranges::unreachable)); @@ -4099,7 +4121,7 @@ void InnerWidget::setupShortcuts() { : std::clamp(index, 0, accountsCount - 1); request->check(command) && request->handle([=] { if (select <= accountsCount) { - const auto account = (*accounts)[select].account.get(); + const auto account = accounts[select]; if (account != &Core::App().domain().active()) { Core::App().domain().maybeActivate(account); }