check PL and compare arrays rather than tracking changes
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f5f3c894d7
commit
293bb15ccc
1 changed files with 15 additions and 7 deletions
|
@ -19,6 +19,7 @@ import {MatrixEvent, MatrixClient} from 'matrix-js-sdk';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
|
|
||||||
const GROUP_ID_REGEX = /\+\S+\:\S+/;
|
const GROUP_ID_REGEX = /\+\S+\:\S+/;
|
||||||
|
|
||||||
|
@ -43,15 +44,24 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
newGroupsList: this.props.relatedGroupsEvent ?
|
newGroupsList: this.getInitialGroupList(),
|
||||||
(this.props.relatedGroupsEvent.getContent().groups || []) : [],
|
|
||||||
hasChanged: false,
|
|
||||||
newGroupId: null,
|
newGroupId: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialGroupList: function() {
|
||||||
|
return this.props.relatedGroupsEvent ? (this.props.relatedGroupsEvent.getContent().groups || []) : [];
|
||||||
|
},
|
||||||
|
|
||||||
|
needsSaving: function() {
|
||||||
|
const cli = this.context.matrixClient;
|
||||||
|
const room = cli.getRoom(this.props.roomId);
|
||||||
|
if (!room.currentState.maySendStateEvent('m.room.related_groups', cli.getUserId())) return false;
|
||||||
|
return isEqual(this.getInitialGroupList(), this.state.newGroupsList);
|
||||||
|
},
|
||||||
|
|
||||||
saveSettings: function() {
|
saveSettings: function() {
|
||||||
if (!this.state.hasChanged) return Promise.resolve();
|
if (!this.needsSaving()) return Promise.resolve();
|
||||||
|
|
||||||
return this.context.matrixClient.sendStateEvent(
|
return this.context.matrixClient.sendStateEvent(
|
||||||
this.props.roomId,
|
this.props.roomId,
|
||||||
|
@ -85,7 +95,6 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
newGroupsList: this.state.newGroupsList.concat([groupId]),
|
newGroupsList: this.state.newGroupsList.concat([groupId]),
|
||||||
hasChanged: true,
|
|
||||||
newGroupId: '',
|
newGroupId: '',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -96,14 +105,13 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
newGroupsList: Object.assign(this.state.newGroupsList, {[index]: groupId}),
|
newGroupsList: Object.assign(this.state.newGroupsList, {[index]: groupId}),
|
||||||
hasChanged: true,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onGroupDeleted: function(index) {
|
onGroupDeleted: function(index) {
|
||||||
const newGroupsList = this.state.newGroupsList.slice();
|
const newGroupsList = this.state.newGroupsList.slice();
|
||||||
newGroupsList.splice(index, 1);
|
newGroupsList.splice(index, 1);
|
||||||
this.setState({ newGroupsList, hasChanged: true });
|
this.setState({ newGroupsList });
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue