Do not override childOptions

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-20 15:42:43 +05:30
parent bdc860eb79
commit dadeb7f3e5
3 changed files with 36 additions and 25 deletions

View File

@ -23,12 +23,10 @@ export class CompleteSSOLoginViewModel extends ViewModel {
const {
loginToken,
sessionContainer,
ready,
attemptLogin,
showError,
} = options;
this._loginToken = loginToken;
this._ready = ready;
this._sessionContainer = sessionContainer;
this._attemptLogin = attemptLogin;
this._showError = showError;
@ -53,7 +51,7 @@ export class CompleteSSOLoginViewModel extends ViewModel {
error = `Your login-token is invalid.`;
break;
case LoginFailure.Connection:
error = `Can't connect to ${this._homeserver}.`;
error = `Can't connect to ${homeserver}.`;
break;
case LoginFailure.Unknown:
error = `Something went wrong while checking your login-token.`;

View File

@ -55,7 +55,14 @@ export class LoginViewModel extends ViewModel {
async _createViewModels(homeserver) {
if (this._loginToken) {
this._hideHomeserver = true;
this._completeSSOLoginViewModel = this.track(new CompleteSSOLoginViewModel(this.childOptions({loginToken: this._loginToken})));
this._completeSSOLoginViewModel = this.track(new CompleteSSOLoginViewModel(
this.childOptions(
{
sessionContainer: this._sessionContainer,
attemptLogin: loginMethod => this.attemptLogin(loginMethod),
showError: message => this.showError(message),
loginToken: this._loginToken
})));
this.emitChange("completeSSOLoginViewModel");
}
else {
@ -80,12 +87,23 @@ export class LoginViewModel extends ViewModel {
}
_showPasswordLogin() {
this._passwordLoginViewModel = this.track(new PasswordLoginViewModel(this.childOptions()));
this._passwordLoginViewModel = this.track(new PasswordLoginViewModel(
this.childOptions({
sessionContainer: this._sessionContainer,
loginOptions: this._loginOptions,
homeserver: this._homeserver,
attemptLogin: loginMethod => this.attemptLogin(loginMethod),
showError: message => this.showError(message)
})));
this.emitChange("passwordLoginViewModel");
}
_showSSOLogin() {
this._startSSOLoginViewModel = this.track(new StartSSOLoginViewModel(this.childOptions()));
this._startSSOLoginViewModel = this.track(
new StartSSOLoginViewModel(
this.childOptions({ loginOptions: this._loginOptions, homeserver: this._homeserver })
)
);
this.emitChange("startSSOLoginViewModel");
}
@ -122,7 +140,19 @@ export class LoginViewModel extends ViewModel {
if (this._loadViewModel) {
this._loadViewModel = this.disposeTracked(this._loadViewModel);
}
this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions()));
this._loadViewModel = this.track(
new SessionLoadViewModel(
this.childOptions({
ready: (sessionContainer) => {
// make sure we don't delete the session in dispose when navigating away
this._sessionContainer = null;
this._ready(sessionContainer);
},
sessionContainer: this._sessionContainer,
homeserver: this._homeserver
})
)
);
this._loadViewModel.start();
this.emitChange("loadViewModel");
this._loadViewModelSubscription = this.track(
@ -148,22 +178,6 @@ export class LoginViewModel extends ViewModel {
this._createViewModels(newHomeserver);
}
childOptions(options = {}) {
return {
...super.childOptions(options),
ready: sessionContainer => {
// make sure we don't delete the session in dispose when navigating away
this._sessionContainer = null;
this._ready(sessionContainer);
},
sessionContainer: this._sessionContainer,
loginOptions: this._loginOptions,
homeserver: this._homeserver,
attemptLogin: loginMethod => this.attemptLogin(loginMethod),
showError: message => this.showError(message)
}
}
dispose() {
super.dispose();
if (this._sessionContainer) {

View File

@ -20,8 +20,7 @@ import {LoginFailure} from "../../matrix/SessionContainer.js";
export class PasswordLoginViewModel extends ViewModel {
constructor(options) {
super(options);
const {ready, loginOptions, sessionContainer, homeserver, attemptLogin, showError} = options;
this._ready = ready;
const {loginOptions, sessionContainer, homeserver, attemptLogin, showError} = options;
this._sessionContainer = sessionContainer;
this._loginOptions = loginOptions;
this._attemptLogin = attemptLogin;