@@ -100,27 +100,50 @@ module.exports = React.createClass({
100100 this . dispatcherRef = dis . register ( this . onAction ) ;
101101 const cli = this . context . matrixClient ;
102102 cli . on ( "RoomState.members" , this . onRoomStateMember ) ;
103+ this . _initGroupStore ( this . props . groupId ) ;
103104 } ,
104105
105106 componentWillUnmount : function ( ) {
106107 dis . unregister ( this . dispatcherRef ) ;
107108 if ( this . context . matrixClient ) {
108109 this . context . matrixClient . removeListener ( "RoomState.members" , this . onRoomStateMember ) ;
109110 }
111+ this . _unregisterGroupStore ( ) ;
110112 } ,
111113
112114 getInitialState : function ( ) {
113- if ( this . props . groupId ) {
114- return {
115- phase : this . Phase . GroupMemberList ,
116- } ;
117- } else {
118- return {
119- phase : this . Phase . RoomMemberList ,
120- } ;
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 ) ;
121138 }
122139 } ,
123140
141+ onGroupStoreUpdated : function ( ) {
142+ this . setState ( {
143+ isUserPrivilegedInGroup : this . _groupStore . isUserPrivileged ( ) ,
144+ } ) ;
145+ } ,
146+
124147 onCollapseClick : function ( ) {
125148 dis . dispatch ( {
126149 action : 'hide_right_panel' ,
@@ -328,9 +351,7 @@ module.exports = React.createClass({
328351 panel = < div className = "mx_RightPanel_blank" > </ div > ;
329352 }
330353
331- if ( this . props . groupId &&
332- GroupStoreCache . getGroupStore ( this . context . matrixClient , this . props . groupId ) . isUserPrivileged ( )
333- ) {
354+ if ( this . props . groupId && this . state . isUserPrivilegedInGroup ) {
334355 inviteGroup = isPhaseGroup ? (
335356 < AccessibleButton className = "mx_RightPanel_invite" onClick = { this . onInviteButtonClick } >
336357 < div className = "mx_RightPanel_icon" >
0 commit comments