firstStage should be a local variable

This commit is contained in:
RMidhunSuresh 2022-02-01 18:23:41 +05:30
parent 2d4c106542
commit 2f3865d8cc

View File

@ -33,7 +33,6 @@ export type RegistrationResponse = {
export class Registration { export class Registration {
private _hsApi: HomeServerApi; private _hsApi: HomeServerApi;
private _data: RegistrationParameters; private _data: RegistrationParameters;
private _firstStage: BaseRegistrationStage;
constructor(hsApi: HomeServerApi, data: RegistrationParameters) { constructor(hsApi: HomeServerApi, data: RegistrationParameters) {
this._hsApi = hsApi; this._hsApi = hsApi;
@ -47,13 +46,13 @@ export class Registration {
this._initialDeviceDisplayName, this._initialDeviceDisplayName,
undefined, undefined,
this._inhibitLogin).response(); this._inhibitLogin).response();
this.parseStagesFromResponse(response); return this.parseStagesFromResponse(response);
return this._firstStage;
} }
parseStagesFromResponse(response: RegistrationResponse) { parseStagesFromResponse(response: RegistrationResponse): BaseRegistrationStage {
const { session, params } = response; const { session, params } = response;
const flow = response.flows.pop(); const flow = response.flows.pop();
let firstStage: BaseRegistrationStage | undefined;
let lastStage: BaseRegistrationStage; let lastStage: BaseRegistrationStage;
for (const stage of flow.stages) { for (const stage of flow.stages) {
const stageClass = registrationStageFromType(stage); const stageClass = registrationStageFromType(stage);
@ -61,14 +60,15 @@ export class Registration {
throw new Error("Unknown stage"); throw new Error("Unknown stage");
} }
const registrationStage = new stageClass(this._hsApi, this._data, session, params?.[stage]); const registrationStage = new stageClass(this._hsApi, this._data, session, params?.[stage]);
if (!this._firstStage) { if (!firstStage) {
this._firstStage = registrationStage; firstStage = registrationStage;
lastStage = registrationStage; lastStage = registrationStage;
} else { } else {
lastStage!.setNextStage(registrationStage); lastStage!.setNextStage(registrationStage);
lastStage = registrationStage; lastStage = registrationStage;
} }
} }
return firstStage!;
} }
private get _username() { return this._data.username; } private get _username() { return this._data.username; }