2021-08-15 16:21:00 +05:30
|
|
|
/*
|
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {ViewModel} from "../ViewModel.js";
|
2021-08-15 16:36:03 +05:30
|
|
|
import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
|
2021-08-15 16:21:00 +05:30
|
|
|
|
2021-08-17 17:01:03 +05:30
|
|
|
export class CompleteSSOLoginViewModel extends ViewModel {
|
2021-08-15 16:21:00 +05:30
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
const {
|
|
|
|
loginToken,
|
|
|
|
sessionContainer,
|
|
|
|
ready,
|
|
|
|
} = options;
|
|
|
|
this._loginToken = loginToken;
|
|
|
|
this._ready = ready;
|
|
|
|
this._sessionContainer = sessionContainer;
|
|
|
|
this._loadViewModelSubscription = null;
|
|
|
|
this._loadViewModel = null;
|
2021-08-15 16:36:03 +05:30
|
|
|
this.performSSOLoginCompletion();
|
2021-08-15 16:21:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get loadViewModel() { return this._loadViewModel; }
|
|
|
|
|
2021-08-15 16:36:03 +05:30
|
|
|
async performSSOLoginCompletion() {
|
|
|
|
if (!this._loginToken) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-17 14:20:48 +05:30
|
|
|
const homeserver = await this.platform.settingsStorage.getString("sso_ongoing_login_homeserver");
|
2021-08-15 16:36:03 +05:30
|
|
|
const loginOptions = await this._sessionContainer.queryLogin(homeserver);
|
2021-08-17 20:54:24 +05:30
|
|
|
if (!loginOptions.token) {
|
|
|
|
const path = this.navigation.pathFrom([this.navigation.segment("session")]);
|
|
|
|
this.navigation.applyPath(path);
|
|
|
|
return;
|
|
|
|
}
|
2021-08-15 16:36:03 +05:30
|
|
|
this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription);
|
|
|
|
if (this._loadViewModel) {
|
|
|
|
this._loadViewModel = this.disposeTracked(this._loadViewModel);
|
|
|
|
}
|
|
|
|
this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions({
|
|
|
|
createAndStartSessionContainer: async () => {
|
2021-08-17 20:54:24 +05:30
|
|
|
this._sessionContainer.startWithLogin(loginOptions.token(this._loginToken));
|
2021-08-15 16:36:03 +05:30
|
|
|
return this._sessionContainer;
|
|
|
|
},
|
|
|
|
ready: this._ready,
|
|
|
|
homeserver,
|
|
|
|
})));
|
|
|
|
this._loadViewModel.start();
|
|
|
|
this.emitChange("loadViewModel");
|
|
|
|
this._loadViewModelSubscription = this.track(this._loadViewModel.disposableOn("change", () => {
|
|
|
|
if (!this._loadViewModel.loading) {
|
|
|
|
this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription);
|
|
|
|
}
|
|
|
|
this.emitChange("isBusy");
|
|
|
|
}));
|
|
|
|
}
|
2021-08-15 16:21:00 +05:30
|
|
|
}
|