@@ -18,6 +18,7 @@ limitations under the License.
1818
1919import React from 'react' ;
2020import PropTypes from 'prop-types' ;
21+ import classNames from 'classnames' ;
2122import { _t } from 'matrix-react-sdk/lib/languageHandler' ;
2223import sdk from 'matrix-react-sdk' ;
2324import dis from 'matrix-react-sdk/lib/dispatcher' ;
@@ -99,27 +100,50 @@ module.exports = React.createClass({
99100 this . dispatcherRef = dis . register ( this . onAction ) ;
100101 const cli = this . context . matrixClient ;
101102 cli . on ( "RoomState.members" , this . onRoomStateMember ) ;
103+ this . _initGroupStore ( this . props . groupId ) ;
102104 } ,
103105
104106 componentWillUnmount : function ( ) {
105107 dis . unregister ( this . dispatcherRef ) ;
106108 if ( this . context . matrixClient ) {
107109 this . context . matrixClient . removeListener ( "RoomState.members" , this . onRoomStateMember ) ;
108110 }
111+ this . _unregisterGroupStore ( ) ;
109112 } ,
110113
111114 getInitialState : function ( ) {
112- if ( this . props . groupId ) {
113- return {
114- phase : this . Phase . GroupMemberList ,
115- } ;
116- } else {
117- return {
118- phase : this . Phase . RoomMemberList ,
119- } ;
115+ return {
116+ phase : this . props . groupId ? this . Phase . GroupMemberList : this . Phase . RoomMemberList ,
117+ isUserPrivilegedInGroup : null ,
118+ }
119+ } ,
120+
121+ componentWillReceiveProps ( newProps ) {
122+ if ( newProps . groupId !== this . props . groupId ) {
123+ this . _unregisterGroupStore ( ) ;
124+ this . _initGroupStore ( newProps . groupId ) ;
125+ }
126+ } ,
127+
128+ _initGroupStore ( groupId ) {
129+ this . _groupStore = GroupStoreCache . getGroupStore (
130+ this . context . matrixClient , this . props . groupId ,
131+ ) ;
132+ this . _groupStore . registerListener ( this . onGroupStoreUpdated ) ;
133+ } ,
134+
135+ _unregisterGroupStore ( ) {
136+ if ( this . _groupStore ) {
137+ this . _groupStore . unregisterListener ( this . onGroupStoreUpdated ) ;
120138 }
121139 } ,
122140
141+ onGroupStoreUpdated : function ( ) {
142+ this . setState ( {
143+ isUserPrivilegedInGroup : this . _groupStore . isUserPrivileged ( ) ,
144+ } ) ;
145+ } ,
146+
123147 onCollapseClick : function ( ) {
124148 dis . dispatch ( {
125149 action : 'hide_right_panel' ,
@@ -248,6 +272,11 @@ module.exports = React.createClass({
248272 }
249273 }
250274
275+ const isPhaseGroup = [
276+ this . Phase . GroupMemberInfo ,
277+ this . Phase . GroupMemberList
278+ ] . includes ( this . state . phase ) ;
279+
251280 let headerButtons = [ ] ;
252281 if ( this . props . roomId ) {
253282 headerButtons = [
@@ -271,7 +300,7 @@ module.exports = React.createClass({
271300 } else if ( this . props . groupId ) {
272301 headerButtons = [
273302 < HeaderButton key = "_groupMembersButton" title = { _t ( 'Members' ) } iconSrc = "img/icons-people.svg"
274- isHighlighted = { this . state . phase === this . Phase . GroupMemberList }
303+ isHighlighted = { isPhaseGroup }
275304 clickPhase = { this . Phase . GroupMemberList }
276305 analytics = { [ 'Right Panel' , 'Group Member List Button' , 'click' ] }
277306 /> ,
@@ -322,13 +351,8 @@ module.exports = React.createClass({
322351 panel = < div className = "mx_RightPanel_blank" > </ div > ;
323352 }
324353
325- if ( this . props . groupId &&
326- GroupStoreCache . getGroupStore ( this . context . matrixClient , this . props . groupId ) . isUserPrivileged ( )
327- ) {
328- inviteGroup = [
329- this . Phase . GroupMemberInfo ,
330- this . Phase . GroupMemberList ,
331- ] . includes ( this . state . phase ) ? (
354+ if ( this . props . groupId && this . state . isUserPrivilegedInGroup ) {
355+ inviteGroup = isPhaseGroup ? (
332356 < AccessibleButton className = "mx_RightPanel_invite" onClick = { this . onInviteButtonClick } >
333357 < div className = "mx_RightPanel_icon" >
334358 < TintableSvg src = "img/icon-invite-people.svg" width = "35" height = "35" />
@@ -345,13 +369,16 @@ module.exports = React.createClass({
345369 ) ;
346370 }
347371
348- let classes = "mx_RightPanel mx_fadable" ;
349- if ( this . props . collapsed ) {
350- classes += " collapsed" ;
351- }
372+ let classes = classNames (
373+ "mx_RightPanel" , "mx_fadable" ,
374+ {
375+ "collapsed" : this . props . collapsed ,
376+ "mx_fadable_faded" : this . props . disabled ,
377+ }
378+ ) ;
352379
353380 return (
354- < aside className = { classes } style = { { opacity : this . props . opacity } } >
381+ < aside className = { classes } >
355382 < div className = "mx_RightPanel_header" >
356383 < div className = "mx_RightPanel_headerButtonGroup" >
357384 { headerButtons }
0 commit comments