diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-13 01:17:25 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-13 01:17:51 +0100 |
commit | b19d9caba69c5408accdd7de8e061300ddb427e2 (patch) | |
tree | 166997c4f700b46c40b1cdaaf496fac61246f05c /src/ui | |
parent | Merge pull request #986 from tastytea/use-standard-buttons (diff) | |
download | nheko-b19d9caba69c5408accdd7de8e061300ddb427e2.tar.xz |
Sort known UIA flows first
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/UIA.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ui/UIA.cpp b/src/ui/UIA.cpp index 9f28ca6a..7c6e440c 100644 --- a/src/ui/UIA.cpp +++ b/src/ui/UIA.cpp @@ -60,6 +60,36 @@ UIA::genericHandler(QString context) return; } + // sort flows with known stages first + std::sort( + flows.begin(), + flows.end(), + [](const mtx::user_interactive::Flow &a, const mtx::user_interactive::Flow &b) { + auto calcWeight = [](const mtx::user_interactive::Flow &f) { + using namespace mtx::user_interactive::auth_types; + const static std::map<std::string_view, int> weights{ + {mtx::user_interactive::auth_types::password, 0}, + {mtx::user_interactive::auth_types::email_identity, 0}, + {mtx::user_interactive::auth_types::msisdn, 0}, + {mtx::user_interactive::auth_types::dummy, 0}, + {mtx::user_interactive::auth_types::registration_token, 0}, + // recaptcha is known, but we'd like to avoid it, because it calls out to + // the browser + {mtx::user_interactive::auth_types::recaptcha, 1}, + }; + int weight = 0; + for (const auto &s : f.stages) { + if (!weights.count(s)) + weight += 3; + else + weight += weights.at(s); + } + return weight; + }; + + return calcWeight(a) < calcWeight(b); + }); + auto current_stage = flows.front().stages.at(u.completed.size()); if (current_stage == mtx::user_interactive::auth_types::password) { |