Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Reset store state when logging out #930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ module.exports = React.createClass({
this.notifyNewScreen('register');
},

// TODO: Move to RoomViewStore
_viewNextRoom: function(roomIndexDelta) {
const allRooms = RoomListSorter.mostRecentActivityFirst(
MatrixClientPeg.get().getRooms(),
Expand All @@ -566,15 +567,22 @@ module.exports = React.createClass({
}
roomIndex = (roomIndex + roomIndexDelta) % allRooms.length;
if (roomIndex < 0) roomIndex = allRooms.length - 1;
this._viewRoom({ room_id: allRooms[roomIndex].roomId });
dis.dispatch({
action: 'view_room',
room_id: allRooms[roomIndex].roomId,
});
},

// TODO: Move to RoomViewStore
_viewIndexedRoom: function(roomIndex) {
const allRooms = RoomListSorter.mostRecentActivityFirst(
MatrixClientPeg.get().getRooms(),
);
if (allRooms[roomIndex]) {
this._viewRoom({ room_id: allRooms[roomIndex].roomId });
dis.dispatch({
action: 'view_room',
room_id: allRooms[roomIndex].roomId,
});
}
},

Expand Down
14 changes: 10 additions & 4 deletions src/components/structures/RoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,6 @@ module.exports = React.createClass({
// compatability workaround, let's not bother.
Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender()).done();
}

this.setState({
joining: false
});
}
}, 500),

Expand Down Expand Up @@ -762,12 +758,22 @@ module.exports = React.createClass({
},
});

// Don't peek whilst registering otherwise getPendingEventList complains
// Do this by indicating our intention to join
dis.dispatch({
action: 'will_join',
});

const SetMxIdDialog = sdk.getComponent('views.dialogs.SetMxIdDialog');
const close = Modal.createDialog(SetMxIdDialog, {
homeserverUrl: cli.getHomeserverUrl(),
onFinished: (submitted, credentials) => {
if (submitted) {
this.props.onRegistered(credentials);
} else {
dis.dispatch({
action: 'cancel_join',
});
}
},
onDifferentServerClicked: (ev) => {
Expand Down
15 changes: 12 additions & 3 deletions src/stores/LifecycleStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ limitations under the License.
import dis from '../dispatcher';
import {Store} from 'flux/utils';

const INITIAL_STATE = {
deferred_action: null,
};

/**
* A class for storing application state to do with login/registration. This is a simple
* flux store that listens for actions and updates its state accordingly, informing any
Expand All @@ -33,9 +37,7 @@ class LifecycleStore extends Store {
super(dis);

// Initialise state
this._state = {
deferred_action: null,
};
this._state = INITIAL_STATE;
}

_setState(newState) {
Expand All @@ -61,8 +63,15 @@ class LifecycleStore extends Store {
});
dis.dispatch(deferredAction);
break;
case 'on_logged_out':
this.reset();
break;
}
}

reset() {
this._state = Object.assign({}, INITIAL_STATE);
}
}

let singletonLifecycleStore = null;
Expand Down
14 changes: 13 additions & 1 deletion src/stores/RoomViewStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ class RoomViewStore extends Store {
case 'view_room':
this._viewRoom(payload);
break;

case 'will_join':
this._setState({
joining: true,
});
break;
case 'cancel_join':
this._setState({
joining: false,
});
break;
// join_room:
// - opts: options for joinRoom
case 'join_room':
this._joinRoom(payload);
break;
case 'on_logged_out':
this.reset();
break;
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/stores/SessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ limitations under the License.
import dis from '../dispatcher';
import {Store} from 'flux/utils';

const INITIAL_STATE = {
cachedPassword: localStorage.getItem('mx_pass'),
};

/**
* A class for storing application state to do with the session. This is a simple flux
* store that listens for actions and updates its state accordingly, informing any
Expand All @@ -33,9 +37,7 @@ class SessionStore extends Store {
super(dis);

// Initialise state
this._state = {
cachedPassword: localStorage.getItem('mx_pass'),
};
this._state = INITIAL_STATE;
}

_update() {
Expand Down Expand Up @@ -66,9 +68,16 @@ class SessionStore extends Store {
cachedPassword: null,
});
break;
case 'on_logged_out':
this.reset();
break;
}
}

reset() {
this._state = Object.assign({}, INITIAL_STATE);
}

getCachedPassword() {
return this._state.cachedPassword;
}
Expand Down