Merge pull request #983 from matrix-org/rav/clear_storage_on_logout
Call MatrixClient.clearStores on logout
This commit is contained in:
commit
53ebc8d7bd
2 changed files with 31 additions and 11 deletions
|
@ -237,7 +237,7 @@ function _handleRestoreFailure(e) {
|
||||||
+ ' This is a once off; sorry for the inconvenience.',
|
+ ' This is a once off; sorry for the inconvenience.',
|
||||||
);
|
);
|
||||||
|
|
||||||
_clearLocalStorage();
|
_clearStorage();
|
||||||
|
|
||||||
return q.reject(new Error(
|
return q.reject(new Error(
|
||||||
_t('Unable to restore previous session') + ': ' + msg,
|
_t('Unable to restore previous session') + ': ' + msg,
|
||||||
|
@ -258,7 +258,7 @@ function _handleRestoreFailure(e) {
|
||||||
return def.promise.then((success) => {
|
return def.promise.then((success) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
// user clicked continue.
|
// user clicked continue.
|
||||||
_clearLocalStorage();
|
_clearStorage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,6 +332,10 @@ export function setLoggedIn(credentials) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop any running clients before we create a new one with these new credentials
|
// stop any running clients before we create a new one with these new credentials
|
||||||
|
//
|
||||||
|
// XXX: why do we have any running clients here? Maybe on sign-in after
|
||||||
|
// initial use as a guest? but what about our persistent storage? we need to
|
||||||
|
// be careful not to leak e2e data created as one user into another session.
|
||||||
stopMatrixClient();
|
stopMatrixClient();
|
||||||
|
|
||||||
MatrixClientPeg.replaceUsingCreds(credentials);
|
MatrixClientPeg.replaceUsingCreds(credentials);
|
||||||
|
@ -402,13 +406,19 @@ export function startMatrixClient() {
|
||||||
* a session has been logged out / ended.
|
* a session has been logged out / ended.
|
||||||
*/
|
*/
|
||||||
export function onLoggedOut() {
|
export function onLoggedOut() {
|
||||||
_clearLocalStorage();
|
stopMatrixClient(true);
|
||||||
stopMatrixClient();
|
|
||||||
dis.dispatch({action: 'on_logged_out'});
|
dis.dispatch({action: 'on_logged_out'});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _clearLocalStorage() {
|
function _clearStorage() {
|
||||||
Analytics.logout();
|
Analytics.logout();
|
||||||
|
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
if (cli) {
|
||||||
|
// TODO: *really* ought to wait for the promise to complete
|
||||||
|
cli.clearStores().done();
|
||||||
|
}
|
||||||
|
|
||||||
if (!window.localStorage) {
|
if (!window.localStorage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -425,9 +435,13 @@ function _clearLocalStorage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop all the background processes related to the current client
|
* Stop all the background processes related to the current client.
|
||||||
|
*
|
||||||
|
* Optionally clears persistent stores.
|
||||||
|
*
|
||||||
|
* @param {boolean} clearStores true to clear the persistent stores.
|
||||||
*/
|
*/
|
||||||
export function stopMatrixClient() {
|
export function stopMatrixClient(clearStores) {
|
||||||
Notifier.stop();
|
Notifier.stop();
|
||||||
UserActivity.stop();
|
UserActivity.stop();
|
||||||
Presence.stop();
|
Presence.stop();
|
||||||
|
@ -436,7 +450,13 @@ export function stopMatrixClient() {
|
||||||
if (cli) {
|
if (cli) {
|
||||||
cli.stopClient();
|
cli.stopClient();
|
||||||
cli.removeAllListeners();
|
cli.removeAllListeners();
|
||||||
cli.store.deleteAllData();
|
}
|
||||||
|
|
||||||
|
if (clearStores) {
|
||||||
|
// note that we have to do this *after* stopping the client, but
|
||||||
|
// *before* clearing the MatrixClientPeg.
|
||||||
|
_clearStorage();
|
||||||
|
}
|
||||||
|
|
||||||
MatrixClientPeg.unset();
|
MatrixClientPeg.unset();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -292,7 +292,7 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
Lifecycle.stopMatrixClient();
|
Lifecycle.stopMatrixClient(false);
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
UDEHandler.stopListening();
|
UDEHandler.stopListening();
|
||||||
window.removeEventListener("focus", this.onFocus);
|
window.removeEventListener("focus", this.onFocus);
|
||||||
|
@ -364,7 +364,7 @@ module.exports = React.createClass({
|
||||||
// is completed in another browser, we'll be 401ed for using
|
// is completed in another browser, we'll be 401ed for using
|
||||||
// a guest access token for a non-guest account.
|
// a guest access token for a non-guest account.
|
||||||
// It will be restarted in onReturnToGuestClick
|
// It will be restarted in onReturnToGuestClick
|
||||||
Lifecycle.stopMatrixClient();
|
Lifecycle.stopMatrixClient(false);
|
||||||
|
|
||||||
this.notifyNewScreen('register');
|
this.notifyNewScreen('register');
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue