From 17c4e7a748b5080ab25f3646b8860a75492a4b89 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 29 May 2017 23:49:56 +0100 Subject: [PATCH] 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> --- .../views/context_menus/MessageContextMenu.js | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 00fa18f6a8..56758b2f30 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -40,6 +40,31 @@ module.exports = React.createClass({ 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() { Resend.resend(this.props.mxEvent); if (this.props.onFinished) this.props.onFinished(); @@ -136,10 +161,7 @@ module.exports = React.createClass({ ); } - const cli = MatrixClientPeg.get(); - const room = cli.getRoom(this.props.mxEvent.getRoomId()); - - if (room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId)) { + if (this.state.canRedact) { redactButton = (
{ _t('Remove') } @@ -209,7 +231,7 @@ module.exports = React.createClass({ externalURLButton = (
{ _t('Source URL') } + rel="noopener" target="_blank" onClick={ this.closeMenu }>{ _t('Source URL') }
); }