From aff1e14efc70ab5c2bc86d4d724c604d63806d6b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 May 2017 13:15:14 +0100 Subject: [PATCH 1/5] first go at show redact only if we can redact Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/context_menus/MessageContextMenu.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index db416b8a..0f750c10 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -25,6 +25,11 @@ var Modal = require('matrix-react-sdk/lib/Modal'); var Resend = require("matrix-react-sdk/lib/Resend"); import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; +function parseIntWithDefault(val, def) { + var res = parseInt(val); + return isNaN(res) ? def : res; +} + module.exports = React.createClass({ displayName: 'MessageContextMenu', @@ -126,7 +131,19 @@ module.exports = React.createClass({ ); } - if (!eventStatus && !this.props.mxEvent.isRedacted()) { // sent and not redacted + const cli = MatrixClientPeg.get(); + + const room = cli.getRoom(this.props.mxEvent.getRoomId()); + const powerLevelEvents = room.currentState.getStateEvents('m.room.power_levels', ''); + const powerLevels = powerLevelEvents ? powerLevelEvents.getContent() : {}; + const userLevels = powerLevels.users || {}; + + const userLevel = userLevels[cli.credentials.userId] || parseIntWithDefault(powerLevels.users_default, 0); + + if (!eventStatus && !this.props.mxEvent.isRedacted() && (// sent and not redacted + this.props.mxEvent.getSender() === cli.credentials.userId // own event + || userLevel >= parseIntWithDefault(powerLevels.redact, 50) // has PL to redact + )) { redactButton = (
Redact From d55f4f9e6a3e3a3e1230d97132b22c9ea1aa14c6 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 May 2017 14:08:00 +0100 Subject: [PATCH 2/5] use new RoomState method from matrix-org/matrix-js-sdk/pull/435 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/context_menus/MessageContextMenu.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 0f750c10..1fab91dd 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -132,18 +132,9 @@ module.exports = React.createClass({ } const cli = MatrixClientPeg.get(); - const room = cli.getRoom(this.props.mxEvent.getRoomId()); - const powerLevelEvents = room.currentState.getStateEvents('m.room.power_levels', ''); - const powerLevels = powerLevelEvents ? powerLevelEvents.getContent() : {}; - const userLevels = powerLevels.users || {}; - const userLevel = userLevels[cli.credentials.userId] || parseIntWithDefault(powerLevels.users_default, 0); - - if (!eventStatus && !this.props.mxEvent.isRedacted() && (// sent and not redacted - this.props.mxEvent.getSender() === cli.credentials.userId // own event - || userLevel >= parseIntWithDefault(powerLevels.redact, 50) // has PL to redact - )) { + if (!eventStatus && room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId)) { redactButton = (
Redact From db78534b45fff22219a07128d600093dfef7b4b9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 May 2017 14:10:00 +0100 Subject: [PATCH 3/5] remove no longer required parseIntWithDefault Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/context_menus/MessageContextMenu.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 1fab91dd..d200f5ae 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -25,11 +25,6 @@ var Modal = require('matrix-react-sdk/lib/Modal'); var Resend = require("matrix-react-sdk/lib/Resend"); import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; -function parseIntWithDefault(val, def) { - var res = parseInt(val); - return isNaN(res) ? def : res; -} - module.exports = React.createClass({ displayName: 'MessageContextMenu', From 58ada2c27d2d0d3f307545169fff2b317fee0399 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 May 2017 14:14:06 +0100 Subject: [PATCH 4/5] move mxEvent.status check to js-sdk Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/context_menus/MessageContextMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index d200f5ae..86c1d74a 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -129,7 +129,7 @@ module.exports = React.createClass({ const cli = MatrixClientPeg.get(); const room = cli.getRoom(this.props.mxEvent.getRoomId()); - if (!eventStatus && room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId)) { + if (room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId)) { redactButton = (
Redact 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 5/5] 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 00fa18f6..56758b2f 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') }
); }