PR feedback

pull/1982/head
David Baker 2016-08-18 13:11:57 +01:00
parent 6b0aeefc66
commit e48d68a449
1 changed files with 30 additions and 22 deletions

View File

@ -37,14 +37,21 @@ module.exports = React.createClass({
} }
}, },
componentWillMount: function() {
this._unmounted = false;
},
componentWillUnmount: function() {
this._unmounted = true;
},
_save: function(newState) { _save: function(newState) {
const oldState = this.state.roomNotifState; const oldState = this.state.roomNotifState;
const roomId = this.props.room.roomId; const roomId = this.props.room.roomId;
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
if (!cli.isGuest()) { if (cli.isGuest()) return;
// Wrapping this in a q promise, as setRoomMutePushRule can return
// a promise or a value
this.setState({ this.setState({
roomNotifState: newState, roomNotifState: newState,
}); });
@ -52,6 +59,7 @@ module.exports = React.createClass({
// delay slightly so that the user can see their state change // delay slightly so that the user can see their state change
// before closing the menu // before closing the menu
return q.delay(500).then(() => { return q.delay(500).then(() => {
if (this._unmounted) return;
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
@ -61,11 +69,11 @@ module.exports = React.createClass({
// TODO: some form of error notification to the user // TODO: some form of error notification to the user
// to inform them that their state change failed. // to inform them that their state change failed.
// For now we at least set the state back // For now we at least set the state back
if (this._unmounted) return;
this.setState({ this.setState({
roomNotifState: oldState, roomNotifState: oldState,
}); });
}); });
}
}, },
_onClickAlertMe: function() { _onClickAlertMe: function() {