Merge pull request #3925 from vector-im/t3chguy/show_redact_if_can

show redact in context menu only if has PL to/sent message
This commit is contained in:
Luke Barnard 2017-05-30 10:13:20 +01:00 committed by GitHub
commit 543f4efc37

View file

@ -40,6 +40,31 @@ module.exports = React.createClass({
onFinished: React.PropTypes.func, onFinished: React.PropTypes.func,
}, },
getInitialState: function() {
return {
canRedact: false,
};
},
componentWillMount: function() {
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkCanRedact);
this._checkCanRedact();
},
componentWillUnmount: function() {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener('RoomMember.powerLevel', this._checkCanRedact);
}
},
_checkCanRedact: 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});
},
onResendClick: function() { onResendClick: function() {
Resend.resend(this.props.mxEvent); Resend.resend(this.props.mxEvent);
if (this.props.onFinished) this.props.onFinished(); if (this.props.onFinished) this.props.onFinished();
@ -136,7 +161,7 @@ module.exports = React.createClass({
); );
} }
if (!eventStatus && !this.props.mxEvent.isRedacted()) { // sent and not redacted if (this.state.canRedact) {
redactButton = ( redactButton = (
<div className="mx_MessageContextMenu_field" onClick={this.onRedactClick}> <div className="mx_MessageContextMenu_field" onClick={this.onRedactClick}>
{ _t('Remove') } { _t('Remove') }