Skip to content

Commit 17c4e7a

Browse files
committed
check PL on change as well as on comp load, that way it'll show remove button if PL increases later.
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent d3f9304 commit 17c4e7a

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

‎src/components/views/context_menus/MessageContextMenu.js‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ module.exports = React.createClass({
4040
onFinished: React.PropTypes.func,
4141
},
4242

43+
getInitialState: function() {
44+
return {
45+
canRedact: false,
46+
};
47+
},
48+
49+
componentWillMount: function() {
50+
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkCanRedact);
51+
this._checkCanRedact();
52+
},
53+
54+
componentWillUnmount: function() {
55+
const cli = MatrixClientPeg.get();
56+
if (cli) {
57+
cli.removeListener('RoomMember.powerLevel', this._checkCanRedact);
58+
}
59+
},
60+
61+
_checkCanRedact: function() {
62+
const cli = MatrixClientPeg.get();
63+
const room = cli.getRoom(this.props.mxEvent.getRoomId());
64+
const canRedact = room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId);
65+
this.setState({canRedact});
66+
},
67+
4368
onResendClick: function() {
4469
Resend.resend(this.props.mxEvent);
4570
if (this.props.onFinished) this.props.onFinished();
@@ -136,10 +161,7 @@ module.exports = React.createClass({
136161
);
137162
}
138163

139-
const cli = MatrixClientPeg.get();
140-
const room = cli.getRoom(this.props.mxEvent.getRoomId());
141-
142-
if (room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId)) {
164+
if (this.state.canRedact) {
143165
redactButton = (
144166
<div className="mx_MessageContextMenu_field" onClick={this.onRedactClick}>
145167
{ _t('Remove') }
@@ -209,7 +231,7 @@ module.exports = React.createClass({
209231
externalURLButton = (
210232
<div className="mx_MessageContextMenu_field">
211233
<a href={ this.props.mxEvent.event.content.external_url }
212-
rel="noopener" target="_blank" onClick={ this.closeMenu }>{ _t('Source URL') }</a>
234+
rel="noopener" target="_blank" onClick={ this.closeMenu }>{ _t('Source URL') }</a>
213235
</div>
214236
);
215237
}

0 commit comments

Comments
 (0)