@@ -237,7 +237,7 @@ function _handleRestoreFailure(e) {
237
237
+ ' This is a once off; sorry for the inconvenience.' ,
238
238
) ;
239
239
240
- _clearLocalStorage ( ) ;
240
+ _clearStorage ( ) ;
241
241
242
242
return q . reject ( new Error (
243
243
_t ( 'Unable to restore previous session' ) + ': ' + msg ,
@@ -258,7 +258,7 @@ function _handleRestoreFailure(e) {
258
258
return def . promise . then ( ( success ) => {
259
259
if ( success ) {
260
260
// user clicked continue.
261
- _clearLocalStorage ( ) ;
261
+ _clearStorage ( ) ;
262
262
return false ;
263
263
}
264
264
@@ -332,6 +332,10 @@ export function setLoggedIn(credentials) {
332
332
}
333
333
334
334
// stop any running clients before we create a new one with these new credentials
335
+ //
336
+ // XXX: why do we have any running clients here? Maybe on sign-in after
337
+ // initial use as a guest? but what about our persistent storage? we need to
338
+ // be careful not to leak e2e data created as one user into another session.
335
339
stopMatrixClient ( ) ;
336
340
337
341
MatrixClientPeg . replaceUsingCreds ( credentials ) ;
@@ -402,13 +406,19 @@ export function startMatrixClient() {
402
406
* a session has been logged out / ended.
403
407
*/
404
408
export function onLoggedOut ( ) {
405
- _clearLocalStorage ( ) ;
406
- stopMatrixClient ( ) ;
409
+ stopMatrixClient ( true ) ;
407
410
dis . dispatch ( { action : 'on_logged_out' } ) ;
408
411
}
409
412
410
- function _clearLocalStorage ( ) {
413
+ function _clearStorage ( ) {
411
414
Analytics . logout ( ) ;
415
+
416
+ const cli = MatrixClientPeg . get ( ) ;
417
+ if ( cli ) {
418
+ // TODO: *really* ought to wait for the promise to complete
419
+ cli . clearStores ( ) . done ( ) ;
420
+ }
421
+
412
422
if ( ! window . localStorage ) {
413
423
return ;
414
424
}
@@ -425,9 +435,13 @@ function _clearLocalStorage() {
425
435
}
426
436
427
437
/**
428
- * Stop all the background processes related to the current client
438
+ * Stop all the background processes related to the current client.
439
+ *
440
+ * Optionally clears persistent stores.
441
+ *
442
+ * @param {boolean } clearStores true to clear the persistent stores.
429
443
*/
430
- export function stopMatrixClient ( ) {
444
+ export function stopMatrixClient ( clearStores ) {
431
445
Notifier . stop ( ) ;
432
446
UserActivity . stop ( ) ;
433
447
Presence . stop ( ) ;
@@ -436,7 +450,13 @@ export function stopMatrixClient() {
436
450
if ( cli ) {
437
451
cli . stopClient ( ) ;
438
452
cli . removeAllListeners ( ) ;
439
- cli . store . deleteAllData ( ) ;
440
- MatrixClientPeg . unset ( ) ;
441
453
}
454
+
455
+ if ( clearStores ) {
456
+ // note that we have to do this *after* stopping the client, but
457
+ // *before* clearing the MatrixClientPeg.
458
+ _clearStorage ( ) ;
459
+ }
460
+
461
+ MatrixClientPeg . unset ( ) ;
442
462
}
0 commit comments