Skip to content

Commit 6f445ca

Browse files
authored
Add stopClient parameter to MatrixClient::logout (#2367)
* Add stopClient parameter to MatrixClient::logout * Add short-circuit
1 parent e2af78d commit 6f445ca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
12041204
* clean shutdown.
12051205
*/
12061206
public stopClient() {
1207+
if (!this.clientRunning) return; // already stopped
1208+
12071209
logger.log('stopping MatrixClient');
12081210

12091211
this.clientRunning = false;
@@ -7067,9 +7069,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
70677069
* it is up to the caller to either reset or destroy the MatrixClient after
70687070
* this method succeeds.
70697071
* @param {module:client.callback} callback Optional.
7072+
* @param {boolean} stopClient whether to stop the client before calling /logout to prevent invalid token errors.
70707073
* @return {Promise} Resolves: On success, the empty object
70717074
*/
7072-
public async logout(callback?: Callback): Promise<{}> {
7075+
public async logout(callback?: Callback, stopClient = false): Promise<{}> {
70737076
if (this.crypto?.backupManager?.getKeyBackupEnabled()) {
70747077
try {
70757078
while (await this.crypto.backupManager.backupPendingKeys(200) > 0);
@@ -7080,6 +7083,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
70807083
);
70817084
}
70827085
}
7086+
7087+
if (stopClient) {
7088+
this.stopClient();
7089+
}
7090+
70837091
return this.http.authedRequest(
70847092
callback, Method.Post, '/logout',
70857093
);

0 commit comments

Comments
 (0)