Skip to content

Commit aff1e14

Browse files
committed
first go at show redact only if we can redact
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent fe61a7e commit aff1e14

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ var Modal = require('matrix-react-sdk/lib/Modal');
2525
var Resend = require("matrix-react-sdk/lib/Resend");
2626
import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore';
2727

28+
function parseIntWithDefault(val, def) {
29+
var res = parseInt(val);
30+
return isNaN(res) ? def : res;
31+
}
32+
2833
module.exports = React.createClass({
2934
displayName: 'MessageContextMenu',
3035

@@ -126,7 +131,19 @@ module.exports = React.createClass({
126131
);
127132
}
128133

129-
if (!eventStatus && !this.props.mxEvent.isRedacted()) { // sent and not redacted
134+
const cli = MatrixClientPeg.get();
135+
136+
const room = cli.getRoom(this.props.mxEvent.getRoomId());
137+
const powerLevelEvents = room.currentState.getStateEvents('m.room.power_levels', '');
138+
const powerLevels = powerLevelEvents ? powerLevelEvents.getContent() : {};
139+
const userLevels = powerLevels.users || {};
140+
141+
const userLevel = userLevels[cli.credentials.userId] || parseIntWithDefault(powerLevels.users_default, 0);
142+
143+
if (!eventStatus && !this.props.mxEvent.isRedacted() && (// sent and not redacted
144+
this.props.mxEvent.getSender() === cli.credentials.userId // own event
145+
|| userLevel >= parseIntWithDefault(powerLevels.redact, 50) // has PL to redact
146+
)) {
130147
redactButton = (
131148
<div className="mx_MessageContextMenu_field" onClick={this.onRedactClick}>
132149
Redact

0 commit comments

Comments
 (0)