From f5f3c894d718cab93706174f412594f980442ea7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 4 Jan 2018 14:24:13 +0000 Subject: [PATCH 1/2] only save RelatedGroupSettings if it was modified. Otherwise perms issue Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/room_settings/RelatedGroupSettings.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/views/room_settings/RelatedGroupSettings.js b/src/components/views/room_settings/RelatedGroupSettings.js index 5b2810d837..f84f1d91cb 100644 --- a/src/components/views/room_settings/RelatedGroupSettings.js +++ b/src/components/views/room_settings/RelatedGroupSettings.js @@ -45,11 +45,14 @@ module.exports = React.createClass({ return { newGroupsList: this.props.relatedGroupsEvent ? (this.props.relatedGroupsEvent.getContent().groups || []) : [], + hasChanged: false, newGroupId: null, }; }, saveSettings: function() { + if (!this.state.hasChanged) return Promise.resolve(); + return this.context.matrixClient.sendStateEvent( this.props.roomId, 'm.room.related_groups', @@ -82,6 +85,7 @@ module.exports = React.createClass({ } this.setState({ newGroupsList: this.state.newGroupsList.concat([groupId]), + hasChanged: true, newGroupId: '', }); }, @@ -92,13 +96,14 @@ module.exports = React.createClass({ } this.setState({ newGroupsList: Object.assign(this.state.newGroupsList, {[index]: groupId}), + hasChanged: true, }); }, onGroupDeleted: function(index) { const newGroupsList = this.state.newGroupsList.slice(); - newGroupsList.splice(index, 1), - this.setState({ newGroupsList }); + newGroupsList.splice(index, 1); + this.setState({ newGroupsList, hasChanged: true }); }, render: function() { From 293bb15cccbcd26fc63e1ef739d41c39d5691a01 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 Jan 2018 10:53:55 +0000 Subject: [PATCH 2/2] check PL and compare arrays rather than tracking changes Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../room_settings/RelatedGroupSettings.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/views/room_settings/RelatedGroupSettings.js b/src/components/views/room_settings/RelatedGroupSettings.js index f84f1d91cb..e1fc7cd80d 100644 --- a/src/components/views/room_settings/RelatedGroupSettings.js +++ b/src/components/views/room_settings/RelatedGroupSettings.js @@ -19,6 +19,7 @@ import {MatrixEvent, MatrixClient} from 'matrix-js-sdk'; import sdk from '../../../index'; import { _t } from '../../../languageHandler'; import Modal from '../../../Modal'; +import isEqual from 'lodash/isEqual'; const GROUP_ID_REGEX = /\+\S+\:\S+/; @@ -43,15 +44,24 @@ module.exports = React.createClass({ getInitialState: function() { return { - newGroupsList: this.props.relatedGroupsEvent ? - (this.props.relatedGroupsEvent.getContent().groups || []) : [], - hasChanged: false, + newGroupsList: this.getInitialGroupList(), 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() { - if (!this.state.hasChanged) return Promise.resolve(); + if (!this.needsSaving()) return Promise.resolve(); return this.context.matrixClient.sendStateEvent( this.props.roomId, @@ -85,7 +95,6 @@ module.exports = React.createClass({ } this.setState({ newGroupsList: this.state.newGroupsList.concat([groupId]), - hasChanged: true, newGroupId: '', }); }, @@ -96,14 +105,13 @@ module.exports = React.createClass({ } this.setState({ newGroupsList: Object.assign(this.state.newGroupsList, {[index]: groupId}), - hasChanged: true, }); }, onGroupDeleted: function(index) { const newGroupsList = this.state.newGroupsList.slice(); newGroupsList.splice(index, 1); - this.setState({ newGroupsList, hasChanged: true }); + this.setState({ newGroupsList }); }, render: function() {