@@ -18,14 +18,16 @@ 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' ;
24- import MatrixClientPeg from 'matrix-react -sdk/lib/MatrixClientPeg ' ;
25+ import MatrixClient from 'matrix-js -sdk' ;
2526import Analytics from 'matrix-react-sdk/lib/Analytics' ;
2627import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc' ;
2728import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
2829import { showGroupInviteDialog , showGroupAddRoomDialog } from 'matrix-react-sdk/lib/GroupAddressPicker' ;
30+ import GroupStoreCache from 'matrix-react-sdk/lib/stores/GroupStoreCache' ;
2931
3032class HeaderButton extends React . Component {
3133 constructor ( ) {
@@ -80,6 +82,10 @@ module.exports = React.createClass({
8082 collapsed : React . PropTypes . bool , // currently unused property to request for a minimized view of the panel
8183 } ,
8284
85+ contextTypes : {
86+ matrixClient : PropTypes . instanceOf ( MatrixClient ) ,
87+ } ,
88+
8389 Phase : {
8490 RoomMemberList : 'RoomMemberList' ,
8591 GroupMemberList : 'GroupMemberList' ,
@@ -92,37 +98,60 @@ module.exports = React.createClass({
9298
9399 componentWillMount : function ( ) {
94100 this . dispatcherRef = dis . register ( this . onAction ) ;
95- const cli = MatrixClientPeg . get ( ) ;
101+ const cli = this . context . matrixClient ;
96102 cli . on ( "RoomState.members" , this . onRoomStateMember ) ;
103+ this . _initGroupStore ( this . props . groupId ) ;
97104 } ,
98105
99106 componentWillUnmount : function ( ) {
100107 dis . unregister ( this . dispatcherRef ) ;
101- if ( MatrixClientPeg . get ( ) ) {
102- MatrixClientPeg . get ( ) . removeListener ( "RoomState.members" , this . onRoomStateMember ) ;
108+ if ( this . context . matrixClient ) {
109+ this . context . matrixClient . removeListener ( "RoomState.members" , this . onRoomStateMember ) ;
103110 }
111+ this . _unregisterGroupStore ( ) ;
104112 } ,
105113
106114 getInitialState : function ( ) {
107- if ( this . props . groupId ) {
108- return {
109- phase : this . Phase . GroupMemberList ,
110- } ;
111- } else {
112- return {
113- phase : this . Phase . RoomMemberList ,
114- } ;
115+ return {
116+ phase : this . props . groupId ? this . Phase . GroupMemberList : this . Phase . RoomMemberList ,
117+ isUserPrivilegedInGroup : null ,
115118 }
116119 } ,
117120
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 ) ;
138+ }
139+ } ,
140+
141+ onGroupStoreUpdated : function ( ) {
142+ this . setState ( {
143+ isUserPrivilegedInGroup : this . _groupStore . isUserPrivileged ( ) ,
144+ } ) ;
145+ } ,
146+
118147 onCollapseClick : function ( ) {
119148 dis . dispatch ( {
120149 action : 'hide_right_panel' ,
121150 } ) ;
122151 } ,
123152
124153 onInviteButtonClick : function ( ) {
125- if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
154+ if ( this . context . matrixClient . isGuest ( ) ) {
126155 dis . dispatch ( { action : 'view_set_mxid' } ) ;
127156 return ;
128157 }
@@ -222,13 +251,13 @@ module.exports = React.createClass({
222251 if ( ( this . state . phase == this . Phase . RoomMemberList || this . state . phase === this . Phase . RoomMemberInfo )
223252 && this . props . roomId
224253 ) {
225- const cli = MatrixClientPeg . get ( ) ;
254+ const cli = this . context . matrixClient ;
226255 const room = cli . getRoom ( this . props . roomId ) ;
227256 let userIsInRoom ;
228257 if ( room ) {
229258 membersBadge = room . getJoinedMembers ( ) . length ;
230259 userIsInRoom = room . hasMembershipState (
231- MatrixClientPeg . get ( ) . credentials . userId , 'join' ,
260+ this . context . matrixClient . credentials . userId , 'join' ,
232261 ) ;
233262 }
234263
@@ -243,6 +272,11 @@ module.exports = React.createClass({
243272 }
244273 }
245274
275+ const isPhaseGroup = [
276+ this . Phase . GroupMemberInfo ,
277+ this . Phase . GroupMemberList
278+ ] . includes ( this . state . phase ) ;
279+
246280 let headerButtons = [ ] ;
247281 if ( this . props . roomId ) {
248282 headerButtons = [
@@ -266,7 +300,7 @@ module.exports = React.createClass({
266300 } else if ( this . props . groupId ) {
267301 headerButtons = [
268302 < HeaderButton key = "_groupMembersButton" title = { _t ( 'Members' ) } iconSrc = "img/icons-people.svg"
269- isHighlighted = { this . state . phase === this . Phase . GroupMemberList }
303+ isHighlighted = { isPhaseGroup }
270304 clickPhase = { this . Phase . GroupMemberList }
271305 analytics = { [ 'Right Panel' , 'Group Member List Button' , 'click' ] }
272306 /> ,
@@ -317,8 +351,8 @@ module.exports = React.createClass({
317351 panel = < div className = "mx_RightPanel_blank" > </ div > ;
318352 }
319353
320- if ( this . props . groupId ) {
321- inviteGroup = this . state . phase === this . Phase . GroupMemberList ? (
354+ if ( this . props . groupId && this . state . isUserPrivilegedInGroup ) {
355+ inviteGroup = isPhaseGroup ? (
322356 < AccessibleButton className = "mx_RightPanel_invite" onClick = { this . onInviteButtonClick } >
323357 < div className = "mx_RightPanel_icon" >
324358 < TintableSvg src = "img/icon-invite-people.svg" width = "35" height = "35" />
@@ -335,13 +369,16 @@ module.exports = React.createClass({
335369 ) ;
336370 }
337371
338- let classes = "mx_RightPanel mx_fadable" ;
339- if ( this . props . collapsed ) {
340- classes += " collapsed" ;
341- }
372+ let classes = classNames (
373+ "mx_RightPanel" , "mx_fadable" ,
374+ {
375+ "collapsed" : this . props . collapsed ,
376+ "mx_fadable_faded" : this . props . disabled ,
377+ }
378+ ) ;
342379
343380 return (
344- < aside className = { classes } style = { { opacity : this . props . opacity } } >
381+ < aside className = { classes } >
345382 < div className = "mx_RightPanel_header" >
346383 < div className = "mx_RightPanel_headerButtonGroup" >
347384 { headerButtons }
0 commit comments