Pass in params to BaseRegistrationStage

This commit is contained in:
RMidhunSuresh 2021-12-27 12:54:54 +05:30
parent a59b67ec45
commit 18e2fc1089
2 changed files with 5 additions and 4 deletions

View File

@ -34,7 +34,6 @@ export class Registration {
private _hsApi: HomeServerApi; private _hsApi: HomeServerApi;
private _data: RegistrationParameters; private _data: RegistrationParameters;
private _firstStage: BaseRegistrationStage; private _firstStage: BaseRegistrationStage;
private _session: string;
constructor(hsApi: HomeServerApi, data: RegistrationParameters) { constructor(hsApi: HomeServerApi, data: RegistrationParameters) {
this._hsApi = hsApi; this._hsApi = hsApi;
@ -58,7 +57,7 @@ export class Registration {
} }
parseStagesFromResponse(response: RegistrationResponse) { parseStagesFromResponse(response: RegistrationResponse) {
this._session = response.session; const { session, params } = response;
const flow = response.flows.pop(); const flow = response.flows.pop();
let lastStage: BaseRegistrationStage; let lastStage: BaseRegistrationStage;
for (const stage of flow.stages) { for (const stage of flow.stages) {
@ -66,7 +65,7 @@ export class Registration {
if (!stageClass) { if (!stageClass) {
throw new Error("Unknown stage"); throw new Error("Unknown stage");
} }
const registrationStage = new stageClass(this._hsApi, this._data, this._session); const registrationStage = new stageClass(this._hsApi, this._data, session, params?.[stage]);
if (!this._firstStage) { if (!this._firstStage) {
this._firstStage = registrationStage; this._firstStage = registrationStage;
lastStage = registrationStage; lastStage = registrationStage;

View File

@ -26,11 +26,13 @@ export abstract class BaseRegistrationStage {
protected _registrationData: RegistrationParameters; protected _registrationData: RegistrationParameters;
protected _session: string; protected _session: string;
protected _nextStage: BaseRegistrationStage; protected _nextStage: BaseRegistrationStage;
protected _params?: Record<string, any>
constructor(hsApi: HomeServerApi, registrationData: RegistrationParameters, session: string) { constructor(hsApi: HomeServerApi, registrationData: RegistrationParameters, session: string, params?: Record<string, any>) {
this._hsApi = hsApi; this._hsApi = hsApi;
this._registrationData = registrationData; this._registrationData = registrationData;
this._session = session; this._session = session;
this._params = params;
} }
/** /**