From c6c1d3b3d8b7a1b250dedfeb9ab3274eea6319b1 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 17 Jan 2022 16:29:01 +0100 Subject: [PATCH] refactor logout in client so we don't need a fully loaded session instead, we pass the session id in this will make it easier to first dispose the client when leaving the /session/ and just creating a client without fully loading it to log out. This way sync is already not running anymore. --- src/matrix/Client.js | 15 +++++++++++++-- src/matrix/Session.js | 5 ----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/matrix/Client.js b/src/matrix/Client.js index 5f6d5ea1..f070d24c 100644 --- a/src/matrix/Client.js +++ b/src/matrix/Client.js @@ -386,10 +386,21 @@ export class Client { return !this._reconnector; } - logout() { + startLogout(sessionId) { return this._platform.logger.run("logout", async log => { + this._sessionId = sessionId; + log.set("id", this._sessionId); + const sessionInfo = await this._platform.sessionInfoStorage.get(this._sessionId); + if (!sessionInfo) { + throw new Error(`Could not find session for id ${this._sessionId}`); + } try { - await this._session?.logout(log); + const hsApi = new HomeServerApi({ + homeserver: sessionInfo.homeServer, + accessToken: sessionInfo.accessToken, + request: this._platform.request + }); + await hsApi.logout({log}).response(); } catch (err) {} await this.deleteSession(log); }); diff --git a/src/matrix/Session.js b/src/matrix/Session.js index ddb3fdb5..8ccc71cc 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -109,11 +109,6 @@ export class Session { return this._sessionInfo.userId; } - /** @internal call Client.logout instead */ - async logout(log = undefined) { - await this._hsApi.logout({log}).response(); - } - // called once this._e2eeAccount is assigned _setupEncryption() { // TODO: this should all go in a wrapper in e2ee/ that is bootstrapped by passing in the account