Skip to content

Commit

Permalink
Merge pull request #33 from vector-im/fix-28
Browse files Browse the repository at this point in the history
Select first flow that contains no unsupported stage during registration
  • Loading branch information
MidhunSureshR authored Apr 27, 2022
2 parents f15d68f + 2de21b3 commit 3599f15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"vite": "^2.7.2"
},
"dependencies": {
"hydrogen-view-sdk": "^0.0.10"
"hydrogen-view-sdk": "^0.0.11"
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main() {
}
root.className = "hydrogen";
const config = await fetchConfig();
const platform = new Platform(root, assetPaths, {}, { development: import.meta.env.DEV });
const platform = new Platform({container: root, assetPaths, config: {}, options: { development: import.meta.env.DEV }});
const navigation = new Navigation(allowsChild);
platform.setNavigation(navigation);
const urlRouter = createRouter({ navigation, history: platform.history });
Expand Down
19 changes: 18 additions & 1 deletion src/viewmodels/AccountSetupViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ export class AccountSetupViewModel extends ViewModel {
for (let i = 0; i < maxAttempts; ++i) {
try {
const username = `${this._config.username_prefix}-${generateUsername(10)}`;
this._registration = await this._client.startRegistration(this._homeserver, username, this._password, "Chatterbox");
const flowSelector = (flows) => {
const allowedStages = [
"m.login.registration_token",
"org.matrix.msc3231.login.registration_token",
"m.login.terms",
"m.login.dummy"
];
for (const flow of flows) {
// Find the first flow that does not contain any unsupported stages but contains Token registration stage.
const containsUnsupportedStage = flow.stages.some(stage => !allowedStages.includes(stage));
const containsTokenStage = flow.stages.includes("m.login.registration_token") ||
flow.stages.includes("org.matrix.msc3231.login.registration_token");
if (!containsUnsupportedStage && containsTokenStage) {
return flow;
}
}
}
this._registration = await this._client.startRegistration(this._homeserver, username, this._password, "Chatterbox", flowSelector);
this._startStage = await this._registration.start();
let stage = this._startStage;
while (stage && stage.type !== "m.login.terms") {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

hydrogen-view-sdk@^0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.10.tgz#be0c729db67e1d1511b7fa32aa101fd889ec9cdc"
integrity sha512-7Ni7ui0mQzKbz6noGDyS1ceIKjU5sjoyX6+2a5dk0nXwttrQYXJbrgblCWC3nIljQPbW+09o+t9BFE0OuBHDPw==
hydrogen-view-sdk@^0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/hydrogen-view-sdk/-/hydrogen-view-sdk-0.0.11.tgz#01c224b6bfd2f89d98d2f9e1816cd962411b9982"
integrity sha512-a7z9FEa078MNuSAtNhoJ82ircGTGVvHnRsl+BvDQaHvgVb01/ff2r81KdIqdqVwXzC9r2McqjTNPCwEKh2Xauw==
dependencies:
"@matrix-org/olm" "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz"
another-json "^0.2.0"
Expand Down

0 comments on commit 3599f15

Please sign in to comment.