Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix account hotkey when accounts are reordered #333

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ int PinnedDialogsCount(
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

struct InnerWidget::CollapsedRow {
Expand Down Expand Up @@ -3174,8 +3196,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));
Expand All @@ -3186,7 +3208,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);
}
Expand Down