2019-10-13 15:08:50 +03:00
|
|
|
/*
|
2021-05-01 16:11:30 +03:00
|
|
|
Copyright 2020-2021 Tulir Asokan <tulir@maunium.net>
|
2019-10-13 15:08:50 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-10 15:45:59 +03:00
|
|
|
import React from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
|
|
|
|
|
2021-07-13 08:46:45 +02:00
|
|
|
import MImageBody from "./MImageBody";
|
2021-07-19 18:04:33 +02:00
|
|
|
import { presentableTextForFile } from "../../../utils/FileUtils";
|
2021-07-02 14:17:40 +02:00
|
|
|
import { IMediaEventContent } from "../../../customisations/models/IMediaEventContent";
|
|
|
|
|
import SenderProfile from "./SenderProfile";
|
2021-07-19 18:04:33 +02:00
|
|
|
import { _t } from "../../../languageHandler";
|
2019-10-13 15:08:50 +03:00
|
|
|
|
2021-07-14 09:53:40 +02:00
|
|
|
const FORCED_IMAGE_HEIGHT = 44;
|
|
|
|
|
|
2019-10-13 15:08:50 +03:00
|
|
|
export default class MImageReplyBody extends MImageBody {
|
2021-07-02 14:17:40 +02:00
|
|
|
public onClick = (ev: React.MouseEvent): void => {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public wrapImage(contentUrl: string, children: JSX.Element): JSX.Element {
|
2019-10-13 15:08:50 +03:00
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Don't show "Download this_file.png ..."
|
2021-07-19 18:04:33 +02:00
|
|
|
public getFileBody(): string {
|
|
|
|
|
const sticker = this.props.mxEvent.getType() === EventType.Sticker;
|
|
|
|
|
return presentableTextForFile(this.props.mxEvent.getContent(), sticker ? _t("Sticker") : _t("Image"), !sticker);
|
2020-04-10 15:45:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2022-03-25 16:31:40 +00:00
|
|
|
if (this.state.error) {
|
2020-04-10 15:45:59 +03:00
|
|
|
return super.render();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 08:47:37 +02:00
|
|
|
const content = this.props.mxEvent.getContent<IMediaEventContent>();
|
2022-03-25 16:31:40 +00:00
|
|
|
const thumbnail = this.messageContent(this.state.contentUrl, this.state.thumbUrl, content, FORCED_IMAGE_HEIGHT);
|
2020-04-10 15:45:59 +03:00
|
|
|
const fileBody = this.getFileBody();
|
2021-05-01 16:11:30 +03:00
|
|
|
const sender = <SenderProfile
|
|
|
|
|
mxEvent={this.props.mxEvent}
|
|
|
|
|
/>;
|
2020-04-10 15:45:59 +03:00
|
|
|
|
|
|
|
|
return <div className="mx_MImageReplyBody">
|
2021-07-13 11:49:49 +02:00
|
|
|
{ thumbnail }
|
|
|
|
|
<div className="mx_MImageReplyBody_info">
|
|
|
|
|
<div className="mx_MImageReplyBody_sender">{ sender }</div>
|
|
|
|
|
<div className="mx_MImageReplyBody_filename">{ fileBody }</div>
|
|
|
|
|
</div>
|
2020-04-10 15:45:59 +03:00
|
|
|
</div>;
|
2019-10-13 15:08:50 +03:00
|
|
|
}
|
|
|
|
|
}
|