1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Add MatrixClient.clearStores

- to clear both sets of storage on logout
This commit is contained in:
Richard van der Hoff
2017-05-31 17:22:07 +01:00
parent 716d098361
commit ef03b708a8
3 changed files with 54 additions and 1 deletions

View File

@@ -156,8 +156,9 @@ function MatrixClient(opts) {
this._notifTimelineSet = null;
this._crypto = null;
this._cryptoStore = opts.cryptoStore;
if (CRYPTO_ENABLED && Boolean(opts.sessionStore) &&
Boolean(opts.cryptoStore) &&
Boolean(this._cryptoStore) &&
userId !== null && this.deviceId !== null) {
this._crypto = new Crypto(
this, this,
@@ -173,6 +174,25 @@ function MatrixClient(opts) {
utils.inherits(MatrixClient, EventEmitter);
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
/**
* Clear any data out of the persistent stores used by the client.
*
* @returns {Promise} Promise which resolves when the stores have been cleared.
*/
MatrixClient.prototype.clearStores = function() {
if (this._clientRunning) {
throw new Error("Cannot clear stores while client is running");
}
const promises = [];
promises.push(this.store.deleteAllData());
if (this._cryptoStore) {
promises.push(this._cryptoStore.deleteAllData());
}
return q.all(promises);
};
/**
* Get the user-id of the logged-in user
*