From 7bae7fe9e5e0cb0877e1038a1efbe2acbe105399 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 27 Oct 2017 14:23:45 +0100 Subject: [PATCH] Use correct group store state when rendering "Invite to this community" This required slight rework of how RightPanel uses the group store, and now it knows an unfortunate amount about the group store. Food for thought on stores in general, I think. --- src/components/structures/RightPanel.js | 43 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/components/structures/RightPanel.js b/src/components/structures/RightPanel.js index e6bfea83..18567b57 100644 --- a/src/components/structures/RightPanel.js +++ b/src/components/structures/RightPanel.js @@ -100,6 +100,7 @@ module.exports = React.createClass({ this.dispatcherRef = dis.register(this.onAction); const cli = this.context.matrixClient; cli.on("RoomState.members", this.onRoomStateMember); + this._initGroupStore(this.props.groupId); }, componentWillUnmount: function() { @@ -107,20 +108,42 @@ module.exports = React.createClass({ if (this.context.matrixClient) { this.context.matrixClient.removeListener("RoomState.members", this.onRoomStateMember); } + this._unregisterGroupStore(); }, getInitialState: function() { - if (this.props.groupId) { - return { - phase: this.Phase.GroupMemberList, - }; - } else { - return { - phase: this.Phase.RoomMemberList, - }; + return { + phase: this.props.groupId ? this.Phase.GroupMemberList : this.Phase.RoomMemberList, + isUserPrivilegedInGroup: null, } }, + componentWillReceiveProps(newProps) { + if (newProps.groupId !== this.props.groupId) { + this._unregisterGroupStore(); + this._initGroupStore(newProps.groupId); + } + }, + + _initGroupStore(groupId) { + this._groupStore = GroupStoreCache.getGroupStore( + this.context.matrixClient, this.props.groupId, + ); + this._groupStore.registerListener(this.onGroupStoreUpdated); + }, + + _unregisterGroupStore() { + if (this._groupStore) { + this._groupStore.unregisterListener(this.onGroupStoreUpdated); + } + }, + + onGroupStoreUpdated: function(){ + this.setState({ + isUserPrivilegedInGroup: this._groupStore.isUserPrivileged(), + }); + }, + onCollapseClick: function() { dis.dispatch({ action: 'hide_right_panel', @@ -328,9 +351,7 @@ module.exports = React.createClass({ panel =
; } - if (this.props.groupId && - GroupStoreCache.getGroupStore(this.context.matrixClient, this.props.groupId).isUserPrivileged() - ) { + if (this.props.groupId && this.state.isUserPrivilegedInGroup) { inviteGroup = isPhaseGroup ? (