From ba27d20b24bd3e6bf39461cac8490c3bad1d9cc8 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 17:19:37 +0100 Subject: [PATCH] only pass platform into Client simplifying the API for SDK --- src/domain/RootViewModel.js | 5 ++--- src/domain/login/LoginViewModel.js | 6 +++--- src/matrix/Client.js | 6 +++--- src/platform/web/main.js | 6 ------ 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/domain/RootViewModel.js b/src/domain/RootViewModel.js index 4541ee22..b754f0ce 100644 --- a/src/domain/RootViewModel.js +++ b/src/domain/RootViewModel.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import {Client} from "../matrix/Client.js"; import {SessionViewModel} from "./session/SessionViewModel.js"; import {SessionLoadViewModel} from "./SessionLoadViewModel.js"; import {LoginViewModel} from "./login/LoginViewModel.js"; @@ -23,7 +24,6 @@ import {ViewModel} from "./ViewModel.js"; export class RootViewModel extends ViewModel { constructor(options) { super(options); - this._createClient = options.createClient; this._error = null; this._sessionPickerViewModel = null; this._sessionLoadViewModel = null; @@ -106,7 +106,6 @@ export class RootViewModel extends ViewModel { this._setSection(() => { this._loginViewModel = new LoginViewModel(this.childOptions({ defaultHomeserver: this.platform.config["defaultHomeServer"], - createClient: this._createClient, ready: client => { // we don't want to load the session container again, // but we also want the change of screen to go through the navigation @@ -132,7 +131,7 @@ export class RootViewModel extends ViewModel { } _showSessionLoader(sessionId) { - const client = this._createClient(); + const client = new Client(this.platform); client.startWithExistingSession(sessionId); this._setSection(() => { this._sessionLoadViewModel = new SessionLoadViewModel(this.childOptions({ diff --git a/src/domain/login/LoginViewModel.js b/src/domain/login/LoginViewModel.js index c44b34f3..b91df4cc 100644 --- a/src/domain/login/LoginViewModel.js +++ b/src/domain/login/LoginViewModel.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import {Client} from "../../matrix/Client.js"; import {ViewModel} from "../ViewModel.js"; import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js"; import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js"; @@ -24,11 +25,10 @@ import {SessionLoadViewModel} from "../SessionLoadViewModel.js"; export class LoginViewModel extends ViewModel { constructor(options) { super(options); - const {ready, defaultHomeserver, createClient, loginToken} = options; - this._createClient = createClient; + const {ready, defaultHomeserver, loginToken} = options; this._ready = ready; this._loginToken = loginToken; - this._client = this._createClient(); + this._client = new Client(this.platform); this._loginOptions = null; this._passwordLoginViewModel = null; this._startSSOLoginViewModel = null; diff --git a/src/matrix/Client.js b/src/matrix/Client.js index ec4e041f..5f6d5ea1 100644 --- a/src/matrix/Client.js +++ b/src/matrix/Client.js @@ -52,7 +52,7 @@ export const LoginFailure = createEnum( ); export class Client { - constructor({platform, olmPromise, workerPromise}) { + constructor(platform) { this._platform = platform; this._sessionStartedByReconnector = false; this._status = new ObservableValue(LoadStatus.NotLoading); @@ -64,8 +64,8 @@ export class Client { this._sessionId = null; this._storage = null; this._requestScheduler = null; - this._olmPromise = olmPromise; - this._workerPromise = workerPromise; + this._olmPromise = platform.loadOlm(); + this._workerPromise = platform.loadOlmWorker(); this._accountSetup = undefined; } diff --git a/src/platform/web/main.js b/src/platform/web/main.js index 63e9a650..eb71244a 100644 --- a/src/platform/web/main.js +++ b/src/platform/web/main.js @@ -37,13 +37,7 @@ export async function main(platform) { platform.setNavigation(navigation); const urlRouter = createRouter({navigation, history: platform.history}); urlRouter.attach(); - const olmPromise = platform.loadOlm(); - const workerPromise = platform.loadOlmWorker(); - const vm = new RootViewModel({ - createClient: () => { - return new Client({platform, olmPromise, workerPromise}); - }, platform, // the only public interface of the router is to create urls, // so we call it that in the view models