From f7389b70aac8c2d933c24b3cff7ad3324ff9db91 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 29 Sep 2017 11:01:17 -0600 Subject: [PATCH] Hide the pin option in the context menu if the user can't pin messages Signed-off-by: Travis Ralston --- .../views/context_menus/MessageContextMenu.js | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 09503f99f..bc76fd255 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -43,26 +43,30 @@ module.exports = React.createClass({ getInitialState: function() { return { canRedact: false, + canPin: false, }; }, componentWillMount: function() { - MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkCanRedact); - this._checkCanRedact(); + MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkPermissions); + this._checkPermissions(); }, componentWillUnmount: function() { const cli = MatrixClientPeg.get(); if (cli) { - cli.removeListener('RoomMember.powerLevel', this._checkCanRedact); + cli.removeListener('RoomMember.powerLevel', this._checkPermissions); } }, - _checkCanRedact: function() { + _checkPermissions: function() { const cli = MatrixClientPeg.get(); const room = cli.getRoom(this.props.mxEvent.getRoomId()); + const canRedact = room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId); - this.setState({canRedact}); + const canPin = room.currentState.mayClientSendStateEvent('m.room.pinned_events', cli); + + this.setState({canRedact, canPin}); }, _isPinned: function() { @@ -210,11 +214,14 @@ module.exports = React.createClass({ { _t('Forward Message') } ); - pinButton = ( -
- { this._isPinned() ? _t('Unpin Message') : _t('Pin Message') } -
- ); + + if (this.state.canPin) { + pinButton = ( +
+ {this._isPinned() ? _t('Unpin Message') : _t('Pin Message')} +
+ ); + } } }