2018-04-03 22:56:12 +00:00
|
|
|
import React from 'react';
|
2018-04-10 01:31:52 +00:00
|
|
|
import classnames from 'classnames';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-04-10 01:31:52 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import Mime from '../../../js/modules/types/mime';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
|
|
|
|
2018-04-10 01:31:52 +00:00
|
|
|
interface Props {
|
2018-04-12 06:55:32 +00:00
|
|
|
attachments: Array<QuotedAttachment>;
|
2018-04-12 07:33:52 +00:00
|
|
|
authorColor: string;
|
|
|
|
authorProfileName?: string;
|
|
|
|
authorTitle: string;
|
|
|
|
i18n: (key: string, values?: Array<string>) => string;
|
2018-04-12 19:21:37 +00:00
|
|
|
isFromMe: string;
|
2018-04-12 07:33:52 +00:00
|
|
|
isIncoming: boolean;
|
2018-04-12 19:21:37 +00:00
|
|
|
onClick?: () => void;
|
2018-04-18 20:06:33 +00:00
|
|
|
onClose?: () => void;
|
2018-04-12 07:33:52 +00:00
|
|
|
text: string;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface QuotedAttachment {
|
|
|
|
contentType: string;
|
2018-04-12 07:33:52 +00:00
|
|
|
fileName: string;
|
2018-04-12 06:55:32 +00:00
|
|
|
/* Not included in protobuf */
|
2018-04-10 01:31:52 +00:00
|
|
|
isVoiceMessage: boolean;
|
2018-04-12 07:33:52 +00:00
|
|
|
thumbnail?: Attachment;
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Attachment {
|
|
|
|
contentType: string;
|
|
|
|
/* Not included in protobuf, and is loaded asynchronously */
|
|
|
|
objectUrl?: string;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateQuote(quote: Props): boolean {
|
|
|
|
if (quote.text) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quote.attachments && quote.attachments.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
function getObjectUrl(thumbnail: Attachment | undefined): string | null {
|
|
|
|
if (thumbnail && thumbnail.objectUrl) {
|
|
|
|
return thumbnail.objectUrl;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
return null;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Quote extends React.Component<Props, {}> {
|
2018-04-12 06:55:32 +00:00
|
|
|
public renderImage(url: string, icon?: string) {
|
2018-04-12 07:33:52 +00:00
|
|
|
const iconElement = icon
|
2018-04-12 19:49:01 +00:00
|
|
|
? <div className={classnames('icon', 'with-image', icon)} />
|
2018-04-12 07:33:52 +00:00
|
|
|
: null;
|
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
return (
|
|
|
|
<div className="icon-container">
|
|
|
|
<div className="inner">
|
|
|
|
<img src={url} />
|
2018-04-12 07:33:52 +00:00
|
|
|
{iconElement}
|
2018-04-12 06:55:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
public renderIcon(icon: string) {
|
2018-04-12 19:21:37 +00:00
|
|
|
const { authorColor, isIncoming } = this.props;
|
2018-04-12 06:55:32 +00:00
|
|
|
|
|
|
|
const backgroundColor = isIncoming ? 'white' : authorColor;
|
2018-04-12 19:21:37 +00:00
|
|
|
const iconColor = isIncoming ? authorColor : 'white';
|
2018-04-12 06:55:32 +00:00
|
|
|
|
|
|
|
return (
|
2018-04-12 07:33:52 +00:00
|
|
|
<div className="icon-container">
|
|
|
|
<div className={classnames('circle-background', backgroundColor)} />
|
|
|
|
<div className={classnames('icon', icon, iconColor)} />
|
2018-04-12 06:55:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public renderIconContainer() {
|
|
|
|
const { attachments } = this.props;
|
|
|
|
if (!attachments || attachments.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const first = attachments[0];
|
2018-04-12 06:55:32 +00:00
|
|
|
const { contentType, thumbnail } = first;
|
|
|
|
const objectUrl = getObjectUrl(thumbnail);
|
|
|
|
|
|
|
|
if (Mime.isVideo(contentType)) {
|
|
|
|
return objectUrl
|
|
|
|
? this.renderImage(objectUrl, 'play')
|
|
|
|
: this.renderIcon('play');
|
|
|
|
}
|
|
|
|
if (Mime.isImage(contentType)) {
|
|
|
|
return objectUrl
|
|
|
|
? this.renderImage(objectUrl)
|
|
|
|
: this.renderIcon('image');
|
|
|
|
}
|
|
|
|
if (Mime.isAudio(contentType)) {
|
|
|
|
return this.renderIcon('microphone');
|
|
|
|
}
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
return this.renderIcon('file');
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public renderText() {
|
|
|
|
const { i18n, text, attachments } = this.props;
|
|
|
|
|
|
|
|
if (text) {
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="text">{text}</div>;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!attachments || attachments.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const first = attachments[0];
|
2018-04-12 06:55:32 +00:00
|
|
|
const { contentType, fileName, isVoiceMessage } = first;
|
2018-04-10 01:31:52 +00:00
|
|
|
|
|
|
|
if (Mime.isVideo(contentType)) {
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="type-label">{i18n('video')}</div>;
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
|
|
|
if (Mime.isImage(contentType)) {
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="type-label">{i18n('photo')}</div>;
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
|
|
|
if (Mime.isAudio(contentType) && isVoiceMessage) {
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="type-label">{i18n('voiceMessage')}</div>;
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
|
|
|
if (Mime.isAudio(contentType)) {
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="type-label">{i18n('audio')}</div>;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 07:33:52 +00:00
|
|
|
return <div className="filename-label">{fileName}</div>;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-04-12 19:21:37 +00:00
|
|
|
public renderIOSLabel() {
|
|
|
|
const { i18n, isIncoming, isFromMe, authorTitle, authorProfileName } = this.props;
|
|
|
|
|
|
|
|
const profileString = authorProfileName ? ` ~${authorProfileName}` : '';
|
|
|
|
const authorName = `${authorTitle}${profileString}`;
|
|
|
|
|
|
|
|
const label = isFromMe
|
|
|
|
? isIncoming
|
|
|
|
? i18n('replyingToYou')
|
|
|
|
: i18n('replyingToYourself')
|
|
|
|
: i18n('replyingTo', [authorName]);
|
|
|
|
|
2018-04-13 00:00:21 +00:00
|
|
|
return <div className="ios-label">{label}</div>;
|
2018-04-12 19:21:37 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 20:06:33 +00:00
|
|
|
public renderClose() {
|
|
|
|
const { onClose } = this.props;
|
|
|
|
|
|
|
|
if (!onClose) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need the container to give us the flexibility to implement the iOS design.
|
|
|
|
return (
|
2018-04-18 21:48:57 +00:00
|
|
|
<div className="close-container">
|
2018-04-18 20:06:33 +00:00
|
|
|
<div className="close-button" onClick={onClose}></div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:56:12 +00:00
|
|
|
public render() {
|
2018-04-12 06:55:32 +00:00
|
|
|
const {
|
|
|
|
authorTitle,
|
|
|
|
authorProfileName,
|
|
|
|
authorColor,
|
2018-04-12 19:21:37 +00:00
|
|
|
onClick,
|
|
|
|
isFromMe,
|
2018-04-12 06:55:32 +00:00
|
|
|
} = this.props;
|
2018-04-10 01:31:52 +00:00
|
|
|
|
|
|
|
if (!validateQuote(this.props)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-04-12 07:33:52 +00:00
|
|
|
const authorProfileElement = authorProfileName
|
|
|
|
? <span className="profile-name">~{authorProfileName}</span>
|
|
|
|
: null;
|
2018-04-13 00:00:21 +00:00
|
|
|
const classes = classnames(
|
|
|
|
authorColor,
|
2018-04-18 18:24:49 +00:00
|
|
|
'quoted-message',
|
2018-04-13 00:00:21 +00:00
|
|
|
isFromMe ? 'from-me' : null,
|
2018-04-13 22:49:05 +00:00
|
|
|
!onClick ? 'no-click' : null,
|
2018-04-13 00:00:21 +00:00
|
|
|
);
|
2018-04-12 07:33:52 +00:00
|
|
|
|
2018-04-03 22:56:12 +00:00
|
|
|
return (
|
2018-04-13 00:00:21 +00:00
|
|
|
<div onClick={onClick} className={classes}>
|
2018-04-10 01:31:52 +00:00
|
|
|
<div className="primary">
|
2018-04-12 19:21:37 +00:00
|
|
|
{this.renderIOSLabel()}
|
2018-04-12 06:55:32 +00:00
|
|
|
<div className={classnames(authorColor, 'author')}>
|
2018-04-12 07:33:52 +00:00
|
|
|
{authorTitle}{' '}{authorProfileElement}
|
2018-04-12 06:55:32 +00:00
|
|
|
</div>
|
2018-04-10 01:31:52 +00:00
|
|
|
{this.renderText()}
|
|
|
|
</div>
|
|
|
|
{this.renderIconContainer()}
|
2018-04-18 20:06:33 +00:00
|
|
|
{this.renderClose()}
|
2018-04-10 01:31:52 +00:00
|
|
|
</div>
|
2018-04-03 22:56:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|