@@ -43,26 +43,30 @@ module.exports = React.createClass({
4343 getInitialState : function ( ) {
4444 return {
4545 canRedact : false ,
46+ canPin : false ,
4647 } ;
4748 } ,
4849
4950 componentWillMount : function ( ) {
50- MatrixClientPeg . get ( ) . on ( 'RoomMember.powerLevel' , this . _checkCanRedact ) ;
51- this . _checkCanRedact ( ) ;
51+ MatrixClientPeg . get ( ) . on ( 'RoomMember.powerLevel' , this . _checkPermissions ) ;
52+ this . _checkPermissions ( ) ;
5253 } ,
5354
5455 componentWillUnmount : function ( ) {
5556 const cli = MatrixClientPeg . get ( ) ;
5657 if ( cli ) {
57- cli . removeListener ( 'RoomMember.powerLevel' , this . _checkCanRedact ) ;
58+ cli . removeListener ( 'RoomMember.powerLevel' , this . _checkPermissions ) ;
5859 }
5960 } ,
6061
61- _checkCanRedact : function ( ) {
62+ _checkPermissions : function ( ) {
6263 const cli = MatrixClientPeg . get ( ) ;
6364 const room = cli . getRoom ( this . props . mxEvent . getRoomId ( ) ) ;
65+
6466 const canRedact = room . currentState . maySendRedactionForEvent ( this . props . mxEvent , cli . credentials . userId ) ;
65- this . setState ( { canRedact} ) ;
67+ const canPin = room . currentState . mayClientSendStateEvent ( 'm.room.pinned_events' , cli ) ;
68+
69+ this . setState ( { canRedact, canPin} ) ;
6670 } ,
6771
6872 _isPinned : function ( ) {
@@ -210,11 +214,14 @@ module.exports = React.createClass({
210214 { _t ( 'Forward Message' ) }
211215 </ div >
212216 ) ;
213- pinButton = (
214- < div className = "mx_MessageContextMenu_field" onClick = { this . onPinClick } >
215- { this . _isPinned ( ) ? _t ( 'Unpin Message' ) : _t ( 'Pin Message' ) }
216- </ div >
217- ) ;
217+
218+ if ( this . state . canPin ) {
219+ pinButton = (
220+ < div className = "mx_MessageContextMenu_field" onClick = { this . onPinClick } >
221+ { this . _isPinned ( ) ? _t ( 'Unpin Message' ) : _t ( 'Pin Message' ) }
222+ </ div >
223+ ) ;
224+ }
218225 }
219226 }
220227
0 commit comments