From 0af27fc8dd963a343bb6925a4c77d08274bf4ba4 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 1 Aug 2021 20:35:04 +0530 Subject: [PATCH] Move normalizeHomeserver to LoginViewModel Signed-off-by: RMidhunSuresh --- src/domain/LoginViewModel.js | 1 + src/matrix/SessionContainer.js | 14 ++------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/domain/LoginViewModel.js b/src/domain/LoginViewModel.js index d75a715e..5e0702da 100644 --- a/src/domain/LoginViewModel.js +++ b/src/domain/LoginViewModel.js @@ -72,6 +72,7 @@ export class LoginViewModel extends ViewModel { } async login(username, password, homeserver) { + homeserver = normalizeHomeserver(homeserver); this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription); if (this._loadViewModel) { this._loadViewModel = this.disposeTracked(this._loadViewModel); diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 85aa979c..4511d982 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -43,14 +43,6 @@ export const LoginFailure = createEnum( "Unknown", ); -function normalizeHomeserver(homeServer) { - try { - return new URL(homeServer).origin; - } catch (err) { - return new URL(`https://${homeServer}`).origin; - } -} - export class SessionContainer { constructor({platform, olmPromise, workerPromise}) { this._platform = platform; @@ -113,7 +105,6 @@ export class SessionContainer { } async queryLogin(homeServer) { - homeServer = normalizeHomeserver(homeServer); const hsApi = new HomeServerApi({homeServer, request: this._platform.request}); const response = await hsApi.queryLogin().response(); return this.parseLoginOptions(response, homeServer); @@ -129,15 +120,14 @@ export class SessionContainer { let sessionInfo; try { const request = this._platform.request; - const homeServer = normalizeHomeserver(loginMethod.homeServer); - const hsApi = new HomeServerApi({homeServer, request}); + const hsApi = new HomeServerApi({homeServer: loginMethod.homeServer, request}); const loginData = await loginMethod.login(hsApi, "Hydrogen", log); const sessionId = this.createNewSessionId(); sessionInfo = { id: sessionId, deviceId: loginData.device_id, userId: loginData.user_id, - homeServer: homeServer, + homeServer: loginMethod.homeServer, accessToken: loginData.access_token, lastUsed: clock.now() };