2018-04-12 01:58:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-07-06 12:42:14 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2021-04-09 09:01:14 +03:00
|
|
|
Copyright 2020, 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-02-24 21:17:33 +03:00
|
|
|
import React, { createRef } from 'react';
|
2018-04-13 02:43:44 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2021-02-24 16:43:33 +03:00
|
|
|
import AccessibleTooltipButton from "./AccessibleTooltipButton";
|
2019-12-16 20:14:03 +03:00
|
|
|
import {Key} from "../../../Keyboard";
|
2020-05-29 03:44:09 +03:00
|
|
|
import FocusLock from "react-focus-lock";
|
2021-02-24 16:43:33 +03:00
|
|
|
import MemberAvatar from "../avatars/MemberAvatar";
|
2021-02-24 21:17:33 +03:00
|
|
|
import {ContextMenuTooltipButton} from "../../../accessibility/context_menu/ContextMenuTooltipButton";
|
|
|
|
import MessageContextMenu from "../context_menus/MessageContextMenu";
|
|
|
|
import {aboveLeftOf, ContextMenu} from '../../structures/ContextMenu';
|
2021-02-24 22:04:25 +03:00
|
|
|
import MessageTimestamp from "../messages/MessageTimestamp";
|
2021-02-24 22:07:41 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2021-02-25 10:20:34 +03:00
|
|
|
import {formatFullDate} from "../../../DateUtils";
|
2021-02-24 22:14:12 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2021-03-09 05:59:41 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2021-04-03 16:06:27 +03:00
|
|
|
import {RoomPermalinkCreator} from "../../../utils/permalinks/Permalinks"
|
|
|
|
import {MatrixEvent} from "matrix-js-sdk/src/models/event";
|
2021-04-22 15:56:35 +03:00
|
|
|
import {normalizeWheelEvent} from "../../../utils/Mouse";
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-24 09:03:39 +03:00
|
|
|
// Max scale to keep gaps around the image
|
|
|
|
const MAX_SCALE = 0.95;
|
2021-03-15 21:28:21 +03:00
|
|
|
// This is used for the buttons
|
2021-04-24 11:35:25 +03:00
|
|
|
const ZOOM_STEP = 0.10;
|
2021-03-15 21:28:21 +03:00
|
|
|
// This is used for mouse wheel events
|
2021-04-24 11:35:25 +03:00
|
|
|
const ZOOM_COEFFICIENT = 0.0025;
|
2021-04-03 17:19:22 +03:00
|
|
|
// If we have moved only this much we can zoom
|
|
|
|
const ZOOM_DISTANCE = 10;
|
2021-02-25 13:19:50 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
interface IProps {
|
|
|
|
src: string, // the source of the image being displayed
|
|
|
|
name?: string, // the main title ('name') for the image
|
|
|
|
link?: string, // the link (if any) applied to the name of the image
|
|
|
|
width?: number, // width of the image src in pixels
|
|
|
|
height?: number, // height of the image src in pixels
|
|
|
|
fileSize?: number, // size of the image src in bytes
|
|
|
|
onFinished(): void, // callback when the lightbox is dismissed
|
|
|
|
|
|
|
|
// the event (if any) that the Image is displaying. Used for event-specific stuff like
|
|
|
|
// redactions, senders, timestamps etc. Other descriptors are taken from the explicit
|
|
|
|
// properties above, which let us use lightboxes to display images which aren't associated
|
|
|
|
// with events.
|
|
|
|
mxEvent: MatrixEvent,
|
|
|
|
permalinkCreator: RoomPermalinkCreator,
|
|
|
|
}
|
2019-03-30 09:31:15 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
interface IState {
|
|
|
|
zoom: number,
|
2021-04-24 09:03:39 +03:00
|
|
|
minZoom: number,
|
2021-04-24 09:32:28 +03:00
|
|
|
maxZoom: number,
|
2021-04-24 09:03:39 +03:00
|
|
|
rotation: number,
|
2021-04-03 16:06:27 +03:00
|
|
|
translationX: number,
|
|
|
|
translationY: number,
|
|
|
|
moving: boolean,
|
|
|
|
contextMenuDisplayed: boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
@replaceableComponent("views.elements.ImageView")
|
|
|
|
export default class ImageView extends React.Component<IProps, IState> {
|
2019-03-30 09:31:15 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-12-19 12:20:15 +03:00
|
|
|
this.state = {
|
2021-04-24 09:03:39 +03:00
|
|
|
zoom: 0,
|
2021-04-24 09:32:28 +03:00
|
|
|
minZoom: MAX_SCALE,
|
2021-04-24 10:24:25 +03:00
|
|
|
maxZoom: MAX_SCALE,
|
2020-12-20 19:40:16 +03:00
|
|
|
rotation: 0,
|
|
|
|
translationX: 0,
|
|
|
|
translationY: 0,
|
|
|
|
moving: false,
|
2021-02-25 13:16:40 +03:00
|
|
|
contextMenuDisplayed: false,
|
2020-12-19 12:20:15 +03:00
|
|
|
};
|
2019-03-30 09:31:15 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-09 09:03:10 +03:00
|
|
|
// XXX: Refs to functional components
|
2021-04-09 09:02:38 +03:00
|
|
|
private contextMenuButton = createRef<any>();
|
|
|
|
private focusLock = createRef<any>();
|
2021-04-26 14:11:41 +03:00
|
|
|
private imageWrapper = createRef<HTMLDivElement>();
|
2021-04-26 14:30:14 +03:00
|
|
|
private image = createRef<HTMLImageElement>();
|
2021-04-03 16:06:27 +03:00
|
|
|
|
2021-04-09 09:02:38 +03:00
|
|
|
private initX = 0;
|
|
|
|
private initY = 0;
|
|
|
|
private lastX = 0;
|
|
|
|
private lastY = 0;
|
|
|
|
private previousX = 0;
|
|
|
|
private previousY = 0;
|
2020-12-20 19:40:16 +03:00
|
|
|
|
2020-12-19 15:30:56 +03:00
|
|
|
componentDidMount() {
|
2021-02-25 09:51:38 +03:00
|
|
|
// We have to use addEventListener() because the listener
|
|
|
|
// needs to be passive in order to work with Chromium
|
2021-04-03 16:06:27 +03:00
|
|
|
this.focusLock.current.addEventListener('wheel', this.onWheel, { passive: false });
|
2021-04-26 14:49:29 +03:00
|
|
|
// We want to recalculate zoom whenever the window's size changes
|
2021-04-24 09:37:51 +03:00
|
|
|
window.addEventListener("resize", this.calculateZoom);
|
2021-04-26 14:30:14 +03:00
|
|
|
// After the image loads for the first time we want to calculate the zoom
|
|
|
|
this.image.current.addEventListener("load", this.calculateZoom);
|
2020-12-19 15:30:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2021-04-03 16:06:27 +03:00
|
|
|
this.focusLock.current.removeEventListener('wheel', this.onWheel);
|
2021-05-04 14:12:22 +03:00
|
|
|
window.removeEventListener("resize", this.calculateZoom);
|
|
|
|
this.image.current.removeEventListener("load", this.calculateZoom);
|
2020-12-19 15:30:56 +03:00
|
|
|
}
|
|
|
|
|
2021-04-24 09:37:51 +03:00
|
|
|
private calculateZoom = () => {
|
2021-04-26 14:30:14 +03:00
|
|
|
const image = this.image.current;
|
2021-04-26 14:11:41 +03:00
|
|
|
const imageWrapper = this.imageWrapper.current;
|
2021-04-24 10:41:46 +03:00
|
|
|
|
2021-05-06 17:41:09 +03:00
|
|
|
const zoomX = imageWrapper.clientWidth / image.naturalWidth;
|
|
|
|
const zoomY = imageWrapper.clientHeight / image.naturalHeight;
|
2021-04-26 14:47:06 +03:00
|
|
|
|
|
|
|
// If the image is smaller in both dimensions set its the zoom to 1 to
|
|
|
|
// display it in its original size
|
|
|
|
if (zoomX >= 1 && zoomY >= 1) {
|
|
|
|
this.setState({
|
|
|
|
zoom: 1,
|
|
|
|
minZoom: 1,
|
|
|
|
maxZoom: 1,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-04-24 10:41:46 +03:00
|
|
|
// We set minZoom to the min of the zoomX and zoomY to avoid overflow in
|
|
|
|
// any direction. We also multiply by MAX_SCALE to get a gap around the
|
|
|
|
// image by default
|
2021-04-24 09:32:28 +03:00
|
|
|
const minZoom = Math.min(zoomX, zoomY) * MAX_SCALE;
|
2021-04-24 09:03:39 +03:00
|
|
|
|
2021-04-24 09:32:28 +03:00
|
|
|
if (this.state.zoom <= this.state.minZoom) this.setState({zoom: minZoom});
|
|
|
|
this.setState({
|
|
|
|
minZoom: minZoom,
|
2021-04-26 14:47:06 +03:00
|
|
|
maxZoom: 1,
|
2021-04-24 09:32:28 +03:00
|
|
|
});
|
2021-04-24 09:03:39 +03:00
|
|
|
}
|
|
|
|
|
2021-04-24 11:36:53 +03:00
|
|
|
private zoom(delta: number) {
|
|
|
|
const newZoom = this.state.zoom + delta;
|
2020-12-20 19:40:16 +03:00
|
|
|
|
2021-04-24 09:32:28 +03:00
|
|
|
if (newZoom <= this.state.minZoom) {
|
2020-12-19 12:20:15 +03:00
|
|
|
this.setState({
|
2021-04-24 09:32:28 +03:00
|
|
|
zoom: this.state.minZoom,
|
2020-12-20 22:09:01 +03:00
|
|
|
translationX: 0,
|
|
|
|
translationY: 0,
|
2020-12-19 12:20:15 +03:00
|
|
|
});
|
2020-12-20 22:09:01 +03:00
|
|
|
return;
|
2020-12-19 12:20:15 +03:00
|
|
|
}
|
2021-04-24 09:32:28 +03:00
|
|
|
if (newZoom >= this.state.maxZoom) {
|
|
|
|
this.setState({zoom: this.state.maxZoom});
|
2020-12-20 22:28:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-20 22:09:01 +03:00
|
|
|
this.setState({
|
|
|
|
zoom: newZoom,
|
|
|
|
});
|
2021-04-24 11:36:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private onWheel = (ev: WheelEvent) => {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
const {deltaY} = normalizeWheelEvent(ev);
|
|
|
|
this.zoom(-(deltaY * ZOOM_COEFFICIENT));
|
|
|
|
};
|
|
|
|
|
|
|
|
private onZoomInClick = () => {
|
|
|
|
this.zoom(ZOOM_STEP);
|
|
|
|
};
|
|
|
|
|
|
|
|
private onZoomOutClick = () => {
|
|
|
|
this.zoom(-ZOOM_STEP);
|
|
|
|
};
|
|
|
|
|
|
|
|
private onKeyDown = (ev: KeyboardEvent) => {
|
|
|
|
if (ev.key === Key.ESCAPE) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
this.props.onFinished();
|
|
|
|
}
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2020-12-19 12:20:15 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onRotateCounterClockwiseClick = () => {
|
2020-12-20 19:40:16 +03:00
|
|
|
const cur = this.state.rotation;
|
2021-04-09 09:16:52 +03:00
|
|
|
const rotationDegrees = cur - 90;
|
2020-12-20 19:40:16 +03:00
|
|
|
this.setState({ rotation: rotationDegrees });
|
2019-03-30 09:31:15 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onRotateClockwiseClick = () => {
|
2020-12-20 19:40:16 +03:00
|
|
|
const cur = this.state.rotation;
|
2021-04-09 09:16:52 +03:00
|
|
|
const rotationDegrees = cur + 90;
|
2020-12-20 19:40:16 +03:00
|
|
|
this.setState({ rotation: rotationDegrees });
|
2019-03-30 09:31:15 +03:00
|
|
|
};
|
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onDownloadClick = () => {
|
2021-02-24 18:28:12 +03:00
|
|
|
const a = document.createElement("a");
|
|
|
|
a.href = this.props.src;
|
|
|
|
a.download = this.props.name;
|
2021-04-13 09:15:42 +03:00
|
|
|
a.target = "_blank";
|
2021-05-14 05:55:14 +03:00
|
|
|
a.rel = "noreferrer noopener";
|
2021-02-24 18:28:12 +03:00
|
|
|
a.click();
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2021-02-24 18:28:12 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onOpenContextMenu = () => {
|
2021-02-24 21:17:33 +03:00
|
|
|
this.setState({
|
2021-02-25 13:16:40 +03:00
|
|
|
contextMenuDisplayed: true,
|
2021-02-24 21:17:33 +03:00
|
|
|
});
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2021-02-24 21:17:33 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onCloseContextMenu = () => {
|
2021-02-24 21:17:33 +03:00
|
|
|
this.setState({
|
2021-02-25 13:16:40 +03:00
|
|
|
contextMenuDisplayed: false,
|
2021-02-24 21:17:33 +03:00
|
|
|
});
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2021-02-24 21:17:33 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onPermalinkClicked = (ev: React.MouseEvent) => {
|
2021-02-24 22:14:12 +03:00
|
|
|
// This allows the permalink to be opened in a new tab/window or copied as
|
|
|
|
// matrix.to, but also for it to enable routing within Element when clicked.
|
2021-02-25 13:23:14 +03:00
|
|
|
ev.preventDefault();
|
2021-02-24 22:14:12 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
event_id: this.props.mxEvent.getId(),
|
|
|
|
highlighted: true,
|
|
|
|
room_id: this.props.mxEvent.getRoomId(),
|
|
|
|
});
|
2021-02-25 10:13:27 +03:00
|
|
|
this.props.onFinished();
|
2021-02-24 22:14:12 +03:00
|
|
|
};
|
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onStartMoving = (ev: React.MouseEvent) => {
|
2020-12-20 19:40:16 +03:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-15 09:10:03 +03:00
|
|
|
// Don't do anything if we pressed any
|
|
|
|
// other button than the left one
|
|
|
|
if (ev.button !== 0) return;
|
|
|
|
|
2021-04-02 11:37:42 +03:00
|
|
|
// Zoom in if we are completely zoomed out
|
2021-04-24 09:32:28 +03:00
|
|
|
if (this.state.zoom === this.state.minZoom) {
|
|
|
|
this.setState({zoom: this.state.maxZoom});
|
2021-04-02 11:37:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-20 19:40:16 +03:00
|
|
|
this.setState({moving: true});
|
2021-04-02 11:01:41 +03:00
|
|
|
this.previousX = this.state.translationX;
|
|
|
|
this.previousY = this.state.translationY;
|
2020-12-20 19:40:16 +03:00
|
|
|
this.initX = ev.pageX - this.lastX;
|
|
|
|
this.initY = ev.pageY - this.lastY;
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onMoving = (ev: React.MouseEvent) => {
|
2020-12-20 19:40:16 +03:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-02 11:22:10 +03:00
|
|
|
if (!this.state.moving) return;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2020-12-20 19:40:16 +03:00
|
|
|
this.lastX = ev.pageX - this.initX;
|
|
|
|
this.lastY = ev.pageY - this.initY;
|
|
|
|
this.setState({
|
|
|
|
translationX: this.lastX,
|
|
|
|
translationY: this.lastY,
|
|
|
|
});
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2020-12-20 19:40:16 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private onEndMoving = () => {
|
2021-04-02 11:37:42 +03:00
|
|
|
// Zoom out if we haven't moved much
|
2021-04-02 11:01:41 +03:00
|
|
|
if (
|
|
|
|
this.state.moving === true &&
|
2021-04-03 17:19:22 +03:00
|
|
|
Math.abs(this.state.translationX - this.previousX) < ZOOM_DISTANCE &&
|
|
|
|
Math.abs(this.state.translationY - this.previousY) < ZOOM_DISTANCE
|
2021-04-02 11:01:41 +03:00
|
|
|
) {
|
2021-04-02 11:37:42 +03:00
|
|
|
this.setState({
|
2021-04-24 09:32:28 +03:00
|
|
|
zoom: this.state.minZoom,
|
2021-04-02 11:37:42 +03:00
|
|
|
translationX: 0,
|
|
|
|
translationY: 0,
|
|
|
|
});
|
2021-04-02 11:01:41 +03:00
|
|
|
}
|
2020-12-20 19:40:16 +03:00
|
|
|
this.setState({moving: false});
|
2021-04-03 16:06:27 +03:00
|
|
|
};
|
2020-12-20 19:40:16 +03:00
|
|
|
|
2021-04-03 16:06:27 +03:00
|
|
|
private renderContextMenu() {
|
2021-02-24 21:17:33 +03:00
|
|
|
let contextMenu = null;
|
2021-02-25 13:16:40 +03:00
|
|
|
if (this.state.contextMenuDisplayed) {
|
2021-02-24 21:17:33 +03:00
|
|
|
contextMenu = (
|
|
|
|
<ContextMenu
|
|
|
|
{...aboveLeftOf(this.contextMenuButton.current.getBoundingClientRect())}
|
|
|
|
onFinished={this.onCloseContextMenu}
|
|
|
|
>
|
|
|
|
<MessageContextMenu
|
|
|
|
mxEvent={this.props.mxEvent}
|
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
|
|
|
onFinished={this.onCloseContextMenu}
|
2021-04-02 09:17:05 +03:00
|
|
|
onCloseDialog={this.props.onFinished}
|
2021-02-24 21:17:33 +03:00
|
|
|
/>
|
|
|
|
</ContextMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{ contextMenu }
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-20 19:40:16 +03:00
|
|
|
render() {
|
|
|
|
const showEventMeta = !!this.props.mxEvent;
|
2021-04-26 16:47:58 +03:00
|
|
|
const zoomingDisabled = this.state.maxZoom === this.state.minZoom;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-04-02 11:01:41 +03:00
|
|
|
let cursor;
|
|
|
|
if (this.state.moving) {
|
|
|
|
cursor= "grabbing";
|
2021-04-26 16:47:58 +03:00
|
|
|
} else if (zoomingDisabled) {
|
2021-04-26 16:01:06 +03:00
|
|
|
cursor = "default";
|
2021-04-24 09:32:28 +03:00
|
|
|
} else if (this.state.zoom === this.state.minZoom) {
|
2021-04-02 11:01:41 +03:00
|
|
|
cursor = "zoom-in";
|
|
|
|
} else {
|
|
|
|
cursor = "zoom-out";
|
|
|
|
}
|
2020-12-20 19:40:16 +03:00
|
|
|
const rotationDegrees = this.state.rotation + "deg";
|
2021-04-24 09:35:45 +03:00
|
|
|
const zoom = this.state.zoom;
|
2020-12-20 19:40:16 +03:00
|
|
|
const translatePixelsX = this.state.translationX + "px";
|
|
|
|
const translatePixelsY = this.state.translationY + "px";
|
2021-02-25 09:51:38 +03:00
|
|
|
// The order of the values is important!
|
|
|
|
// First, we translate and only then we rotate, otherwise
|
|
|
|
// we would apply the translation to an already rotated
|
|
|
|
// image causing it translate in the wrong direction.
|
2020-12-20 19:40:16 +03:00
|
|
|
const style = {
|
2021-04-02 11:01:41 +03:00
|
|
|
cursor: cursor,
|
2021-04-02 11:09:53 +03:00
|
|
|
transition: this.state.moving ? null : "transform 200ms ease 0s",
|
2020-12-20 22:00:11 +03:00
|
|
|
transform: `translateX(${translatePixelsX})
|
|
|
|
translateY(${translatePixelsY})
|
2021-04-24 09:35:45 +03:00
|
|
|
scale(${zoom})
|
2020-12-20 22:00:11 +03:00
|
|
|
rotate(${rotationDegrees})`,
|
2020-12-20 19:40:16 +03:00
|
|
|
};
|
2019-03-30 09:31:15 +03:00
|
|
|
|
2021-02-24 20:24:44 +03:00
|
|
|
let info;
|
2021-02-24 22:04:25 +03:00
|
|
|
if (showEventMeta) {
|
|
|
|
const mxEvent = this.props.mxEvent;
|
2021-02-24 22:07:41 +03:00
|
|
|
const showTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps");
|
2021-02-24 22:14:12 +03:00
|
|
|
let permalink = "#";
|
|
|
|
if (this.props.permalinkCreator) {
|
|
|
|
permalink = this.props.permalinkCreator.forEvent(this.props.mxEvent.getId());
|
|
|
|
}
|
2021-02-24 22:04:25 +03:00
|
|
|
|
|
|
|
const senderName = mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender();
|
2021-04-02 09:31:42 +03:00
|
|
|
const sender = (
|
|
|
|
<div className="mx_ImageView_info_sender">
|
|
|
|
{senderName}
|
|
|
|
</div>
|
|
|
|
);
|
2021-02-24 22:04:25 +03:00
|
|
|
const messageTimestamp = (
|
2021-02-24 22:14:12 +03:00
|
|
|
<a
|
|
|
|
href={permalink}
|
|
|
|
onClick={this.onPermalinkClicked}
|
2021-04-03 16:06:27 +03:00
|
|
|
aria-label={formatFullDate(new Date(this.props.mxEvent.getTs()), showTwelveHour, false)}
|
2021-02-24 22:14:12 +03:00
|
|
|
>
|
2021-04-03 16:06:27 +03:00
|
|
|
<MessageTimestamp
|
|
|
|
showFullDate={true}
|
|
|
|
showTwelveHour={showTwelveHour}
|
|
|
|
ts={mxEvent.getTs()}
|
|
|
|
showSeconds={false}
|
|
|
|
/>
|
2021-02-24 22:14:12 +03:00
|
|
|
</a>
|
2021-02-24 22:04:25 +03:00
|
|
|
);
|
|
|
|
const avatar = (
|
|
|
|
<MemberAvatar
|
|
|
|
member={mxEvent.sender}
|
|
|
|
width={32} height={32}
|
|
|
|
viewUserOnClick={true}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-02-24 20:24:44 +03:00
|
|
|
info = (
|
|
|
|
<div className="mx_ImageView_info_wrapper">
|
2021-02-24 22:04:25 +03:00
|
|
|
{avatar}
|
2021-02-24 20:24:44 +03:00
|
|
|
<div className="mx_ImageView_info">
|
2021-04-02 09:31:42 +03:00
|
|
|
{sender}
|
2021-02-24 22:04:25 +03:00
|
|
|
{messageTimestamp}
|
2021-02-24 20:24:44 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// If there is no event - we're viewing an avatar, we set
|
|
|
|
// an empty div here, since the panel uses space-between
|
|
|
|
// and we want the same placement of elements
|
|
|
|
info = (
|
|
|
|
<div></div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:11:09 +03:00
|
|
|
let contextMenuButton;
|
|
|
|
if (this.props.mxEvent) {
|
|
|
|
contextMenuButton = (
|
|
|
|
<ContextMenuTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_more"
|
|
|
|
title={_t("Options")}
|
|
|
|
onClick={this.onOpenContextMenu}
|
|
|
|
inputRef={this.contextMenuButton}
|
|
|
|
isExpanded={this.state.contextMenuDisplayed}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-26 16:47:58 +03:00
|
|
|
let zoomOutButton;
|
|
|
|
let zoomInButton;
|
|
|
|
if (!zoomingDisabled) {
|
|
|
|
zoomOutButton = (
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_zoomOut"
|
|
|
|
title={_t("Zoom out")}
|
|
|
|
onClick={this.onZoomOutClick}>
|
|
|
|
</AccessibleTooltipButton>
|
|
|
|
);
|
|
|
|
zoomInButton = (
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_zoomIn"
|
|
|
|
title={_t("Zoom in")}
|
|
|
|
onClick={ this.onZoomInClick }>
|
|
|
|
</AccessibleTooltipButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
return (
|
2020-05-29 03:44:09 +03:00
|
|
|
<FocusLock
|
|
|
|
returnFocus={true}
|
|
|
|
lockProps={{
|
|
|
|
onKeyDown: this.onKeyDown,
|
|
|
|
role: "dialog",
|
|
|
|
}}
|
|
|
|
className="mx_ImageView"
|
2021-04-03 16:06:27 +03:00
|
|
|
ref={this.focusLock}
|
2020-05-29 03:44:09 +03:00
|
|
|
>
|
2021-04-03 16:06:27 +03:00
|
|
|
<div className="mx_ImageView_panel">
|
|
|
|
{info}
|
|
|
|
<div className="mx_ImageView_toolbar">
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_rotateCCW"
|
|
|
|
title={_t("Rotate Left")}
|
|
|
|
onClick={ this.onRotateCounterClockwiseClick }>
|
|
|
|
</AccessibleTooltipButton>
|
2021-05-14 05:50:07 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_rotateCW"
|
|
|
|
title={_t("Rotate Right")}
|
|
|
|
onClick={this.onRotateClockwiseClick}>
|
|
|
|
</AccessibleTooltipButton>
|
2021-04-26 16:47:58 +03:00
|
|
|
{zoomOutButton}
|
|
|
|
{zoomInButton}
|
2021-04-03 16:06:27 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_download"
|
|
|
|
title={_t("Download")}
|
|
|
|
onClick={ this.onDownloadClick }>
|
|
|
|
</AccessibleTooltipButton>
|
2021-04-13 09:11:09 +03:00
|
|
|
{contextMenuButton}
|
2021-04-03 16:06:27 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_ImageView_button mx_ImageView_button_close"
|
|
|
|
title={_t("Close")}
|
|
|
|
onClick={ this.props.onFinished }>
|
|
|
|
</AccessibleTooltipButton>
|
|
|
|
{this.renderContextMenu()}
|
2021-02-24 13:15:59 +03:00
|
|
|
</div>
|
2021-04-03 16:06:27 +03:00
|
|
|
</div>
|
2021-04-26 14:11:41 +03:00
|
|
|
<div
|
|
|
|
className="mx_ImageView_image_wrapper"
|
|
|
|
ref={this.imageWrapper}>
|
2021-04-03 16:06:27 +03:00
|
|
|
<img
|
|
|
|
src={this.props.src}
|
|
|
|
title={this.props.name}
|
|
|
|
style={style}
|
2021-04-26 14:30:14 +03:00
|
|
|
ref={this.image}
|
2021-04-03 16:06:27 +03:00
|
|
|
className="mx_ImageView_image"
|
|
|
|
draggable={true}
|
|
|
|
onMouseDown={this.onStartMoving}
|
|
|
|
onMouseMove={this.onMoving}
|
|
|
|
onMouseUp={this.onEndMoving}
|
|
|
|
onMouseLeave={this.onEndMoving}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-05-29 03:44:09 +03:00
|
|
|
</FocusLock>
|
2018-04-12 01:58:04 +03:00
|
|
|
);
|
2019-03-30 09:31:15 +03:00
|
|
|
}
|
|
|
|
}
|