You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Add MatrixClient.clearStores
- to clear both sets of storage on logout
This commit is contained in:
@@ -156,8 +156,9 @@ function MatrixClient(opts) {
|
|||||||
this._notifTimelineSet = null;
|
this._notifTimelineSet = null;
|
||||||
|
|
||||||
this._crypto = null;
|
this._crypto = null;
|
||||||
|
this._cryptoStore = opts.cryptoStore;
|
||||||
if (CRYPTO_ENABLED && Boolean(opts.sessionStore) &&
|
if (CRYPTO_ENABLED && Boolean(opts.sessionStore) &&
|
||||||
Boolean(opts.cryptoStore) &&
|
Boolean(this._cryptoStore) &&
|
||||||
userId !== null && this.deviceId !== null) {
|
userId !== null && this.deviceId !== null) {
|
||||||
this._crypto = new Crypto(
|
this._crypto = new Crypto(
|
||||||
this, this,
|
this, this,
|
||||||
@@ -173,6 +174,25 @@ function MatrixClient(opts) {
|
|||||||
utils.inherits(MatrixClient, EventEmitter);
|
utils.inherits(MatrixClient, EventEmitter);
|
||||||
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
|
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
|
* Get the user-id of the logged-in user
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -88,6 +88,28 @@ export default class IndexedDBCryptoStore {
|
|||||||
});
|
});
|
||||||
return this._dbPromise;
|
return this._dbPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all data from this store.
|
||||||
|
*
|
||||||
|
* @returns {Promise} resolves when the store has been cleared.
|
||||||
|
*/
|
||||||
|
deleteAllData() {
|
||||||
|
return new q.Promise((resolve, reject) => {
|
||||||
|
console.log(`Removing indexeddb instance: ${this._dbName}`);
|
||||||
|
const req = this._indexedDB.deleteDatabase(this._dbName);
|
||||||
|
req.onerror = (ev) => {
|
||||||
|
reject(new Error(
|
||||||
|
"unable to delete indexeddb: " + ev.target.error,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
req.onsuccess = () => {
|
||||||
|
console.log(`Removed indexeddb instance: ${this._dbName}`);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDatabase(db) {
|
function createDatabase(db) {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import q from 'q';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal module. in-memory storage for e2e.
|
* Internal module. in-memory storage for e2e.
|
||||||
*
|
*
|
||||||
@@ -26,4 +28,13 @@ limitations under the License.
|
|||||||
export default class MemoryCryptoStore {
|
export default class MemoryCryptoStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all data from this store.
|
||||||
|
*
|
||||||
|
* @returns {Promise} Promise which resolves when the store has been cleared.
|
||||||
|
*/
|
||||||
|
deleteAllData() {
|
||||||
|
return q();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user