2018-04-03 22:56:12 +00:00
|
|
|
import React from 'react';
|
2019-03-20 17:42:28 +00:00
|
|
|
import ReactDOM from 'react-dom';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-09-27 00:23:17 +00:00
|
|
|
import { Avatar } from '../Avatar';
|
2019-01-30 20:15:07 +00:00
|
|
|
import { Spinner } from '../Spinner';
|
2018-06-27 20:53:49 +00:00
|
|
|
import { MessageBody } from './MessageBody';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { ExpireTimer } from './ExpireTimer';
|
|
|
|
import { ImageGrid } from './ImageGrid';
|
|
|
|
import { Image } from './Image';
|
|
|
|
import { Timestamp } from './Timestamp';
|
|
|
|
import { ContactName } from './ContactName';
|
|
|
|
import { Quote, QuotedAttachmentType } from './Quote';
|
|
|
|
import { EmbeddedContact } from './EmbeddedContact';
|
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
import {
|
2019-01-14 21:49:58 +00:00
|
|
|
canDisplayImage,
|
|
|
|
getExtensionForDisplay,
|
2018-11-14 18:47:19 +00:00
|
|
|
getGridDimensions,
|
2019-01-16 03:03:56 +00:00
|
|
|
getImageDimensions,
|
2018-11-14 18:47:19 +00:00
|
|
|
hasImage,
|
|
|
|
hasVideoScreenshot,
|
2019-01-14 21:49:58 +00:00
|
|
|
isAudio,
|
2018-11-14 18:47:19 +00:00
|
|
|
isImage,
|
2019-01-16 03:03:56 +00:00
|
|
|
isImageAttachment,
|
2018-11-14 18:47:19 +00:00
|
|
|
isVideo,
|
2019-01-14 21:49:58 +00:00
|
|
|
} from '../../../ts/types/Attachment';
|
|
|
|
import { AttachmentType } from '../../types/Attachment';
|
2019-03-15 22:18:00 +00:00
|
|
|
import { ContactType } from '../../types/Contact';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { getIncrement } from '../../util/timer';
|
2018-10-04 01:12:42 +00:00
|
|
|
import { isFileDangerous } from '../../util/isFileDangerous';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { ColorType, LocalizerType } from '../../types/Util';
|
2018-07-09 21:29:13 +00:00
|
|
|
import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
|
|
|
|
|
|
|
|
interface Trigger {
|
|
|
|
handleContextClick: (event: React.MouseEvent<HTMLDivElement>) => void;
|
|
|
|
}
|
|
|
|
|
2019-01-16 03:03:56 +00:00
|
|
|
// Same as MIN_WIDTH in ImageGrid.tsx
|
|
|
|
const MINIMUM_LINK_PREVIEW_IMAGE_WIDTH = 200;
|
2019-05-16 22:32:11 +00:00
|
|
|
const STICKER_SIZE = 128;
|
2019-11-21 19:16:06 +00:00
|
|
|
const SELECTED_TIMEOUT = 1000;
|
2019-01-16 03:03:56 +00:00
|
|
|
|
|
|
|
interface LinkPreviewType {
|
|
|
|
title: string;
|
|
|
|
domain: string;
|
|
|
|
url: string;
|
2019-05-16 22:32:11 +00:00
|
|
|
isStickerPack: boolean;
|
2019-01-16 03:03:56 +00:00
|
|
|
image?: AttachmentType;
|
|
|
|
}
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
export type PropsData = {
|
2019-03-15 22:18:00 +00:00
|
|
|
id: string;
|
2019-11-07 21:36:16 +00:00
|
|
|
conversationId: string;
|
2018-06-27 20:53:49 +00:00
|
|
|
text?: string;
|
2019-03-13 20:38:28 +00:00
|
|
|
textPending?: boolean;
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
isSelected: boolean;
|
2019-11-21 19:16:06 +00:00
|
|
|
isSelectedCounter: number;
|
|
|
|
interactionMode: 'mouse' | 'keyboard';
|
2018-06-27 20:53:49 +00:00
|
|
|
direction: 'incoming' | 'outgoing';
|
|
|
|
timestamp: number;
|
2018-07-09 21:29:13 +00:00
|
|
|
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
|
2019-03-15 22:18:00 +00:00
|
|
|
contact?: ContactType;
|
2018-06-27 20:53:49 +00:00
|
|
|
authorName?: string;
|
|
|
|
authorProfileName?: string;
|
|
|
|
/** Note: this should be formatted for display */
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
authorColor?: ColorType;
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType: 'group' | 'direct';
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments?: Array<AttachmentType>;
|
2018-06-27 20:53:49 +00:00
|
|
|
quote?: {
|
|
|
|
text: string;
|
2018-11-14 18:47:19 +00:00
|
|
|
attachment?: QuotedAttachmentType;
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe: boolean;
|
2019-03-15 22:18:00 +00:00
|
|
|
sentAt: number;
|
|
|
|
authorId: string;
|
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;
|
2019-01-14 21:49:58 +00:00
|
|
|
authorColor?: ColorType;
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
};
|
2019-01-16 03:03:56 +00:00
|
|
|
previews: Array<LinkPreviewType>;
|
2018-06-27 20:53:49 +00:00
|
|
|
authorAvatarPath?: string;
|
2018-08-09 23:18:10 +00:00
|
|
|
isExpired: boolean;
|
2019-06-26 19:33:13 +00:00
|
|
|
|
|
|
|
isTapToView?: boolean;
|
|
|
|
isTapToViewExpired?: boolean;
|
|
|
|
isTapToViewError?: boolean;
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
expirationLength?: number;
|
|
|
|
expirationTimestamp?: number;
|
2019-03-15 22:18:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type PropsHousekeeping = {
|
|
|
|
i18n: LocalizerType;
|
|
|
|
disableMenu?: boolean;
|
|
|
|
disableScroll?: boolean;
|
|
|
|
collapseMetadata?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsActions = {
|
2019-05-31 22:42:01 +00:00
|
|
|
clearSelectedMessage: () => unknown;
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage: (id: string) => void;
|
|
|
|
retrySend: (id: string) => void;
|
|
|
|
deleteMessage: (id: string) => void;
|
|
|
|
showMessageDetail: (id: string) => void;
|
|
|
|
|
|
|
|
openConversation: (conversationId: string, messageId?: string) => void;
|
2020-01-08 17:44:54 +00:00
|
|
|
showContactDetail: (options: {
|
|
|
|
contact: ContactType;
|
|
|
|
signalAccount?: string;
|
|
|
|
}) => void;
|
|
|
|
|
|
|
|
showVisualAttachment: (options: {
|
|
|
|
attachment: AttachmentType;
|
|
|
|
messageId: string;
|
|
|
|
}) => void;
|
|
|
|
downloadAttachment: (options: {
|
|
|
|
attachment: AttachmentType;
|
|
|
|
timestamp: number;
|
|
|
|
isDangerous: boolean;
|
|
|
|
}) => void;
|
2019-06-26 19:33:13 +00:00
|
|
|
displayTapToViewMessage: (messageId: string) => unknown;
|
2019-03-15 22:18:00 +00:00
|
|
|
|
|
|
|
openLink: (url: string) => void;
|
2020-01-08 17:44:54 +00:00
|
|
|
scrollToQuotedMessage: (options: { author: string; sentAt: number }) => void;
|
2019-11-21 19:16:06 +00:00
|
|
|
selectMessage?: (messageId: string, conversationId: string) => unknown;
|
2019-03-15 22:18:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Props = PropsData & PropsHousekeeping & PropsActions;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
interface State {
|
|
|
|
expiring: boolean;
|
|
|
|
expired: boolean;
|
|
|
|
imageBroken: boolean;
|
2019-11-21 19:16:06 +00:00
|
|
|
|
|
|
|
isSelected: boolean;
|
|
|
|
prevSelectedCounter: number;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const EXPIRATION_CHECK_MINIMUM = 2000;
|
|
|
|
const EXPIRED_DELAY = 600;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export class Message extends React.PureComponent<Props, State> {
|
|
|
|
public menuTriggerRef: Trigger | undefined;
|
2019-11-07 21:36:16 +00:00
|
|
|
public focusRef: React.RefObject<HTMLDivElement> = React.createRef();
|
|
|
|
public audioRef: React.RefObject<HTMLAudioElement> = React.createRef();
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
public expirationCheckInterval: any;
|
|
|
|
public expiredTimeout: any;
|
2019-05-31 22:42:01 +00:00
|
|
|
public selectedTimeout: any;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
expiring: false,
|
|
|
|
expired: false,
|
|
|
|
imageBroken: false,
|
|
|
|
|
|
|
|
isSelected: props.isSelected,
|
|
|
|
prevSelectedCounter: props.isSelectedCounter,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getDerivedStateFromProps(props: Props, state: State): State {
|
|
|
|
if (!props.isSelected) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isSelected: false,
|
|
|
|
prevSelectedCounter: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
props.isSelected &&
|
|
|
|
props.isSelectedCounter !== state.prevSelectedCounter
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isSelected: props.isSelected,
|
|
|
|
prevSelectedCounter: props.isSelectedCounter,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public captureMenuTrigger = (triggerRef: Trigger) => {
|
|
|
|
this.menuTriggerRef = triggerRef;
|
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public showMenu = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
|
|
if (this.menuTriggerRef) {
|
|
|
|
this.menuTriggerRef.handleContextClick(event);
|
|
|
|
}
|
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public handleImageError = () => {
|
|
|
|
const { id } = this.props;
|
|
|
|
// tslint:disable-next-line no-console
|
|
|
|
console.log(
|
|
|
|
`Message ${id}: Image failed to load; failing over to placeholder`
|
|
|
|
);
|
|
|
|
this.setState({
|
|
|
|
imageBroken: true,
|
|
|
|
});
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
public handleFocus = () => {
|
|
|
|
const { interactionMode } = this.props;
|
|
|
|
|
|
|
|
if (interactionMode === 'keyboard') {
|
|
|
|
this.setSelected();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public setSelected = () => {
|
|
|
|
const { id, conversationId, selectMessage } = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
if (selectMessage) {
|
|
|
|
selectMessage(id, conversationId);
|
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public setFocus = () => {
|
2019-11-14 23:54:50 +00:00
|
|
|
const container = this.focusRef.current;
|
|
|
|
|
|
|
|
if (container && !container.contains(document.activeElement)) {
|
|
|
|
container.focus();
|
2019-11-07 21:36:16 +00:00
|
|
|
}
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
public componentDidMount() {
|
2019-11-21 19:16:06 +00:00
|
|
|
this.startSelectedTimer();
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
const { isSelected } = this.props;
|
|
|
|
if (isSelected) {
|
|
|
|
this.setFocus();
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
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() {
|
2019-05-31 22:42:01 +00:00
|
|
|
if (this.selectedTimeout) {
|
|
|
|
clearInterval(this.selectedTimeout);
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.expirationCheckInterval) {
|
|
|
|
clearInterval(this.expirationCheckInterval);
|
|
|
|
}
|
|
|
|
if (this.expiredTimeout) {
|
|
|
|
clearTimeout(this.expiredTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public componentDidUpdate(prevProps: Props) {
|
2019-11-21 19:16:06 +00:00
|
|
|
this.startSelectedTimer();
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
if (!prevProps.isSelected && this.props.isSelected) {
|
|
|
|
this.setFocus();
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
this.checkExpired();
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
public startSelectedTimer() {
|
|
|
|
const { interactionMode } = this.props;
|
|
|
|
const { isSelected } = this.state;
|
|
|
|
|
|
|
|
if (interactionMode === 'keyboard' || !isSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.selectedTimeout) {
|
|
|
|
this.selectedTimeout = setTimeout(() => {
|
|
|
|
this.selectedTimeout = undefined;
|
|
|
|
this.setState({ isSelected: false });
|
|
|
|
this.props.clearSelectedMessage();
|
|
|
|
}, SELECTED_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
public renderMetadata() {
|
|
|
|
const {
|
|
|
|
collapseMetadata,
|
|
|
|
direction,
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
i18n,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
isTapToViewExpired,
|
2018-06-27 20:53:49 +00:00
|
|
|
status,
|
|
|
|
text,
|
2019-03-13 20:38:28 +00:00
|
|
|
textPending,
|
2018-07-09 21:29:13 +00:00
|
|
|
timestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (collapseMetadata) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-16 03:03:56 +00:00
|
|
|
const isShowingImage = this.isShowingImage();
|
2019-05-16 22:32:11 +00:00
|
|
|
const withImageNoCaption = Boolean(!isSticker && !text && isShowingImage);
|
2018-07-09 21:29:13 +00:00
|
|
|
const showError = status === 'error' && direction === 'outgoing';
|
2019-05-16 22:32:11 +00:00
|
|
|
const metadataDirection = isSticker ? undefined : direction;
|
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
|
|
|
|
)}
|
|
|
|
>
|
2019-10-04 18:06:17 +00:00
|
|
|
<span className="module-message__metadata__spacer" />
|
2018-07-09 21:29:13 +00:00
|
|
|
{showError ? (
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
'module-message__metadata__date',
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker ? 'module-message__metadata__date--with-sticker' : null,
|
|
|
|
!isSticker
|
|
|
|
? `module-message__metadata__date--${direction}`
|
|
|
|
: null,
|
2018-07-09 21:29:13 +00:00
|
|
|
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}
|
2019-05-16 22:32:11 +00:00
|
|
|
direction={metadataDirection}
|
2018-07-09 21:29:13 +00:00
|
|
|
withImageNoCaption={withImageNoCaption}
|
2019-05-16 22:32:11 +00:00
|
|
|
withSticker={isSticker}
|
2019-06-26 19:33:13 +00:00
|
|
|
withTapToViewExpired={isTapToViewExpired}
|
2018-07-09 21:29:13 +00:00
|
|
|
module="module-message__metadata__date"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{expirationLength && expirationTimestamp ? (
|
|
|
|
<ExpireTimer
|
2019-05-16 22:32:11 +00:00
|
|
|
direction={metadataDirection}
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationLength={expirationLength}
|
|
|
|
expirationTimestamp={expirationTimestamp}
|
|
|
|
withImageNoCaption={withImageNoCaption}
|
2019-05-16 22:32:11 +00:00
|
|
|
withSticker={isSticker}
|
2019-06-26 19:33:13 +00:00
|
|
|
withTapToViewExpired={isTapToViewExpired}
|
2018-07-09 21:29:13 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2019-03-13 20:38:28 +00:00
|
|
|
{textPending ? (
|
|
|
|
<div className="module-message__metadata__spinner-container">
|
2019-06-26 19:33:13 +00:00
|
|
|
<Spinner svgSize="small" size="14px" direction={direction} />
|
2019-03-13 20:38:28 +00:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{!textPending && 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}`,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker
|
|
|
|
? 'module-message__metadata__status-icon--with-sticker'
|
|
|
|
: null,
|
2018-06-27 20:53:49 +00:00
|
|
|
withImageNoCaption
|
|
|
|
? 'module-message__metadata__status-icon--with-image-no-caption'
|
2019-06-26 19:33:13 +00:00
|
|
|
: null,
|
|
|
|
isTapToViewExpired
|
|
|
|
? 'module-message__metadata__status-icon--with-tap-to-view-expired'
|
2018-06-27 20:53:49 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAuthor() {
|
|
|
|
const {
|
|
|
|
authorName,
|
2018-07-09 21:29:13 +00:00
|
|
|
authorPhoneNumber,
|
|
|
|
authorProfileName,
|
2019-05-16 22:32:11 +00:00
|
|
|
collapseMetadata,
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType,
|
|
|
|
direction,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
isTapToView,
|
|
|
|
isTapToViewExpired,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
if (collapseMetadata) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
const title = authorName ? authorName : authorPhoneNumber;
|
|
|
|
|
|
|
|
if (direction !== 'incoming' || conversationType !== 'group' || !title) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-06-26 19:33:13 +00:00
|
|
|
const withTapToViewExpired = isTapToView && isTapToViewExpired;
|
|
|
|
|
|
|
|
const stickerSuffix = isSticker ? '_with_sticker' : '';
|
|
|
|
const tapToViewSuffix = withTapToViewExpired
|
|
|
|
? '--with-tap-to-view-expired'
|
|
|
|
: '';
|
|
|
|
const moduleName = `module-message__author${stickerSuffix}${tapToViewSuffix}`;
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2019-05-16 22:32:11 +00:00
|
|
|
<div className={moduleName}>
|
2018-07-09 21:29:13 +00:00
|
|
|
<ContactName
|
|
|
|
phoneNumber={authorPhoneNumber}
|
|
|
|
name={authorName}
|
|
|
|
profileName={authorProfileName}
|
2019-05-16 22:32:11 +00:00
|
|
|
module={moduleName}
|
2018-07-09 21:29:13 +00:00
|
|
|
/>
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-11 19:24:58 +00:00
|
|
|
// tslint:disable-next-line max-func-body-length cyclomatic-complexity
|
2018-06-27 20:53:49 +00:00
|
|
|
public renderAttachment() {
|
|
|
|
const {
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2018-06-27 20:53:49 +00:00
|
|
|
collapseMetadata,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
2018-11-14 18:47:19 +00:00
|
|
|
i18n,
|
2019-05-16 22:32:11 +00:00
|
|
|
id,
|
2018-06-27 20:53:49 +00:00
|
|
|
quote,
|
2019-03-15 22:18:00 +00:00
|
|
|
showVisualAttachment,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
|
|
|
text,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
2019-11-07 21:36:16 +00:00
|
|
|
const { imageBroken } = this.state;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
if (!attachments || !attachments[0]) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
2018-11-14 18:47:19 +00:00
|
|
|
const firstAttachment = attachments[0];
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
// For attachments which aren't full-frame
|
2018-11-14 18:47:19 +00:00
|
|
|
const withContentBelow = Boolean(text);
|
2018-06-27 20:53:49 +00:00
|
|
|
const withContentAbove =
|
2018-11-14 18:47:19 +00:00
|
|
|
Boolean(quote) ||
|
|
|
|
(conversationType === 'group' && direction === 'incoming');
|
|
|
|
const displayImage = canDisplayImage(attachments);
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
if (
|
2018-09-05 19:07:53 +00:00
|
|
|
displayImage &&
|
|
|
|
!imageBroken &&
|
2018-11-14 18:47:19 +00:00
|
|
|
((isImage(attachments) && hasImage(attachments)) ||
|
|
|
|
(isVideo(attachments) && hasVideoScreenshot(attachments)))
|
2018-09-05 19:07:53 +00:00
|
|
|
) {
|
2019-05-16 22:32:11 +00:00
|
|
|
const prefix = isSticker ? 'sticker' : 'attachment';
|
|
|
|
const bottomOverlay = !isSticker && !collapseMetadata;
|
2019-11-07 21:36:16 +00:00
|
|
|
// We only want users to tab into this if there's more than one
|
|
|
|
const tabIndex = attachments.length > 1 ? 0 : -1;
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
2018-08-01 22:40:13 +00:00
|
|
|
className={classNames(
|
2019-05-16 22:32:11 +00:00
|
|
|
`module-message__${prefix}-container`,
|
2018-08-01 22:40:13 +00:00
|
|
|
withContentAbove
|
2019-05-16 22:32:11 +00:00
|
|
|
? `module-message__${prefix}-container--with-content-above`
|
2018-11-14 18:47:19 +00:00
|
|
|
: null,
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__attachment-container--with-content-below'
|
2019-05-16 22:32:11 +00:00
|
|
|
: null,
|
|
|
|
isSticker && !collapseMetadata
|
|
|
|
? 'module-message__sticker-container--with-content-below'
|
2018-08-01 22:40:13 +00:00
|
|
|
: null
|
|
|
|
)}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
2018-11-14 18:47:19 +00:00
|
|
|
<ImageGrid
|
|
|
|
attachments={attachments}
|
2019-05-16 22:32:11 +00:00
|
|
|
withContentAbove={isSticker || withContentAbove}
|
|
|
|
withContentBelow={isSticker || withContentBelow}
|
|
|
|
isSticker={isSticker}
|
|
|
|
stickerSize={STICKER_SIZE}
|
|
|
|
bottomOverlay={bottomOverlay}
|
2018-11-14 18:47:19 +00:00
|
|
|
i18n={i18n}
|
2019-11-07 21:36:16 +00:00
|
|
|
onError={this.handleImageError}
|
|
|
|
tabIndex={tabIndex}
|
2019-03-15 22:18:00 +00:00
|
|
|
onClick={attachment => {
|
|
|
|
showVisualAttachment({ attachment, messageId: id });
|
|
|
|
}}
|
2018-07-09 21:29:13 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
2019-01-30 20:15:07 +00:00
|
|
|
} else if (!firstAttachment.pending && isAudio(attachments)) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
|
|
|
<audio
|
2019-11-07 21:36:16 +00:00
|
|
|
ref={this.audioRef}
|
2018-06-27 20:53:49 +00:00
|
|
|
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
|
|
|
|
)}
|
2019-01-30 20:15:07 +00:00
|
|
|
key={firstAttachment.url}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
2018-11-14 18:47:19 +00:00
|
|
|
<source src={firstAttachment.url} />
|
2018-06-27 20:53:49 +00:00
|
|
|
</audio>
|
|
|
|
);
|
|
|
|
} else {
|
2019-01-30 20:15:07 +00:00
|
|
|
const { pending, fileName, fileSize, contentType } = firstAttachment;
|
2019-01-14 21:49:58 +00:00
|
|
|
const extension = getExtensionForDisplay({ contentType, fileName });
|
2018-10-15 18:54:50 +00:00
|
|
|
const isDangerous = isFileDangerous(fileName || '');
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
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
|
|
|
|
)}
|
2019-11-07 21:36:16 +00:00
|
|
|
// There's only ever one of these, so we don't want users to tab into it
|
|
|
|
tabIndex={-1}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.openGenericAttachment();
|
|
|
|
}}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
2019-01-30 20:15:07 +00:00
|
|
|
{pending ? (
|
|
|
|
<div className="module-message__generic-attachment__spinner-container">
|
2019-06-26 19:33:13 +00:00
|
|
|
<Spinner svgSize="small" size="24px" direction={direction} />
|
2019-01-30 20:15:07 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="module-message__generic-attachment__icon-container">
|
|
|
|
<div className="module-message__generic-attachment__icon">
|
|
|
|
{extension ? (
|
|
|
|
<div className="module-message__generic-attachment__icon__extension">
|
|
|
|
{extension}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
{isDangerous ? (
|
|
|
|
<div className="module-message__generic-attachment__icon-dangerous-container">
|
|
|
|
<div className="module-message__generic-attachment__icon-dangerous" />
|
2018-10-04 01:12:42 +00:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2019-01-30 20:15:07 +00:00
|
|
|
)}
|
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>
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 21:59:14 +00:00
|
|
|
// tslint:disable-next-line cyclomatic-complexity max-func-body-length
|
2019-01-16 03:03:56 +00:00
|
|
|
public renderPreview() {
|
|
|
|
const {
|
|
|
|
attachments,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
2019-03-15 22:18:00 +00:00
|
|
|
openLink,
|
2019-01-16 03:03:56 +00:00
|
|
|
previews,
|
|
|
|
quote,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
// Attachments take precedence over Link Previews
|
|
|
|
if (attachments && attachments.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!previews || previews.length < 1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const first = previews[0];
|
|
|
|
if (!first) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const withContentAbove =
|
|
|
|
Boolean(quote) ||
|
|
|
|
(conversationType === 'group' && direction === 'incoming');
|
|
|
|
|
|
|
|
const previewHasImage = first.image && isImageAttachment(first.image);
|
|
|
|
const width = first.image && first.image.width;
|
2019-05-16 22:32:11 +00:00
|
|
|
const isFullSizeImage =
|
|
|
|
!first.isStickerPack &&
|
|
|
|
width &&
|
|
|
|
width >= MINIMUM_LINK_PREVIEW_IMAGE_WIDTH;
|
2019-01-16 03:03:56 +00:00
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2019-01-16 03:03:56 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__link-preview',
|
2019-11-21 19:16:06 +00:00
|
|
|
`module-message__link-preview--${direction}`,
|
2019-01-16 03:03:56 +00:00
|
|
|
withContentAbove
|
|
|
|
? 'module-message__link-preview--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
2019-11-07 21:36:16 +00:00
|
|
|
onKeyDown={(event: React.KeyboardEvent) => {
|
|
|
|
if (event.key === 'Enter' || event.key === 'Space') {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
openLink(first.url);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
openLink(first.url);
|
2019-01-16 03:03:56 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{first.image && previewHasImage && isFullSizeImage ? (
|
|
|
|
<ImageGrid
|
|
|
|
attachments={[first.image]}
|
|
|
|
withContentAbove={withContentAbove}
|
|
|
|
withContentBelow={true}
|
2019-11-07 21:36:16 +00:00
|
|
|
onError={this.handleImageError}
|
2019-01-16 03:03:56 +00:00
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__link-preview__content',
|
|
|
|
withContentAbove || isFullSizeImage
|
|
|
|
? 'module-message__link-preview__content--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{first.image && previewHasImage && !isFullSizeImage ? (
|
|
|
|
<div className="module-message__link-preview__icon_container">
|
|
|
|
<Image
|
|
|
|
smallCurveTopLeft={!withContentAbove}
|
2019-05-29 21:59:14 +00:00
|
|
|
noBorder={true}
|
|
|
|
noBackground={true}
|
2019-01-16 03:03:56 +00:00
|
|
|
softCorners={true}
|
|
|
|
alt={i18n('previewThumbnail', [first.domain])}
|
|
|
|
height={72}
|
|
|
|
width={72}
|
|
|
|
url={first.image.url}
|
|
|
|
attachment={first.image}
|
2019-11-07 21:36:16 +00:00
|
|
|
onError={this.handleImageError}
|
2019-01-16 03:03:56 +00:00
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__link-preview__text',
|
|
|
|
previewHasImage && !isFullSizeImage
|
|
|
|
? 'module-message__link-preview__text--with-icon'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<div className="module-message__link-preview__title">
|
|
|
|
{first.title}
|
|
|
|
</div>
|
|
|
|
<div className="module-message__link-preview__location">
|
|
|
|
{first.domain}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2019-01-16 03:03:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
public renderQuote() {
|
2018-10-18 18:57:10 +00:00
|
|
|
const {
|
|
|
|
conversationType,
|
|
|
|
authorColor,
|
|
|
|
direction,
|
2019-03-15 22:18:00 +00:00
|
|
|
disableScroll,
|
2018-10-18 18:57:10 +00:00
|
|
|
i18n,
|
|
|
|
quote,
|
2019-05-31 22:42:01 +00:00
|
|
|
scrollToQuotedMessage,
|
2018-10-18 18:57:10 +00:00
|
|
|
} = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
|
|
|
if (!quote) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const withContentAbove =
|
|
|
|
conversationType === 'group' && direction === 'incoming';
|
2018-10-18 18:57:10 +00:00
|
|
|
const quoteColor =
|
|
|
|
direction === 'incoming' ? authorColor : quote.authorColor;
|
2019-03-15 22:18:00 +00:00
|
|
|
const { referencedMessageNotFound } = quote;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
const clickHandler = disableScroll
|
|
|
|
? undefined
|
|
|
|
: () => {
|
2019-05-31 22:42:01 +00:00
|
|
|
scrollToQuotedMessage({
|
2019-03-15 22:18:00 +00:00
|
|
|
author: quote.authorId,
|
|
|
|
sentAt: quote.sentAt,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
|
|
|
<Quote
|
|
|
|
i18n={i18n}
|
2019-03-15 22:18:00 +00:00
|
|
|
onClick={clickHandler}
|
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}
|
2018-10-18 18:57:10 +00:00
|
|
|
authorColor={quoteColor}
|
2019-03-15 22:18:00 +00:00
|
|
|
referencedMessageNotFound={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,
|
2019-03-15 22:18:00 +00:00
|
|
|
showContactDetail,
|
2018-06-27 20:53:49 +00:00
|
|
|
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;
|
|
|
|
|
2019-11-15 02:12:31 +00:00
|
|
|
const otherContent = (contact && contact.signalAccount) || withCaption;
|
|
|
|
const tabIndex = otherContent ? 0 : -1;
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
|
|
|
<EmbeddedContact
|
2018-07-09 21:29:13 +00:00
|
|
|
contact={contact}
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming={direction === 'incoming'}
|
|
|
|
i18n={i18n}
|
2019-03-15 22:18:00 +00:00
|
|
|
onClick={() => {
|
|
|
|
showContactDetail({ contact, signalAccount: contact.signalAccount });
|
|
|
|
}}
|
2018-06-27 20:53:49 +00:00
|
|
|
withContentAbove={withContentAbove}
|
|
|
|
withContentBelow={withContentBelow}
|
2019-11-15 02:12:31 +00:00
|
|
|
tabIndex={tabIndex}
|
2018-06-27 20:53:49 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderSendMessageButton() {
|
2019-03-15 22:18:00 +00:00
|
|
|
const { contact, openConversation, i18n } = this.props;
|
|
|
|
if (!contact || !contact.signalAccount) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2019-03-15 22:18:00 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (contact.signalAccount) {
|
|
|
|
openConversation(contact.signalAccount);
|
|
|
|
}
|
|
|
|
}}
|
2018-06-27 20:53:49 +00:00
|
|
|
className="module-message__send-message-button"
|
|
|
|
>
|
|
|
|
{i18n('sendMessageToContact')}
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAvatar() {
|
|
|
|
const {
|
2018-09-27 00:23:17 +00:00
|
|
|
authorAvatarPath,
|
2018-06-27 20:53:49 +00:00
|
|
|
authorName,
|
|
|
|
authorPhoneNumber,
|
|
|
|
authorProfileName,
|
|
|
|
collapseMetadata,
|
2018-10-09 22:56:14 +00:00
|
|
|
authorColor,
|
2018-06-27 20:53:49 +00:00
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (
|
|
|
|
collapseMetadata ||
|
|
|
|
conversationType !== 'group' ||
|
|
|
|
direction === 'outgoing'
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-message__author-avatar">
|
2018-09-27 00:23:17 +00:00
|
|
|
<Avatar
|
|
|
|
avatarPath={authorAvatarPath}
|
2018-10-09 22:56:14 +00:00
|
|
|
color={authorColor}
|
2018-09-27 00:23:17 +00:00
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
name={authorName}
|
|
|
|
phoneNumber={authorPhoneNumber}
|
|
|
|
profileName={authorProfileName}
|
2019-10-04 18:06:17 +00:00
|
|
|
size={28}
|
2018-09-27 00:23:17 +00:00
|
|
|
/>
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderText() {
|
2019-03-13 20:38:28 +00:00
|
|
|
const { text, textPending, i18n, direction, status } = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
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
|
|
|
)}
|
|
|
|
>
|
2019-03-13 20:38:28 +00:00
|
|
|
<MessageBody
|
|
|
|
text={contents || ''}
|
|
|
|
i18n={i18n}
|
|
|
|
textPending={textPending}
|
|
|
|
/>
|
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 renderMenu(isCorrectSide: boolean, triggerId: string) {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2018-07-09 21:29:13 +00:00
|
|
|
direction,
|
|
|
|
disableMenu,
|
2019-03-15 22:18:00 +00:00
|
|
|
id,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
isTapToView,
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage,
|
2018-07-09 21:29:13 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!isCorrectSide || disableMenu) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
const multipleAttachments = attachments && attachments.length > 1;
|
2019-01-30 20:15:07 +00:00
|
|
|
const firstAttachment = attachments && attachments[0];
|
2018-10-04 01:12:42 +00:00
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
const downloadButton =
|
2019-05-16 22:32:11 +00:00
|
|
|
!isSticker &&
|
|
|
|
!multipleAttachments &&
|
2019-06-26 19:33:13 +00:00
|
|
|
!isTapToView &&
|
2019-05-16 22:32:11 +00:00
|
|
|
firstAttachment &&
|
|
|
|
!firstAttachment.pending ? (
|
2018-11-14 18:47:19 +00:00
|
|
|
<div
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={this.openGenericAttachment}
|
|
|
|
// This a menu meant for mouse use only
|
2018-11-14 18:47:19 +00:00
|
|
|
role="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__download',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
const replyButton = (
|
|
|
|
<div
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage(id);
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
// This a menu meant for mouse use only
|
2018-07-09 21:29:13 +00:00
|
|
|
role="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__reply',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuButton = (
|
2019-11-07 21:36:16 +00:00
|
|
|
<ContextMenuTrigger id={triggerId} ref={this.captureMenuTrigger as any}>
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
2019-11-07 21:36:16 +00:00
|
|
|
// This a menu meant for mouse use only
|
2018-07-09 21:29:13 +00:00
|
|
|
role="button"
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={this.showMenu}
|
2018-07-09 21:29:13 +00:00
|
|
|
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-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2019-06-26 19:33:13 +00:00
|
|
|
deleteMessage,
|
2018-07-09 21:29:13 +00:00
|
|
|
direction,
|
|
|
|
i18n,
|
2019-03-15 22:18:00 +00:00
|
|
|
id,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
isTapToView,
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage,
|
|
|
|
retrySend,
|
2019-06-26 19:33:13 +00:00
|
|
|
showMessageDetail,
|
2019-03-15 22:18:00 +00:00
|
|
|
status,
|
2018-07-09 21:29:13 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const showRetry = status === 'error' && direction === 'outgoing';
|
2018-11-14 18:47:19 +00:00
|
|
|
const multipleAttachments = attachments && attachments.length > 1;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
const menu = (
|
2018-07-09 21:29:13 +00:00
|
|
|
<ContextMenu id={triggerId}>
|
2019-06-26 19:33:13 +00:00
|
|
|
{!isSticker &&
|
|
|
|
!multipleAttachments &&
|
|
|
|
!isTapToView &&
|
|
|
|
attachments &&
|
|
|
|
attachments[0] ? (
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__download',
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={this.openGenericAttachment}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{i18n('downloadAttachment')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__reply',
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage(id);
|
|
|
|
}}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{i18n('replyToMessage')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className: 'module-message__context__more-info',
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
showMessageDetail(id);
|
|
|
|
}}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{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',
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
retrySend(id);
|
|
|
|
}}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{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',
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
deleteMessage(id);
|
|
|
|
}}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{i18n('deleteMessage')}
|
|
|
|
</MenuItem>
|
2018-07-09 21:29:13 +00:00
|
|
|
</ContextMenu>
|
|
|
|
);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
return ReactDOM.createPortal(menu, document.body);
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
public getWidth(): number | undefined {
|
2019-05-16 22:32:11 +00:00
|
|
|
const { attachments, isSticker, previews } = this.props;
|
2019-01-16 03:03:56 +00:00
|
|
|
|
|
|
|
if (attachments && attachments.length) {
|
2019-05-16 22:32:11 +00:00
|
|
|
if (isSticker) {
|
2019-11-07 21:36:16 +00:00
|
|
|
// Padding is 8px, on both sides, plus two for 1px border
|
|
|
|
return STICKER_SIZE + 8 * 2 + 2;
|
2019-05-16 22:32:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 03:03:56 +00:00
|
|
|
const dimensions = getGridDimensions(attachments);
|
|
|
|
if (dimensions) {
|
2019-11-07 21:36:16 +00:00
|
|
|
// Add two for 1px border
|
|
|
|
return dimensions.width + 2;
|
2019-01-16 03:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previews && previews.length) {
|
|
|
|
const first = previews[0];
|
|
|
|
|
|
|
|
if (!first || !first.image) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { width } = first.image;
|
|
|
|
|
|
|
|
if (
|
2019-05-16 22:32:11 +00:00
|
|
|
!first.isStickerPack &&
|
2019-01-16 03:03:56 +00:00
|
|
|
isImageAttachment(first.image) &&
|
|
|
|
width &&
|
|
|
|
width >= MINIMUM_LINK_PREVIEW_IMAGE_WIDTH
|
|
|
|
) {
|
|
|
|
const dimensions = getImageDimensions(first.image);
|
|
|
|
if (dimensions) {
|
2019-11-07 21:36:16 +00:00
|
|
|
// Add two for 1px border
|
|
|
|
return dimensions.width + 2;
|
2019-01-16 03:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public isShowingImage() {
|
2019-06-26 19:33:13 +00:00
|
|
|
const { isTapToView, attachments, previews } = this.props;
|
2019-01-16 03:03:56 +00:00
|
|
|
const { imageBroken } = this.state;
|
|
|
|
|
2019-06-26 19:33:13 +00:00
|
|
|
if (imageBroken || isTapToView) {
|
2019-01-16 03:03:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachments && attachments.length) {
|
|
|
|
const displayImage = canDisplayImage(attachments);
|
|
|
|
|
|
|
|
return (
|
|
|
|
displayImage &&
|
|
|
|
((isImage(attachments) && hasImage(attachments)) ||
|
|
|
|
(isVideo(attachments) && hasVideoScreenshot(attachments)))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previews && previews.length) {
|
|
|
|
const first = previews[0];
|
|
|
|
const { image } = first;
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isImageAttachment(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-26 19:33:13 +00:00
|
|
|
public isAttachmentPending() {
|
|
|
|
const { attachments } = this.props;
|
|
|
|
|
|
|
|
if (!attachments || attachments.length < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const first = attachments[0];
|
|
|
|
|
|
|
|
return Boolean(first.pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderTapToViewIcon() {
|
|
|
|
const { direction, isTapToViewExpired } = this.props;
|
|
|
|
const isDownloadPending = this.isAttachmentPending();
|
|
|
|
|
|
|
|
return !isTapToViewExpired && isDownloadPending ? (
|
|
|
|
<div className="module-message__tap-to-view__spinner-container">
|
|
|
|
<Spinner svgSize="small" size="20px" direction={direction} />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__tap-to-view__icon',
|
|
|
|
`module-message__tap-to-view__icon--${direction}`,
|
|
|
|
isTapToViewExpired
|
|
|
|
? 'module-message__tap-to-view__icon--expired'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderTapToViewText() {
|
|
|
|
const {
|
2019-10-03 19:03:46 +00:00
|
|
|
attachments,
|
2019-06-26 19:33:13 +00:00
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
isTapToViewExpired,
|
|
|
|
isTapToViewError,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const incomingString = isTapToViewExpired
|
|
|
|
? i18n('Message--tap-to-view-expired')
|
2019-10-03 19:03:46 +00:00
|
|
|
: i18n(
|
|
|
|
`Message--tap-to-view--incoming${
|
|
|
|
isVideo(attachments) ? '-video' : ''
|
|
|
|
}`
|
|
|
|
);
|
2019-06-26 19:33:13 +00:00
|
|
|
const outgoingString = i18n('Message--tap-to-view--outgoing');
|
|
|
|
const isDownloadPending = this.isAttachmentPending();
|
|
|
|
|
|
|
|
if (isDownloadPending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isTapToViewError
|
|
|
|
? i18n('incomingError')
|
|
|
|
: direction === 'outgoing'
|
2020-01-08 17:44:54 +00:00
|
|
|
? outgoingString
|
|
|
|
: incomingString;
|
2019-06-26 19:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public renderTapToView() {
|
|
|
|
const {
|
|
|
|
collapseMetadata,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
isTapToViewExpired,
|
|
|
|
isTapToViewError,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const withContentBelow = !collapseMetadata;
|
|
|
|
const withContentAbove =
|
|
|
|
!collapseMetadata &&
|
|
|
|
conversationType === 'group' &&
|
|
|
|
direction === 'incoming';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__tap-to-view',
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__tap-to-view--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__tap-to-view--with-content-above'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{isTapToViewError ? null : this.renderTapToViewIcon()}
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__tap-to-view__text',
|
|
|
|
`module-message__tap-to-view__text--${direction}`,
|
|
|
|
isTapToViewExpired
|
|
|
|
? `module-message__tap-to-view__text--${direction}-expired`
|
|
|
|
: null,
|
|
|
|
isTapToViewError
|
|
|
|
? `module-message__tap-to-view__text--${direction}-error`
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.renderTapToViewText()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderContents() {
|
|
|
|
const { isTapToView } = this.props;
|
|
|
|
|
|
|
|
if (isTapToView) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.renderTapToView()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.renderQuote()}
|
|
|
|
{this.renderAttachment()}
|
|
|
|
{this.renderPreview()}
|
|
|
|
{this.renderEmbeddedContact()}
|
|
|
|
{this.renderText()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
{this.renderSendMessageButton()}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line cyclomatic-complexity
|
2019-11-07 21:36:16 +00:00
|
|
|
public handleOpen = (
|
|
|
|
event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent
|
|
|
|
) => {
|
2018-07-09 21:29:13 +00:00
|
|
|
const {
|
2019-05-16 22:32:11 +00:00
|
|
|
attachments,
|
2019-11-15 02:12:31 +00:00
|
|
|
contact,
|
2019-06-26 19:33:13 +00:00
|
|
|
displayTapToViewMessage,
|
2018-06-27 20:53:49 +00:00
|
|
|
id,
|
2019-11-07 21:36:16 +00:00
|
|
|
isTapToView,
|
|
|
|
isTapToViewExpired,
|
2019-11-15 02:12:31 +00:00
|
|
|
openConversation,
|
|
|
|
showContactDetail,
|
2019-11-07 21:36:16 +00:00
|
|
|
showVisualAttachment,
|
|
|
|
} = this.props;
|
|
|
|
const { imageBroken } = this.state;
|
|
|
|
|
|
|
|
const isAttachmentPending = this.isAttachmentPending();
|
|
|
|
|
|
|
|
if (isTapToView) {
|
|
|
|
if (!isTapToViewExpired && !isAttachmentPending) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
displayTapToViewMessage(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!imageBroken &&
|
|
|
|
attachments &&
|
|
|
|
attachments.length > 0 &&
|
|
|
|
!isAttachmentPending &&
|
|
|
|
canDisplayImage(attachments) &&
|
|
|
|
((isImage(attachments) && hasImage(attachments)) ||
|
|
|
|
(isVideo(attachments) && hasVideoScreenshot(attachments)))
|
|
|
|
) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const attachment = attachments[0];
|
|
|
|
|
|
|
|
showVisualAttachment({ attachment, messageId: id });
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
attachments &&
|
|
|
|
attachments.length === 1 &&
|
|
|
|
!isAttachmentPending &&
|
|
|
|
!isAudio(attachments)
|
|
|
|
) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
this.openGenericAttachment();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!isAttachmentPending &&
|
|
|
|
isAudio(attachments) &&
|
|
|
|
this.audioRef &&
|
|
|
|
this.audioRef.current
|
|
|
|
) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
if (this.audioRef.current.paused) {
|
|
|
|
// tslint:disable-next-line no-floating-promises
|
|
|
|
this.audioRef.current.play();
|
|
|
|
} else {
|
|
|
|
// tslint:disable-next-line no-floating-promises
|
|
|
|
this.audioRef.current.pause();
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 02:12:31 +00:00
|
|
|
|
|
|
|
if (contact && contact.signalAccount) {
|
|
|
|
openConversation(contact.signalAccount);
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact) {
|
|
|
|
showContactDetail({ contact, signalAccount: contact.signalAccount });
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public openGenericAttachment = (event?: React.MouseEvent) => {
|
|
|
|
const { attachments, downloadAttachment, timestamp } = this.props;
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!attachments || attachments.length !== 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const attachment = attachments[0];
|
|
|
|
const { fileName } = attachment;
|
|
|
|
const isDangerous = isFileDangerous(fileName || '');
|
|
|
|
|
|
|
|
downloadAttachment({
|
|
|
|
isDangerous,
|
|
|
|
attachment,
|
|
|
|
timestamp,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
public handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
|
|
if (event.key !== 'Enter' && event.key !== 'Space') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.handleOpen(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
public handleClick = (event: React.MouseEvent) => {
|
|
|
|
// We don't want clicks on body text to result in the 'default action' for the message
|
|
|
|
const { text } = this.props;
|
|
|
|
if (text && text.length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.handleOpen(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
public renderContainer() {
|
|
|
|
const {
|
|
|
|
authorColor,
|
|
|
|
direction,
|
2019-05-16 22:32:11 +00:00
|
|
|
isSticker,
|
2019-06-26 19:33:13 +00:00
|
|
|
isTapToView,
|
|
|
|
isTapToViewExpired,
|
|
|
|
isTapToViewError,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
2019-11-21 19:16:06 +00:00
|
|
|
const { isSelected } = this.state;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-06-26 19:33:13 +00:00
|
|
|
const isAttachmentPending = this.isAttachmentPending();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
|
|
|
const width = this.getWidth();
|
|
|
|
const isShowingImage = this.isShowingImage();
|
|
|
|
|
|
|
|
const containerClassnames = classNames(
|
|
|
|
'module-message__container',
|
|
|
|
isSelected && !isSticker ? 'module-message__container--selected' : null,
|
|
|
|
isSticker ? 'module-message__container--with-sticker' : null,
|
|
|
|
!isSticker ? `module-message__container--${direction}` : null,
|
|
|
|
isTapToView ? 'module-message__container--with-tap-to-view' : null,
|
|
|
|
isTapToView && isTapToViewExpired
|
|
|
|
? 'module-message__container--with-tap-to-view-expired'
|
|
|
|
: null,
|
|
|
|
!isSticker && direction === 'incoming'
|
|
|
|
? `module-message__container--incoming-${authorColor}`
|
|
|
|
: null,
|
|
|
|
isTapToView && isAttachmentPending && !isTapToViewExpired
|
|
|
|
? 'module-message__container--with-tap-to-view-pending'
|
|
|
|
: null,
|
|
|
|
isTapToView && isAttachmentPending && !isTapToViewExpired
|
|
|
|
? `module-message__container--${direction}-${authorColor}-tap-to-view-pending`
|
|
|
|
: null,
|
|
|
|
isTapToViewError
|
|
|
|
? 'module-message__container--with-tap-to-view-error'
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
const containerStyles = {
|
|
|
|
width: isShowingImage ? width : undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={containerClassnames} style={containerStyles}>
|
|
|
|
{this.renderAuthor()}
|
|
|
|
{this.renderContents()}
|
|
|
|
{this.renderAvatar()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line cyclomatic-complexity
|
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
authorPhoneNumber,
|
|
|
|
attachments,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
id,
|
|
|
|
isSticker,
|
|
|
|
timestamp,
|
|
|
|
} = this.props;
|
2019-11-21 19:16:06 +00:00
|
|
|
const { expired, expiring, imageBroken, isSelected } = 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
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
if (isSticker && (imageBroken || !attachments || !attachments.length)) {
|
|
|
|
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}`,
|
2019-11-21 19:16:06 +00:00
|
|
|
isSelected ? 'module-message--selected' : null,
|
2019-05-31 22:42:01 +00:00
|
|
|
expiring ? 'module-message--expired' : null,
|
|
|
|
conversationType === 'group' ? 'module-message--group' : null
|
2018-07-09 21:29:13 +00:00
|
|
|
)}
|
2019-11-07 21:36:16 +00:00
|
|
|
tabIndex={0}
|
|
|
|
// We pretend to be a button because we sometimes contain buttons and a button
|
|
|
|
// cannot be within another button
|
|
|
|
role="button"
|
|
|
|
onKeyDown={this.handleKeyDown}
|
|
|
|
onClick={this.handleClick}
|
2019-11-21 19:16:06 +00:00
|
|
|
onFocus={this.handleFocus}
|
2019-11-07 21:36:16 +00:00
|
|
|
ref={this.focusRef}
|
2018-07-09 21:29:13 +00:00
|
|
|
>
|
|
|
|
{this.renderError(direction === 'incoming')}
|
|
|
|
{this.renderMenu(direction === 'outgoing', triggerId)}
|
2019-11-07 21:36:16 +00:00
|
|
|
{this.renderContainer()}
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|