forked from matrix/element-web
Hide the pin option in the context menu if the user can't pin messages
Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
parent
efdb4b02c6
commit
f7389b70aa
|
@ -43,26 +43,30 @@ module.exports = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
canRedact: false,
|
canRedact: false,
|
||||||
|
canPin: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkCanRedact);
|
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkPermissions);
|
||||||
this._checkCanRedact();
|
this._checkPermissions();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
if (cli) {
|
if (cli) {
|
||||||
cli.removeListener('RoomMember.powerLevel', this._checkCanRedact);
|
cli.removeListener('RoomMember.powerLevel', this._checkPermissions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_checkCanRedact: function() {
|
_checkPermissions: function() {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
const room = cli.getRoom(this.props.mxEvent.getRoomId());
|
const room = cli.getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
|
||||||
const canRedact = room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId);
|
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() {
|
_isPinned: function() {
|
||||||
|
@ -210,11 +214,14 @@ module.exports = React.createClass({
|
||||||
{ _t('Forward Message') }
|
{ _t('Forward Message') }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
pinButton = (
|
|
||||||
<div className="mx_MessageContextMenu_field" onClick={this.onPinClick}>
|
if (this.state.canPin) {
|
||||||
{ this._isPinned() ? _t('Unpin Message') : _t('Pin Message') }
|
pinButton = (
|
||||||
</div>
|
<div className="mx_MessageContextMenu_field" onClick={this.onPinClick}>
|
||||||
);
|
{this._isPinned() ? _t('Unpin Message') : _t('Pin Message')}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue