Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stopClient parameter to MatrixClient::logout #2367

Merged
merged 2 commits into from
May 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* clean shutdown.
*/
public stopClient() {
if (!this.clientRunning) return; // already stopped

logger.log('stopping MatrixClient');

this.clientRunning = false;
Expand Down Expand Up @@ -7067,9 +7069,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* it is up to the caller to either reset or destroy the MatrixClient after
* this method succeeds.
* @param {module:client.callback} callback Optional.
* @param {boolean} stopClient whether to stop the client before calling /logout to prevent invalid token errors.
* @return {Promise} Resolves: On success, the empty object
*/
public async logout(callback?: Callback): Promise<{}> {
public async logout(callback?: Callback, stopClient = false): Promise<{}> {
if (this.crypto?.backupManager?.getKeyBackupEnabled()) {
try {
while (await this.crypto.backupManager.backupPendingKeys(200) > 0);
Expand All @@ -7080,6 +7083,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
);
}
}

if (stopClient) {
this.stopClient();
}

return this.http.authedRequest(
callback, Method.Post, '/logout',
);
Expand Down