Lifecycle: Make the clear storage method async.

This commit is contained in:
Damir Jelić
2019-11-19 14:05:00 +01:00
parent 6017473caf
commit 979803797f
+6 -10
View File
@@ -607,20 +607,20 @@ async function startMatrixClient(startSyncing=true) {
* Stops a running client and all related services, and clears persistent * Stops a running client and all related services, and clears persistent
* storage. Used after a session has been logged out. * storage. Used after a session has been logged out.
*/ */
export function onLoggedOut() { export async function onLoggedOut() {
_isLoggingOut = false; _isLoggingOut = false;
// Ensure that we dispatch a view change **before** stopping the client so // Ensure that we dispatch a view change **before** stopping the client so
// so that React components unmount first. This avoids React soft crashes // so that React components unmount first. This avoids React soft crashes
// that can occur when components try to use a null client. // that can occur when components try to use a null client.
dis.dispatch({action: 'on_logged_out'}); dis.dispatch({action: 'on_logged_out'});
stopMatrixClient(); stopMatrixClient();
_clearStorage().done(); await _clearStorage();
} }
/** /**
* @returns {Promise} promise which resolves once the stores have been cleared * @returns {Promise} promise which resolves once the stores have been cleared
*/ */
function _clearStorage() { async function _clearStorage() {
Analytics.logout(); Analytics.logout();
if (window.localStorage) { if (window.localStorage) {
@@ -633,12 +633,8 @@ function _clearStorage() {
baseUrl: "", baseUrl: "",
}); });
const clear = async () => { await EventIndexPeg.deleteEventIndex();
await EventIndexPeg.deleteEventIndex(); await cli.clearStores();
await cli.clearStores();
};
return clear();
} }
/** /**
@@ -662,7 +658,7 @@ export function stopMatrixClient(unsetClient=true) {
if (unsetClient) { if (unsetClient) {
MatrixClientPeg.unset(); MatrixClientPeg.unset();
EventIndexPeg.unset().done(); EventIndexPeg.unset();
} }
} }
} }