2018-04-03 22:56:12 +00:00
|
|
|
import React from 'react';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
import {
|
|
|
|
isImageTypeSupported,
|
|
|
|
isVideoTypeSupported,
|
|
|
|
} from '../../util/GoogleChrome';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
import { MessageBody } from './MessageBody';
|
2018-07-09 21:29:13 +00:00
|
|
|
import { ExpireTimer, getIncrement } from './ExpireTimer';
|
|
|
|
import { Timestamp } from './Timestamp';
|
|
|
|
import { ContactName } from './ContactName';
|
2018-06-27 20:53:49 +00:00
|
|
|
import { Quote, QuotedAttachment } from './Quote';
|
|
|
|
import { EmbeddedContact } from './EmbeddedContact';
|
|
|
|
|
|
|
|
import { Contact } from '../../types/Contact';
|
2018-07-09 21:29:13 +00:00
|
|
|
import { Color, Localizer } from '../../types/Util';
|
|
|
|
import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
import * as MIME from '../../../ts/types/MIME';
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
interface Trigger {
|
|
|
|
handleContextClick: (event: React.MouseEvent<HTMLDivElement>) => void;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
interface Attachment {
|
|
|
|
contentType: MIME.MIMEType;
|
|
|
|
fileName: string;
|
|
|
|
/** Not included in protobuf, needs to be pulled from flags */
|
|
|
|
isVoiceMessage: boolean;
|
|
|
|
/** For messages not already on disk, this will be a data url */
|
|
|
|
url: string;
|
|
|
|
fileSize?: string;
|
2018-07-09 21:29:13 +00:00
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
screenshot?: {
|
|
|
|
height: number;
|
|
|
|
width: number;
|
|
|
|
url: string;
|
|
|
|
contentType: MIME.MIMEType;
|
|
|
|
};
|
|
|
|
thumbnail?: {
|
|
|
|
height: number;
|
|
|
|
width: number;
|
|
|
|
url: string;
|
|
|
|
contentType: MIME.MIMEType;
|
|
|
|
};
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
export interface Props {
|
|
|
|
disableMenu?: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
text?: string;
|
|
|
|
id?: string;
|
|
|
|
collapseMetadata?: boolean;
|
|
|
|
direction: 'incoming' | 'outgoing';
|
|
|
|
timestamp: number;
|
2018-07-09 21:29:13 +00:00
|
|
|
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
|
|
|
|
// What if changed this over to a single contact like quote, and put the events on it?
|
|
|
|
contact?: Contact & {
|
|
|
|
hasSignalAccount: boolean;
|
|
|
|
onSendMessage?: () => void;
|
|
|
|
onClick?: () => void;
|
|
|
|
};
|
2018-06-27 20:53:49 +00:00
|
|
|
i18n: Localizer;
|
|
|
|
authorName?: string;
|
|
|
|
authorProfileName?: string;
|
|
|
|
/** Note: this should be formatted for display */
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber: string;
|
|
|
|
authorColor: Color;
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType: 'group' | 'direct';
|
|
|
|
attachment?: Attachment;
|
|
|
|
quote?: {
|
|
|
|
text: string;
|
2018-07-09 21:29:13 +00:00
|
|
|
attachment?: QuotedAttachment;
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe: boolean;
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber: string;
|
2018-06-27 20:53:49 +00:00
|
|
|
authorProfileName?: string;
|
2018-07-09 21:29:13 +00:00
|
|
|
authorName?: string;
|
|
|
|
authorColor: Color;
|
|
|
|
onClick?: () => void;
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
};
|
|
|
|
authorAvatarPath?: string;
|
2018-08-09 23:18:10 +00:00
|
|
|
isExpired: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
expirationLength?: number;
|
|
|
|
expirationTimestamp?: number;
|
|
|
|
onClickAttachment?: () => void;
|
2018-07-09 21:29:13 +00:00
|
|
|
onReply?: () => void;
|
|
|
|
onRetrySend?: () => void;
|
|
|
|
onDownload?: () => void;
|
|
|
|
onDelete?: () => void;
|
|
|
|
onShowDetail: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
expiring: boolean;
|
|
|
|
expired: boolean;
|
|
|
|
imageBroken: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isImage(attachment?: Attachment) {
|
|
|
|
return (
|
2018-07-07 00:48:14 +00:00
|
|
|
attachment &&
|
|
|
|
attachment.contentType &&
|
|
|
|
isImageTypeSupported(attachment.contentType)
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
function hasImage(attachment?: Attachment) {
|
|
|
|
return attachment && attachment.url;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
function isVideo(attachment?: Attachment) {
|
|
|
|
return (
|
2018-07-07 00:48:14 +00:00
|
|
|
attachment &&
|
|
|
|
attachment.contentType &&
|
|
|
|
isVideoTypeSupported(attachment.contentType)
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
function hasVideoScreenshot(attachment?: Attachment) {
|
|
|
|
return attachment && attachment.screenshot && attachment.screenshot.url;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
function isAudio(attachment?: Attachment) {
|
|
|
|
return (
|
|
|
|
attachment && attachment.contentType && MIME.isAudio(attachment.contentType)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
function getInitial(name: string): string {
|
|
|
|
return name.trim()[0] || '#';
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getExtension({
|
|
|
|
fileName,
|
|
|
|
contentType,
|
|
|
|
}: {
|
|
|
|
fileName: string;
|
|
|
|
contentType: MIME.MIMEType;
|
|
|
|
}): string | null {
|
|
|
|
if (fileName && fileName.indexOf('.') >= 0) {
|
|
|
|
const lastPeriod = fileName.lastIndexOf('.');
|
|
|
|
const extension = fileName.slice(lastPeriod + 1);
|
|
|
|
if (extension.length) {
|
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const slash = contentType.indexOf('/');
|
|
|
|
if (slash >= 0) {
|
|
|
|
return contentType.slice(slash + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const MINIMUM_IMG_HEIGHT = 150;
|
|
|
|
const MAXIMUM_IMG_HEIGHT = 300;
|
|
|
|
const EXPIRATION_CHECK_MINIMUM = 2000;
|
|
|
|
const EXPIRED_DELAY = 600;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
export class Message extends React.Component<Props, State> {
|
|
|
|
public captureMenuTriggerBound: (trigger: any) => void;
|
|
|
|
public showMenuBound: (event: React.MouseEvent<HTMLDivElement>) => void;
|
|
|
|
public handleImageErrorBound: () => void;
|
|
|
|
|
|
|
|
public menuTriggerRef: Trigger | null;
|
|
|
|
public expirationCheckInterval: any;
|
|
|
|
public expiredTimeout: any;
|
|
|
|
|
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.captureMenuTriggerBound = this.captureMenuTrigger.bind(this);
|
|
|
|
this.showMenuBound = this.showMenu.bind(this);
|
|
|
|
this.handleImageErrorBound = this.handleImageError.bind(this);
|
|
|
|
|
|
|
|
this.menuTriggerRef = null;
|
|
|
|
this.expirationCheckInterval = null;
|
|
|
|
this.expiredTimeout = null;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
expiring: false,
|
|
|
|
expired: false,
|
|
|
|
imageBroken: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
const { expirationLength } = this.props;
|
|
|
|
if (!expirationLength) {
|
|
|
|
return;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const increment = getIncrement(expirationLength);
|
|
|
|
const checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment);
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.checkExpired();
|
|
|
|
|
|
|
|
this.expirationCheckInterval = setInterval(() => {
|
|
|
|
this.checkExpired();
|
|
|
|
}, checkFrequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
if (this.expirationCheckInterval) {
|
|
|
|
clearInterval(this.expirationCheckInterval);
|
|
|
|
}
|
|
|
|
if (this.expiredTimeout) {
|
|
|
|
clearTimeout(this.expiredTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:18:10 +00:00
|
|
|
public componentDidUpdate() {
|
|
|
|
this.checkExpired();
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
public checkExpired() {
|
|
|
|
const now = Date.now();
|
2018-08-09 23:18:10 +00:00
|
|
|
const { isExpired, expirationTimestamp, expirationLength } = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
if (!expirationTimestamp || !expirationLength) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-09 23:18:10 +00:00
|
|
|
if (this.expiredTimeout) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2018-08-09 23:18:10 +00:00
|
|
|
if (isExpired || now >= expirationTimestamp) {
|
2018-07-09 21:29:13 +00:00
|
|
|
this.setState({
|
|
|
|
expiring: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const setExpired = () => {
|
|
|
|
this.setState({
|
|
|
|
expired: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.expiredTimeout = setTimeout(setExpired, EXPIRED_DELAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public handleImageError() {
|
|
|
|
// tslint:disable-next-line no-console
|
|
|
|
console.log('Message: Image failed to load; failing over to placeholder');
|
|
|
|
this.setState({
|
|
|
|
imageBroken: true,
|
|
|
|
});
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public renderMetadata() {
|
|
|
|
const {
|
2018-07-09 21:29:13 +00:00
|
|
|
attachment,
|
2018-06-27 20:53:49 +00:00
|
|
|
collapseMetadata,
|
|
|
|
direction,
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
i18n,
|
|
|
|
status,
|
|
|
|
text,
|
2018-07-09 21:29:13 +00:00
|
|
|
timestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
const { imageBroken } = this.state;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
if (collapseMetadata) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const withImageNoCaption = Boolean(
|
|
|
|
!text &&
|
|
|
|
!imageBroken &&
|
|
|
|
((isImage(attachment) && hasImage(attachment)) ||
|
|
|
|
(isVideo(attachment) && hasVideoScreenshot(attachment)))
|
|
|
|
);
|
|
|
|
const showError = status === 'error' && direction === 'outgoing';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__metadata',
|
|
|
|
withImageNoCaption
|
|
|
|
? 'module-message__metadata--with-image-no-caption'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
{showError ? (
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
'module-message__metadata__date',
|
|
|
|
`module-message__metadata__date--${direction}`,
|
|
|
|
withImageNoCaption
|
|
|
|
? 'module-message__metadata__date--with-image-no-caption'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('sendFailed')}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<Timestamp
|
|
|
|
i18n={i18n}
|
|
|
|
timestamp={timestamp}
|
2018-07-18 03:25:55 +00:00
|
|
|
extended={true}
|
2018-07-09 21:29:13 +00:00
|
|
|
direction={direction}
|
|
|
|
withImageNoCaption={withImageNoCaption}
|
|
|
|
module="module-message__metadata__date"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{expirationLength && expirationTimestamp ? (
|
|
|
|
<ExpireTimer
|
|
|
|
direction={direction}
|
|
|
|
expirationLength={expirationLength}
|
|
|
|
expirationTimestamp={expirationTimestamp}
|
|
|
|
withImageNoCaption={withImageNoCaption}
|
|
|
|
/>
|
|
|
|
) : null}
|
2018-06-27 20:53:49 +00:00
|
|
|
<span className="module-message__metadata__spacer" />
|
2018-07-09 21:29:13 +00:00
|
|
|
{direction === 'outgoing' && status !== 'error' ? (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__metadata__status-icon',
|
2018-07-09 21:29:13 +00:00
|
|
|
`module-message__metadata__status-icon--${status}`,
|
2018-06-27 20:53:49 +00:00
|
|
|
withImageNoCaption
|
|
|
|
? 'module-message__metadata__status-icon--with-image-no-caption'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAuthor() {
|
|
|
|
const {
|
|
|
|
authorName,
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber,
|
|
|
|
authorProfileName,
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const title = authorName ? authorName : authorPhoneNumber;
|
|
|
|
|
|
|
|
if (direction !== 'incoming' || conversationType !== 'group' || !title) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-message__author">
|
2018-07-09 21:29:13 +00:00
|
|
|
<ContactName
|
|
|
|
phoneNumber={authorPhoneNumber}
|
|
|
|
name={authorName}
|
|
|
|
profileName={authorProfileName}
|
|
|
|
module="module-message__author"
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
// tslint:disable-next-line max-func-body-length cyclomatic-complexity
|
2018-06-27 20:53:49 +00:00
|
|
|
public renderAttachment() {
|
|
|
|
const {
|
|
|
|
i18n,
|
|
|
|
attachment,
|
|
|
|
text,
|
|
|
|
collapseMetadata,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
quote,
|
|
|
|
onClickAttachment,
|
|
|
|
} = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
const { imageBroken } = this.state;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
if (!attachment) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const withCaption = Boolean(text);
|
|
|
|
// For attachments which aren't full-frame
|
|
|
|
const withContentBelow = withCaption || !collapseMetadata;
|
|
|
|
const withContentAbove =
|
|
|
|
quote || (conversationType === 'group' && direction === 'incoming');
|
|
|
|
|
|
|
|
if (isImage(attachment)) {
|
2018-07-09 21:29:13 +00:00
|
|
|
if (imageBroken || !attachment.url) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__broken-image',
|
|
|
|
`module-message__broken-image--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('imageFailedToLoad')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculating height to prevent reflow when image loads
|
|
|
|
const height = Math.max(MINIMUM_IMG_HEIGHT, attachment.height || 0);
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
|
|
|
onClick={onClickAttachment}
|
|
|
|
role="button"
|
2018-08-01 22:40:13 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__attachment-container',
|
|
|
|
withCaption
|
|
|
|
? 'module-message__attachment-container--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__attachment-container--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
2018-07-09 21:29:13 +00:00
|
|
|
>
|
2018-06-27 20:53:49 +00:00
|
|
|
<img
|
2018-07-09 21:29:13 +00:00
|
|
|
onError={this.handleImageErrorBound}
|
2018-08-01 22:40:13 +00:00
|
|
|
className="module-message__img-attachment"
|
|
|
|
height={Math.min(MAXIMUM_IMG_HEIGHT, height)}
|
|
|
|
src={attachment.url}
|
|
|
|
alt={i18n('imageAttachmentAlt')}
|
|
|
|
/>
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-08-01 22:40:13 +00:00
|
|
|
'module-message__img-border-overlay',
|
2018-06-27 20:53:49 +00:00
|
|
|
withCaption
|
2018-08-01 22:40:13 +00:00
|
|
|
? 'module-message__img-border-overlay--with-content-below'
|
2018-06-27 20:53:49 +00:00
|
|
|
: null,
|
|
|
|
withContentAbove
|
2018-08-01 22:40:13 +00:00
|
|
|
? 'module-message__img-border-overlay--with-content-above'
|
2018-06-27 20:53:49 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{!withCaption && !collapseMetadata ? (
|
|
|
|
<div className="module-message__img-overlay" />
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (isVideo(attachment)) {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { screenshot } = attachment;
|
|
|
|
if (imageBroken || !screenshot || !screenshot.url) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={onClickAttachment}
|
|
|
|
className={classNames(
|
|
|
|
'module-message__broken-video-screenshot',
|
|
|
|
`module-message__broken-video-screenshot--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('videoScreenshotFailedToLoad')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculating height to prevent reflow when image loads
|
|
|
|
const height = Math.max(MINIMUM_IMG_HEIGHT, screenshot.height || 0);
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
|
|
|
onClick={onClickAttachment}
|
|
|
|
role="button"
|
2018-08-01 22:40:13 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__attachment-container',
|
|
|
|
withCaption
|
|
|
|
? 'module-message__attachment-container--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__attachment-container--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
<img
|
|
|
|
onError={this.handleImageErrorBound}
|
2018-08-01 22:40:13 +00:00
|
|
|
className="module-message__img-attachment"
|
|
|
|
alt={i18n('videoAttachmentAlt')}
|
|
|
|
height={Math.min(MAXIMUM_IMG_HEIGHT, height)}
|
|
|
|
src={screenshot.url}
|
|
|
|
/>
|
|
|
|
<div
|
2018-07-09 21:29:13 +00:00
|
|
|
className={classNames(
|
2018-08-01 22:40:13 +00:00
|
|
|
'module-message__img-border-overlay',
|
2018-07-09 21:29:13 +00:00
|
|
|
withCaption
|
2018-08-01 22:40:13 +00:00
|
|
|
? 'module-message__img-border-overlay--with-content-below'
|
2018-07-09 21:29:13 +00:00
|
|
|
: null,
|
|
|
|
withContentAbove
|
2018-08-01 22:40:13 +00:00
|
|
|
? 'module-message__img-border-overlay--with-content-above'
|
2018-07-09 21:29:13 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{!withCaption && !collapseMetadata ? (
|
|
|
|
<div className="module-message__img-overlay" />
|
|
|
|
) : null}
|
|
|
|
<div className="module-message__video-overlay__circle">
|
|
|
|
<div className="module-message__video-overlay__play-icon" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
} else if (isAudio(attachment)) {
|
|
|
|
return (
|
|
|
|
<audio
|
|
|
|
controls={true}
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__audio-attachment',
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__audio-attachment--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__audio-attachment--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<source src={attachment.url} />
|
|
|
|
</audio>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
const { fileName, fileSize, contentType } = attachment;
|
|
|
|
const extension = getExtension({ contentType, fileName });
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__generic-attachment',
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__generic-attachment--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__generic-attachment--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<div className="module-message__generic-attachment__icon">
|
|
|
|
{extension ? (
|
|
|
|
<div className="module-message__generic-attachment__icon__extension">
|
|
|
|
{extension}
|
|
|
|
</div>
|
|
|
|
) : null}
|
2018-04-14 00:34:53 +00:00
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className="module-message__generic-attachment__text">
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__generic-attachment__file-name',
|
|
|
|
`module-message__generic-attachment__file-name--${direction}`
|
|
|
|
)}
|
2018-04-03 22:56:12 +00:00
|
|
|
>
|
2018-06-27 20:53:49 +00:00
|
|
|
{fileName}
|
|
|
|
</div>
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__generic-attachment__file-size',
|
|
|
|
`module-message__generic-attachment__file-size--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{fileSize}
|
|
|
|
</div>
|
2018-04-03 22:56:12 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderQuote() {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { conversationType, direction, i18n, quote } = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
if (!quote) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const withContentAbove =
|
|
|
|
conversationType === 'group' && direction === 'incoming';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Quote
|
|
|
|
i18n={i18n}
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={quote.onClick}
|
2018-06-27 20:53:49 +00:00
|
|
|
text={quote.text}
|
2018-07-09 21:29:13 +00:00
|
|
|
attachment={quote.attachment}
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming={direction === 'incoming'}
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber={quote.authorPhoneNumber}
|
|
|
|
authorProfileName={quote.authorProfileName}
|
|
|
|
authorName={quote.authorName}
|
|
|
|
authorColor={quote.authorColor}
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound={quote.referencedMessageNotFound}
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe={quote.isFromMe}
|
|
|
|
withContentAbove={withContentAbove}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderEmbeddedContact() {
|
|
|
|
const {
|
|
|
|
collapseMetadata,
|
2018-07-09 21:29:13 +00:00
|
|
|
contact,
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
text,
|
|
|
|
} = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
if (!contact) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const withCaption = Boolean(text);
|
|
|
|
const withContentAbove =
|
|
|
|
conversationType === 'group' && direction === 'incoming';
|
|
|
|
const withContentBelow = withCaption || !collapseMetadata;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EmbeddedContact
|
2018-07-09 21:29:13 +00:00
|
|
|
contact={contact}
|
|
|
|
hasSignalAccount={contact.hasSignalAccount}
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming={direction === 'incoming'}
|
|
|
|
i18n={i18n}
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={contact.onClick}
|
2018-06-27 20:53:49 +00:00
|
|
|
withContentAbove={withContentAbove}
|
|
|
|
withContentBelow={withContentBelow}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderSendMessageButton() {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { contact, i18n } = this.props;
|
|
|
|
if (!contact || !contact.hasSignalAccount) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="button"
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={contact.onSendMessage}
|
2018-06-27 20:53:49 +00:00
|
|
|
className="module-message__send-message-button"
|
|
|
|
>
|
|
|
|
{i18n('sendMessageToContact')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAvatar() {
|
|
|
|
const {
|
|
|
|
authorName,
|
|
|
|
authorPhoneNumber,
|
|
|
|
authorProfileName,
|
|
|
|
authorAvatarPath,
|
2018-07-09 21:29:13 +00:00
|
|
|
authorColor,
|
2018-06-27 20:53:49 +00:00
|
|
|
collapseMetadata,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const title = `${authorName || authorPhoneNumber}${
|
|
|
|
!authorName && authorProfileName ? ` ~${authorProfileName}` : ''
|
|
|
|
}`;
|
|
|
|
|
|
|
|
if (
|
|
|
|
collapseMetadata ||
|
|
|
|
conversationType !== 'group' ||
|
|
|
|
direction === 'outgoing'
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!authorAvatarPath) {
|
2018-07-09 21:29:13 +00:00
|
|
|
const label = authorName ? getInitial(authorName) : '#';
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__author-default-avatar',
|
2018-07-09 21:29:13 +00:00
|
|
|
`module-message__author-default-avatar--${authorColor}`
|
2018-06-27 20:53:49 +00:00
|
|
|
)}
|
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
<div className="module-message__author-default-avatar__label">
|
|
|
|
{label}
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-message__author-avatar">
|
|
|
|
<img alt={i18n('contactAvatarAlt', [title])} src={authorAvatarPath} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderText() {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { text, i18n, direction, status } = this.props;
|
|
|
|
|
|
|
|
const contents =
|
|
|
|
direction === 'incoming' && status === 'error'
|
|
|
|
? i18n('incomingError')
|
|
|
|
: text;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
if (!contents) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2018-07-27 17:42:26 +00:00
|
|
|
dir="auto"
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-message__text',
|
2018-07-09 21:29:13 +00:00
|
|
|
`module-message__text--${direction}`,
|
|
|
|
status === 'error' && direction === 'incoming'
|
|
|
|
? 'module-message__text--error'
|
|
|
|
: null
|
2018-06-27 20:53:49 +00:00
|
|
|
)}
|
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
<MessageBody text={contents || ''} i18n={i18n} />
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
public renderError(isCorrectSide: boolean) {
|
|
|
|
const { status, direction } = this.props;
|
|
|
|
|
|
|
|
if (!isCorrectSide || status !== 'error') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-message__error-container">
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__error',
|
|
|
|
`module-message__error--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public captureMenuTrigger(triggerRef: Trigger) {
|
|
|
|
this.menuTriggerRef = triggerRef;
|
|
|
|
}
|
|
|
|
public showMenu(event: React.MouseEvent<HTMLDivElement>) {
|
|
|
|
if (this.menuTriggerRef) {
|
|
|
|
this.menuTriggerRef.handleContextClick(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderMenu(isCorrectSide: boolean, triggerId: string) {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
|
|
|
attachment,
|
2018-07-09 21:29:13 +00:00
|
|
|
direction,
|
|
|
|
disableMenu,
|
|
|
|
onDownload,
|
|
|
|
onReply,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!isCorrectSide || disableMenu) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const downloadButton = attachment ? (
|
|
|
|
<div
|
|
|
|
onClick={onDownload}
|
|
|
|
role="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__download',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
const replyButton = (
|
|
|
|
<div
|
|
|
|
onClick={onReply}
|
|
|
|
role="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__reply',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuButton = (
|
|
|
|
<ContextMenuTrigger id={triggerId} ref={this.captureMenuTriggerBound}>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={this.showMenuBound}
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__menu',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</ContextMenuTrigger>
|
|
|
|
);
|
|
|
|
|
|
|
|
const first = direction === 'incoming' ? downloadButton : menuButton;
|
|
|
|
const last = direction === 'incoming' ? menuButton : downloadButton;
|
|
|
|
|
|
|
|
return (
|
2018-08-11 00:15:00 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons',
|
|
|
|
`module-message__buttons--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
{first}
|
|
|
|
{replyButton}
|
|
|
|
{last}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderContextMenu(triggerId: string) {
|
|
|
|
const {
|
2018-08-11 00:15:00 +00:00
|
|
|
attachment,
|
2018-07-09 21:29:13 +00:00
|
|
|
direction,
|
|
|
|
status,
|
|
|
|
onDelete,
|
2018-08-11 00:15:00 +00:00
|
|
|
onDownload,
|
|
|
|
onReply,
|
2018-07-09 21:29:13 +00:00
|
|
|
onRetrySend,
|
|
|
|
onShowDetail,
|
|
|
|
i18n,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const showRetry = status === 'error' && direction === 'outgoing';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ContextMenu id={triggerId}>
|
2018-08-11 00:15:00 +00:00
|
|
|
{attachment ? (
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__download',
|
|
|
|
}}
|
|
|
|
onClick={onDownload}
|
|
|
|
>
|
|
|
|
{i18n('downloadAttachment')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__reply',
|
|
|
|
}}
|
|
|
|
onClick={onReply}
|
|
|
|
>
|
|
|
|
{i18n('replyToMessage')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__more-info',
|
|
|
|
}}
|
|
|
|
onClick={onShowDetail}
|
|
|
|
>
|
|
|
|
{i18n('moreInfo')}
|
|
|
|
</MenuItem>
|
2018-07-09 21:29:13 +00:00
|
|
|
{showRetry ? (
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__retry-send',
|
|
|
|
}}
|
|
|
|
onClick={onRetrySend}
|
|
|
|
>
|
|
|
|
{i18n('retrySend')}
|
|
|
|
</MenuItem>
|
2018-07-09 21:29:13 +00:00
|
|
|
) : null}
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__delete-message',
|
|
|
|
}}
|
|
|
|
onClick={onDelete}
|
|
|
|
>
|
|
|
|
{i18n('deleteMessage')}
|
|
|
|
</MenuItem>
|
2018-07-09 21:29:13 +00:00
|
|
|
</ContextMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
authorPhoneNumber,
|
|
|
|
authorColor,
|
2018-06-27 20:53:49 +00:00
|
|
|
direction,
|
|
|
|
id,
|
2018-07-09 21:29:13 +00:00
|
|
|
timestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
const { expired, expiring } = this.state;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
// This id is what connects our triple-dot click with our associated pop-up menu.
|
|
|
|
// It needs to be unique.
|
|
|
|
const triggerId = String(id || `${authorPhoneNumber}-${timestamp}`);
|
|
|
|
|
|
|
|
if (expired) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
return (
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message',
|
|
|
|
`module-message--${direction}`,
|
|
|
|
expiring ? 'module-message--expired' : null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.renderError(direction === 'incoming')}
|
|
|
|
{this.renderMenu(direction === 'outgoing', triggerId)}
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-07-09 21:29:13 +00:00
|
|
|
'module-message__container',
|
|
|
|
`module-message__container--${direction}`,
|
2018-06-27 20:53:49 +00:00
|
|
|
direction === 'incoming'
|
2018-07-09 21:29:13 +00:00
|
|
|
? `module-message__container--incoming-${authorColor}`
|
2018-06-27 20:53:49 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.renderAuthor()}
|
|
|
|
{this.renderQuote()}
|
|
|
|
{this.renderAttachment()}
|
|
|
|
{this.renderEmbeddedContact()}
|
|
|
|
{this.renderText()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
{this.renderSendMessageButton()}
|
|
|
|
{this.renderAvatar()}
|
|
|
|
</div>
|
2018-07-09 21:29:13 +00:00
|
|
|
{this.renderError(direction === 'outgoing')}
|
|
|
|
{this.renderMenu(direction === 'incoming', triggerId)}
|
|
|
|
{this.renderContextMenu(triggerId)}
|
|
|
|
</div>
|
2018-04-03 22:56:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|