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/<id> and just creating a client without fully loading it
to log out. This way sync is already not running anymore.
This commit is contained in:
Bruno Windels 2022-01-17 16:29:01 +01:00
parent 164d72830f
commit c6c1d3b3d8
2 changed files with 13 additions and 7 deletions

View File

@ -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);
});

View File

@ -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