Merge pull request #3191 from matrix-org/t3chguy/lightbox_remove_no_pl

Don't show Remove button in ImageView if can't redact, delint ImageView
This commit is contained in:
Michael Telatynski 2019-07-08 10:23:51 +01:00 committed by GitHub
commit dd27891ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View file

@ -17,7 +17,6 @@ src/components/views/dialogs/SetPasswordDialog.js
src/components/views/dialogs/UnknownDeviceDialog.js src/components/views/dialogs/UnknownDeviceDialog.js
src/components/views/elements/AddressSelector.js src/components/views/elements/AddressSelector.js
src/components/views/elements/DirectorySearchBox.js src/components/views/elements/DirectorySearchBox.js
src/components/views/elements/ImageView.js
src/components/views/elements/MemberEventListSummary.js src/components/views/elements/MemberEventListSummary.js
src/components/views/elements/TintableSvg.js src/components/views/elements/TintableSvg.js
src/components/views/elements/UserSelector.js src/components/views/elements/UserSelector.js

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -60,7 +61,7 @@ export default class ImageView extends React.Component {
} }
onKeyDown = (ev) => { onKeyDown = (ev) => {
if (ev.keyCode == 27) { // escape if (ev.keyCode === 27) { // escape
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
this.props.onFinished(); this.props.onFinished();
@ -72,7 +73,6 @@ export default class ImageView extends React.Component {
Modal.createTrackedDialog('Confirm Redact Dialog', 'Image View', ConfirmRedactDialog, { Modal.createTrackedDialog('Confirm Redact Dialog', 'Image View', ConfirmRedactDialog, {
onFinished: (proceed) => { onFinished: (proceed) => {
if (!proceed) return; if (!proceed) return;
const self = this;
MatrixClientPeg.get().redactEvent( MatrixClientPeg.get().redactEvent(
this.props.mxEvent.getRoomId(), this.props.mxEvent.getId(), this.props.mxEvent.getRoomId(), this.props.mxEvent.getId(),
).catch(function(e) { ).catch(function(e) {
@ -153,32 +153,38 @@ export default class ImageView extends React.Component {
size = filesize(this.props.fileSize); size = filesize(this.props.fileSize);
} }
let size_res; let sizeRes;
if (size && res) { if (size && res) {
size_res = size + ", " + res; sizeRes = size + ", " + res;
} else { } else {
size_res = size || res; sizeRes = size || res;
} }
let mayRedact = false;
const showEventMeta = !!this.props.mxEvent; const showEventMeta = !!this.props.mxEvent;
let eventMeta; let eventMeta;
if (showEventMeta) { if (showEventMeta) {
// Figure out the sender, defaulting to mxid // Figure out the sender, defaulting to mxid
let sender = this.props.mxEvent.getSender(); let sender = this.props.mxEvent.getSender();
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); const cli = MatrixClientPeg.get();
const room = cli.getRoom(this.props.mxEvent.getRoomId());
if (room) { if (room) {
mayRedact = room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId);
const member = room.getMember(sender); const member = room.getMember(sender);
if (member) sender = member.name; if (member) sender = member.name;
} }
eventMeta = (<div className="mx_ImageView_metadata"> eventMeta = (<div className="mx_ImageView_metadata">
{ _t('Uploaded on %(date)s by %(user)s', {date: formatDate(new Date(this.props.mxEvent.getTs())), user: sender}) } { _t('Uploaded on %(date)s by %(user)s', {
date: formatDate(new Date(this.props.mxEvent.getTs())),
user: sender,
}) }
</div>); </div>);
} }
let eventRedact; let eventRedact;
if (showEventMeta) { if (mayRedact) {
eventRedact = (<div className="mx_ImageView_button" onClick={this.onRedactClick}> eventRedact = (<div className="mx_ImageView_button" onClick={this.onRedactClick}>
{ _t('Remove') } { _t('Remove') }
</div>); </div>);
@ -213,7 +219,7 @@ export default class ImageView extends React.Component {
<a className="mx_ImageView_link" href={ this.props.src } download={ this.props.name } target="_blank" rel="noopener"> <a className="mx_ImageView_link" href={ this.props.src } download={ this.props.name } target="_blank" rel="noopener">
<div className="mx_ImageView_download"> <div className="mx_ImageView_download">
{ _t('Download this file') }<br /> { _t('Download this file') }<br />
<span className="mx_ImageView_size">{ size_res }</span> <span className="mx_ImageView_size">{ sizeRes }</span>
</div> </div>
</a> </a>
{ eventRedact } { eventRedact }