Move normalizeHomeserver to LoginViewModel

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-01 20:35:04 +05:30
parent 2c953e361d
commit 0af27fc8dd
2 changed files with 3 additions and 12 deletions

View File

@ -72,6 +72,7 @@ export class LoginViewModel extends ViewModel {
} }
async login(username, password, homeserver) { async login(username, password, homeserver) {
homeserver = normalizeHomeserver(homeserver);
this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription); this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription);
if (this._loadViewModel) { if (this._loadViewModel) {
this._loadViewModel = this.disposeTracked(this._loadViewModel); this._loadViewModel = this.disposeTracked(this._loadViewModel);

View File

@ -43,14 +43,6 @@ export const LoginFailure = createEnum(
"Unknown", "Unknown",
); );
function normalizeHomeserver(homeServer) {
try {
return new URL(homeServer).origin;
} catch (err) {
return new URL(`https://${homeServer}`).origin;
}
}
export class SessionContainer { export class SessionContainer {
constructor({platform, olmPromise, workerPromise}) { constructor({platform, olmPromise, workerPromise}) {
this._platform = platform; this._platform = platform;
@ -113,7 +105,6 @@ export class SessionContainer {
} }
async queryLogin(homeServer) { async queryLogin(homeServer) {
homeServer = normalizeHomeserver(homeServer);
const hsApi = new HomeServerApi({homeServer, request: this._platform.request}); const hsApi = new HomeServerApi({homeServer, request: this._platform.request});
const response = await hsApi.queryLogin().response(); const response = await hsApi.queryLogin().response();
return this.parseLoginOptions(response, homeServer); return this.parseLoginOptions(response, homeServer);
@ -129,15 +120,14 @@ export class SessionContainer {
let sessionInfo; let sessionInfo;
try { try {
const request = this._platform.request; const request = this._platform.request;
const homeServer = normalizeHomeserver(loginMethod.homeServer); const hsApi = new HomeServerApi({homeServer: loginMethod.homeServer, request});
const hsApi = new HomeServerApi({homeServer, request});
const loginData = await loginMethod.login(hsApi, "Hydrogen", log); const loginData = await loginMethod.login(hsApi, "Hydrogen", log);
const sessionId = this.createNewSessionId(); const sessionId = this.createNewSessionId();
sessionInfo = { sessionInfo = {
id: sessionId, id: sessionId,
deviceId: loginData.device_id, deviceId: loginData.device_id,
userId: loginData.user_id, userId: loginData.user_id,
homeServer: homeServer, homeServer: loginMethod.homeServer,
accessToken: loginData.access_token, accessToken: loginData.access_token,
lastUsed: clock.now() lastUsed: clock.now()
}; };