From 834f6b39711d00477a4e49e3de16a05d55640ddf Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 27 Apr 2022 14:57:24 +0530 Subject: [PATCH 1/5] Upgrade to latest sdk --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ab2e118..3a75bac 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,6 @@ "vite": "^2.7.2" }, "dependencies": { - "hydrogen-view-sdk": "^0.0.10" + "hydrogen-view-sdk": "^0.0.11" } } diff --git a/yarn.lock b/yarn.lock index 77c7a0d..b441e1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From b1a0fa998442db5153af71da9960bab46ed85e37 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 27 Apr 2022 14:57:41 +0530 Subject: [PATCH 2/5] Use named params in Platform --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 91460d5..9c3c83e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 }); From 112c0eacbadc26c56c173f703abe1de48363855f Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 27 Apr 2022 14:58:03 +0530 Subject: [PATCH 3/5] Fix bug --- src/viewmodels/AccountSetupViewModel.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts index 2444ef3..20962a0 100644 --- a/src/viewmodels/AccountSetupViewModel.ts +++ b/src/viewmodels/AccountSetupViewModel.ts @@ -1,3 +1,4 @@ + import { ViewModel, Client, LoadStatus } from "hydrogen-view-sdk"; import { IChatterboxConfig } from "../types/IChatterboxConfig"; import { generatePassword, generateUsername } from "../random"; @@ -25,7 +26,22 @@ 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 + const containsUnsupportedStage = flow.stages.some(stage => !allowedStages.includes(stage)); + if (!containsUnsupportedStage) { + 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") { From a9f0dbdbe2754fb8688d2a167e827e127399ed62 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 27 Apr 2022 15:00:27 +0530 Subject: [PATCH 4/5] Remove newline at top --- src/viewmodels/AccountSetupViewModel.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts index 20962a0..daccd6f 100644 --- a/src/viewmodels/AccountSetupViewModel.ts +++ b/src/viewmodels/AccountSetupViewModel.ts @@ -1,4 +1,3 @@ - import { ViewModel, Client, LoadStatus } from "hydrogen-view-sdk"; import { IChatterboxConfig } from "../types/IChatterboxConfig"; import { generatePassword, generateUsername } from "../random"; From 2de21b3449d3bc37574e74b5b8447090357aea87 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 27 Apr 2022 15:34:02 +0530 Subject: [PATCH 5/5] Also check if token registration stage is present --- src/viewmodels/AccountSetupViewModel.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts index daccd6f..9e46c51 100644 --- a/src/viewmodels/AccountSetupViewModel.ts +++ b/src/viewmodels/AccountSetupViewModel.ts @@ -33,9 +33,11 @@ export class AccountSetupViewModel extends ViewModel { "m.login.dummy" ]; for (const flow of flows) { - // Find the first flow that does not contain any unsupported stages + // 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)); - if (!containsUnsupportedStage) { + const containsTokenStage = flow.stages.includes("m.login.registration_token") || + flow.stages.includes("org.matrix.msc3231.login.registration_token"); + if (!containsUnsupportedStage && containsTokenStage) { return flow; } }