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:
parent
164d72830f
commit
c6c1d3b3d8
2 changed files with 13 additions and 7 deletions
|
@ -386,10 +386,21 @@ export class Client {
|
||||||
return !this._reconnector;
|
return !this._reconnector;
|
||||||
}
|
}
|
||||||
|
|
||||||
logout() {
|
startLogout(sessionId) {
|
||||||
return this._platform.logger.run("logout", async log => {
|
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 {
|
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) {}
|
} catch (err) {}
|
||||||
await this.deleteSession(log);
|
await this.deleteSession(log);
|
||||||
});
|
});
|
||||||
|
|
|
@ -109,11 +109,6 @@ export class Session {
|
||||||
return this._sessionInfo.userId;
|
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
|
// called once this._e2eeAccount is assigned
|
||||||
_setupEncryption() {
|
_setupEncryption() {
|
||||||
// TODO: this should all go in a wrapper in e2ee/ that is bootstrapped by passing in the account
|
// TODO: this should all go in a wrapper in e2ee/ that is bootstrapped by passing in the account
|
||||||
|
|
Reference in a new issue