2022-03-04 21:14:52 +00:00
|
|
|
// Copyright 2018-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
import React, { useRef, useState, useEffect } from 'react';
|
2021-01-21 23:57:07 +00:00
|
|
|
import { noop } from 'lodash';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
import * as MIME from '../../types/MIME';
|
|
|
|
import * as GoogleChrome from '../../util/GoogleChrome';
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2018-05-14 20:52:10 +00:00
|
|
|
import { MessageBody } from './MessageBody';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { AttachmentType, ThumbnailType } from '../../types/Attachment';
|
2022-11-10 04:59:36 +00:00
|
|
|
import type { HydratedBodyRangesType, LocalizerType } from '../../types/Util';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
|
|
|
ConversationColorType,
|
|
|
|
CustomColorType,
|
|
|
|
} from '../../types/Colors';
|
2018-07-09 21:29:13 +00:00
|
|
|
import { ContactName } from './ContactName';
|
2022-05-10 19:02:21 +00:00
|
|
|
import { Emojify } from './Emojify';
|
|
|
|
import { TextAttachment } from '../TextAttachment';
|
2020-09-18 21:43:57 +00:00
|
|
|
import { getTextWithMentions } from '../../util/getTextWithMentions';
|
2022-03-16 17:30:14 +00:00
|
|
|
import { getClassNamesFor } from '../../util/getClassNamesFor';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { getCustomColorStyle } from '../../util/getCustomColorStyle';
|
2022-11-30 21:47:54 +00:00
|
|
|
import type { AnyPaymentEvent } from '../../types/Payment';
|
|
|
|
import { PaymentEventKind } from '../../types/Payment';
|
|
|
|
import { getPaymentEventNotificationText } from '../../messages/helpers';
|
2018-05-14 20:52:10 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type Props = {
|
2020-07-24 01:35:32 +00:00
|
|
|
authorTitle: string;
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor: ConversationColorType;
|
2022-11-30 21:47:54 +00:00
|
|
|
conversationTitle: string;
|
2021-05-28 16:15:17 +00:00
|
|
|
customColor?: CustomColorType;
|
2022-11-10 04:59:36 +00:00
|
|
|
bodyRanges?: HydratedBodyRangesType;
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe: boolean;
|
2021-09-13 02:36:41 +00:00
|
|
|
isIncoming?: boolean;
|
2022-06-15 17:53:08 +00:00
|
|
|
isCompose?: boolean;
|
2022-05-10 19:02:21 +00:00
|
|
|
isStoryReply?: boolean;
|
2022-03-16 17:30:14 +00:00
|
|
|
moduleClassName?: string;
|
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;
|
2021-03-25 18:36:50 +00:00
|
|
|
rawAttachment?: QuotedAttachmentType;
|
2022-11-30 21:47:54 +00:00
|
|
|
payment?: AnyPaymentEvent;
|
2022-05-11 20:59:58 +00:00
|
|
|
isGiftBadge: boolean;
|
2021-06-02 16:42:19 +00:00
|
|
|
isViewOnce: boolean;
|
2022-05-10 19:02:21 +00:00
|
|
|
reactionEmoji?: string;
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound: boolean;
|
2021-09-13 02:36:41 +00:00
|
|
|
doubleCheckMissingQuoteReference?: () => unknown;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type State = {
|
2019-01-30 20:15:07 +00:00
|
|
|
imageBroken: boolean;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
export type QuotedAttachmentType = Pick<
|
|
|
|
AttachmentType,
|
2022-04-15 00:08:46 +00:00
|
|
|
'contentType' | 'fileName' | 'isVoiceMessage' | 'thumbnail' | 'textAttachment'
|
2022-03-04 21:14:52 +00:00
|
|
|
>;
|
2018-04-10 01:31:52 +00:00
|
|
|
|
|
|
|
function validateQuote(quote: Props): boolean {
|
2022-05-10 19:02:21 +00:00
|
|
|
if (
|
|
|
|
quote.isStoryReply &&
|
|
|
|
(quote.referencedMessageNotFound || quote.reactionEmoji)
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-11 20:59:58 +00:00
|
|
|
if (quote.isGiftBadge) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-10 01:31:52 +00:00
|
|
|
if (quote.text) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-25 18:36:50 +00:00
|
|
|
if (quote.rawAttachment) {
|
2018-04-10 01:31:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-30 21:47:54 +00:00
|
|
|
if (quote.payment?.kind === PaymentEventKind.Notification) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-10 01:31:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-25 18:36:50 +00:00
|
|
|
// Long message attachments should not be shown.
|
|
|
|
function getAttachment(
|
|
|
|
rawAttachment: undefined | QuotedAttachmentType
|
|
|
|
): undefined | QuotedAttachmentType {
|
|
|
|
return rawAttachment && !MIME.isLongMessage(rawAttachment.contentType)
|
|
|
|
? rawAttachment
|
|
|
|
: undefined;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
function getUrl(thumbnail?: ThumbnailType): string | undefined {
|
|
|
|
if (!thumbnail) {
|
|
|
|
return;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
return thumbnail.objectUrl || thumbnail.url;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
function getTypeLabel({
|
|
|
|
i18n,
|
2021-06-02 16:42:19 +00:00
|
|
|
isViewOnce = false,
|
2018-06-27 20:53:49 +00:00
|
|
|
contentType,
|
|
|
|
isVoiceMessage,
|
|
|
|
}: {
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2021-06-02 16:42:19 +00:00
|
|
|
isViewOnce?: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
contentType: MIME.MIMEType;
|
2022-03-04 21:14:52 +00:00
|
|
|
isVoiceMessage?: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
}): string | undefined {
|
2018-06-27 20:53:49 +00:00
|
|
|
if (GoogleChrome.isVideoTypeSupported(contentType)) {
|
2021-06-02 16:42:19 +00:00
|
|
|
if (isViewOnce) {
|
|
|
|
return i18n('message--getDescription--disappearing-video');
|
|
|
|
}
|
2018-06-27 20:53:49 +00:00
|
|
|
return i18n('video');
|
|
|
|
}
|
|
|
|
if (GoogleChrome.isImageTypeSupported(contentType)) {
|
2021-06-02 16:42:19 +00:00
|
|
|
if (isViewOnce) {
|
|
|
|
return i18n('message--getDescription--disappearing-photo');
|
|
|
|
}
|
2018-06-27 20:53:49 +00:00
|
|
|
return i18n('photo');
|
|
|
|
}
|
2021-06-02 16:42:19 +00:00
|
|
|
|
|
|
|
if (isViewOnce) {
|
|
|
|
return i18n('message--getDescription--disappearing-media');
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
if (MIME.isAudio(contentType) && isVoiceMessage) {
|
|
|
|
return i18n('voiceMessage');
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
return MIME.isAudio(contentType) ? i18n('audio') : undefined;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
export class Quote extends React.Component<Props, State> {
|
2022-03-16 17:30:14 +00:00
|
|
|
private getClassName: (modifier?: string) => string;
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
imageBroken: false,
|
|
|
|
};
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName = getClassNamesFor('module-quote', props.moduleClassName);
|
2020-09-14 19:51:27 +00:00
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2021-11-12 23:44:20 +00:00
|
|
|
override componentDidMount(): void {
|
2021-11-11 22:43:05 +00:00
|
|
|
const { doubleCheckMissingQuoteReference, referencedMessageNotFound } =
|
|
|
|
this.props;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
if (referencedMessageNotFound) {
|
2021-09-13 02:36:41 +00:00
|
|
|
doubleCheckMissingQuoteReference?.();
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleKeyDown = (
|
|
|
|
event: React.KeyboardEvent<HTMLButtonElement>
|
|
|
|
): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
const { onClick } = this.props;
|
|
|
|
|
|
|
|
// This is important to ensure that using this quote to navigate to the referenced
|
|
|
|
// message doesn't also trigger its parent message's keydown.
|
2019-11-21 19:16:06 +00:00
|
|
|
if (onClick && (event.key === 'Enter' || event.key === ' ')) {
|
2019-11-07 21:36:16 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
};
|
2020-09-14 19:51:27 +00:00
|
|
|
|
|
|
|
public handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => {
|
2020-01-22 19:34:36 +00:00
|
|
|
const { onClick } = this.props;
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
};
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleImageError = (): void => {
|
|
|
|
window.console.info(
|
|
|
|
'Message: Image failed to load; failing over to placeholder'
|
|
|
|
);
|
2019-01-30 20:15:07 +00:00
|
|
|
this.setState({
|
|
|
|
imageBroken: true,
|
|
|
|
});
|
2019-11-07 21:36:16 +00:00
|
|
|
};
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2022-05-11 20:59:58 +00:00
|
|
|
public renderImage(
|
|
|
|
url: string,
|
|
|
|
icon: string | undefined,
|
|
|
|
isGiftBadge?: boolean
|
|
|
|
): JSX.Element {
|
|
|
|
const { isIncoming } = this.props;
|
2018-04-27 21:25:04 +00:00
|
|
|
const iconElement = icon ? (
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__icon-container__inner')}>
|
|
|
|
<div
|
|
|
|
className={this.getClassName('__icon-container__circle-background')}
|
|
|
|
>
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__icon-container__icon'),
|
|
|
|
this.getClassName(`__icon-container__icon--${icon}`)
|
2018-06-27 20:53:49 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-04-27 21:25:04 +00:00
|
|
|
) : null;
|
2018-04-12 07:33:52 +00:00
|
|
|
|
2018-04-12 06:55:32 +00:00
|
|
|
return (
|
2022-03-16 17:30:14 +00:00
|
|
|
<ThumbnailImage
|
2022-05-11 20:59:58 +00:00
|
|
|
className={classNames(
|
|
|
|
this.getClassName('__icon-container'),
|
|
|
|
isIncoming === false &&
|
|
|
|
isGiftBadge &&
|
|
|
|
this.getClassName('__icon-container__outgoing-gift-badge')
|
|
|
|
)}
|
2022-03-16 17:30:14 +00:00
|
|
|
src={url}
|
|
|
|
onError={this.handleImageError}
|
|
|
|
>
|
2018-06-27 20:53:49 +00:00
|
|
|
{iconElement}
|
2021-01-21 23:57:07 +00:00
|
|
|
</ThumbnailImage>
|
2018-04-12 06:55:32 +00:00
|
|
|
);
|
|
|
|
}
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderIcon(icon: string): JSX.Element {
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__icon-container')}>
|
|
|
|
<div className={this.getClassName('__icon-container__inner')}>
|
|
|
|
<div
|
|
|
|
className={this.getClassName('__icon-container__circle-background')}
|
|
|
|
>
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__icon-container__icon'),
|
|
|
|
this.getClassName(`__icon-container__icon--${icon}`)
|
2018-06-27 20:53:49 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-04-12 06:55:32 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderGenericFile(): JSX.Element | null {
|
2021-03-25 18:36:50 +00:00
|
|
|
const { rawAttachment, isIncoming } = this.props;
|
|
|
|
const attachment = getAttachment(rawAttachment);
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
if (!attachment) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return null;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
const { fileName, contentType, textAttachment } = attachment;
|
2018-06-27 20:53:49 +00:00
|
|
|
const isGenericFile =
|
|
|
|
!GoogleChrome.isVideoTypeSupported(contentType) &&
|
|
|
|
!GoogleChrome.isImageTypeSupported(contentType) &&
|
2022-04-15 00:08:46 +00:00
|
|
|
!textAttachment &&
|
2018-06-27 20:53:49 +00:00
|
|
|
!MIME.isAudio(contentType);
|
|
|
|
|
|
|
|
if (!isGenericFile) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-12 06:55:32 +00:00
|
|
|
|
|
|
|
return (
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__generic-file')}>
|
|
|
|
<div className={this.getClassName('__generic-file__icon')} />
|
2018-08-14 00:06:50 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__generic-file__text'),
|
|
|
|
isIncoming
|
|
|
|
? this.getClassName('__generic-file__text--incoming')
|
|
|
|
: null
|
2018-08-14 00:06:50 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{fileName}
|
|
|
|
</div>
|
2018-04-12 06:55:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:47:54 +00:00
|
|
|
public renderPayment(): JSX.Element | null {
|
|
|
|
const { payment, authorTitle, conversationTitle, isFromMe, i18n } =
|
|
|
|
this.props;
|
|
|
|
|
|
|
|
if (payment == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Emojify text="💳" />
|
|
|
|
{getPaymentEventNotificationText(
|
|
|
|
payment,
|
|
|
|
authorTitle,
|
|
|
|
conversationTitle,
|
|
|
|
isFromMe,
|
|
|
|
i18n
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderIconContainer(): JSX.Element | null {
|
2022-05-11 20:59:58 +00:00
|
|
|
const { isGiftBadge, isViewOnce, i18n, rawAttachment } = this.props;
|
2019-01-30 20:15:07 +00:00
|
|
|
const { imageBroken } = this.state;
|
2021-03-25 18:36:50 +00:00
|
|
|
const attachment = getAttachment(rawAttachment);
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2022-05-11 20:59:58 +00:00
|
|
|
if (isGiftBadge) {
|
|
|
|
return this.renderImage('images/gift-thumbnail.svg', undefined, true);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
if (!attachment) {
|
2018-04-10 01:31:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
const { contentType, textAttachment, thumbnail } = attachment;
|
2022-03-04 21:14:52 +00:00
|
|
|
const url = getUrl(thumbnail);
|
2018-04-12 06:55:32 +00:00
|
|
|
|
2021-06-02 16:42:19 +00:00
|
|
|
if (isViewOnce) {
|
|
|
|
return this.renderIcon('view-once');
|
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
if (textAttachment) {
|
2022-05-10 19:02:21 +00:00
|
|
|
return (
|
|
|
|
<div className={this.getClassName('__icon-container')}>
|
|
|
|
<TextAttachment
|
|
|
|
i18n={i18n}
|
|
|
|
isThumbnail
|
|
|
|
textAttachment={textAttachment}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2022-04-15 00:08:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 21:16:26 +00:00
|
|
|
if (GoogleChrome.isVideoTypeSupported(contentType)) {
|
2022-03-04 21:14:52 +00:00
|
|
|
return url && !imageBroken
|
|
|
|
? this.renderImage(url, 'play')
|
2018-04-19 01:20:36 +00:00
|
|
|
: this.renderIcon('movie');
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
2018-04-24 21:16:26 +00:00
|
|
|
if (GoogleChrome.isImageTypeSupported(contentType)) {
|
2022-03-04 21:14:52 +00:00
|
|
|
return url && !imageBroken
|
2022-05-11 20:59:58 +00:00
|
|
|
? this.renderImage(url, undefined)
|
2018-05-22 19:31:43 +00:00
|
|
|
: this.renderIcon('image');
|
2018-04-12 06:55:32 +00:00
|
|
|
}
|
2018-04-09 23:24:24 +00:00
|
|
|
if (MIME.isAudio(contentType)) {
|
2018-04-12 06:55:32 +00:00
|
|
|
return this.renderIcon('microphone');
|
|
|
|
}
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 22:42:48 +00:00
|
|
|
public renderText(): JSX.Element | null {
|
2022-05-11 20:59:58 +00:00
|
|
|
const {
|
|
|
|
bodyRanges,
|
|
|
|
isGiftBadge,
|
|
|
|
i18n,
|
|
|
|
text,
|
|
|
|
rawAttachment,
|
|
|
|
isIncoming,
|
|
|
|
isViewOnce,
|
|
|
|
} = this.props;
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2022-05-16 19:54:38 +00:00
|
|
|
if (text && !isGiftBadge) {
|
2020-09-18 21:43:57 +00:00
|
|
|
const quoteText = bodyRanges
|
|
|
|
? getTextWithMentions(bodyRanges, text)
|
|
|
|
: text;
|
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
return (
|
2018-08-14 00:06:50 +00:00
|
|
|
<div
|
|
|
|
dir="auto"
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__primary__text'),
|
|
|
|
isIncoming ? this.getClassName('__primary__text--incoming') : null
|
2018-08-14 00:06:50 +00:00
|
|
|
)}
|
|
|
|
>
|
2021-09-16 22:45:32 +00:00
|
|
|
<MessageBody
|
|
|
|
disableLinks
|
|
|
|
disableJumbomoji
|
|
|
|
text={quoteText}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
2018-05-14 20:52:10 +00:00
|
|
|
</div>
|
2018-04-27 21:25:04 +00:00
|
|
|
);
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-25 18:36:50 +00:00
|
|
|
const attachment = getAttachment(rawAttachment);
|
|
|
|
|
2022-05-11 20:59:58 +00:00
|
|
|
let typeLabel;
|
|
|
|
|
|
|
|
if (isGiftBadge) {
|
|
|
|
typeLabel = i18n('quote--giftBadge');
|
|
|
|
} else if (attachment) {
|
|
|
|
const { contentType, isVoiceMessage } = attachment;
|
|
|
|
typeLabel = getTypeLabel({
|
|
|
|
i18n,
|
|
|
|
isViewOnce,
|
|
|
|
contentType,
|
|
|
|
isVoiceMessage,
|
|
|
|
});
|
|
|
|
} else {
|
2018-04-10 01:31:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
if (typeLabel) {
|
|
|
|
return (
|
2018-08-14 00:06:50 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__primary__type-label'),
|
|
|
|
isIncoming
|
|
|
|
? this.getClassName('__primary__type-label--incoming')
|
|
|
|
: null
|
2018-08-14 00:06:50 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{typeLabel}
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
2018-04-12 19:21:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderClose(): JSX.Element | null {
|
|
|
|
const { i18n, onClose } = this.props;
|
2018-04-18 20:06:33 +00:00
|
|
|
|
|
|
|
if (!onClose) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
const clickHandler = (e: React.MouseEvent): void => {
|
2018-04-18 23:10:14 +00:00
|
|
|
e.stopPropagation();
|
2019-11-07 21:36:16 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
2018-04-18 23:10:14 +00:00
|
|
|
onClose();
|
|
|
|
};
|
2019-11-21 19:16:06 +00:00
|
|
|
const keyDownHandler = (e: React.KeyboardEvent): void => {
|
|
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
};
|
2018-04-18 23:10:14 +00:00
|
|
|
|
2018-04-18 20:06:33 +00:00
|
|
|
// We need the container to give us the flexibility to implement the iOS design.
|
|
|
|
return (
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__close-container')}>
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2019-11-07 21:36:16 +00:00
|
|
|
tabIndex={0}
|
|
|
|
// We can't be a button because the overall quote is a button; can't nest them
|
2018-06-27 20:53:49 +00:00
|
|
|
role="button"
|
2022-03-16 17:30:14 +00:00
|
|
|
className={this.getClassName('__close-button')}
|
2020-09-14 19:51:27 +00:00
|
|
|
aria-label={i18n('close')}
|
2019-11-21 19:16:06 +00:00
|
|
|
onKeyDown={keyDownHandler}
|
|
|
|
onClick={clickHandler}
|
2018-06-27 20:53:49 +00:00
|
|
|
/>
|
2018-04-18 20:06:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAuthor(): JSX.Element {
|
2022-05-10 19:02:21 +00:00
|
|
|
const { authorTitle, i18n, isFromMe, isIncoming, isStoryReply } =
|
|
|
|
this.props;
|
|
|
|
|
|
|
|
const title = isFromMe ? i18n('you') : <ContactName title={authorTitle} />;
|
|
|
|
const author = isStoryReply ? (
|
|
|
|
<>
|
|
|
|
{title} · {i18n('Quote__story')}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
title
|
|
|
|
);
|
2018-04-30 19:28:14 +00:00
|
|
|
|
|
|
|
return (
|
2018-07-09 21:29:13 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__primary__author'),
|
|
|
|
isIncoming ? this.getClassName('__primary__author--incoming') : null
|
2018-07-09 21:29:13 +00:00
|
|
|
)}
|
|
|
|
>
|
2022-05-10 19:02:21 +00:00
|
|
|
{author}
|
2018-04-30 19:28:14 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderReferenceWarning(): JSX.Element | null {
|
2021-05-28 16:15:17 +00:00
|
|
|
const {
|
|
|
|
conversationColor,
|
|
|
|
customColor,
|
|
|
|
i18n,
|
|
|
|
isIncoming,
|
2022-05-10 19:02:21 +00:00
|
|
|
isStoryReply,
|
2021-05-28 16:15:17 +00:00
|
|
|
referencedMessageNotFound,
|
|
|
|
} = this.props;
|
2018-08-15 19:31:29 +00:00
|
|
|
|
2022-05-10 19:02:21 +00:00
|
|
|
if (!referencedMessageNotFound || isStoryReply) {
|
2018-08-15 19:31:29 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__reference-warning'),
|
2021-05-28 16:15:17 +00:00
|
|
|
isIncoming
|
2022-03-16 17:30:14 +00:00
|
|
|
? this.getClassName(`--incoming-${conversationColor}`)
|
|
|
|
: this.getClassName(`--outgoing-${conversationColor}`)
|
2018-08-15 19:31:29 +00:00
|
|
|
)}
|
2021-05-28 16:15:17 +00:00
|
|
|
style={{ ...getCustomColorStyle(customColor, true) }}
|
2018-08-15 19:31:29 +00:00
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__reference-warning__icon'),
|
2018-08-15 19:31:29 +00:00
|
|
|
isIncoming
|
2022-03-16 17:30:14 +00:00
|
|
|
? this.getClassName('__reference-warning__icon--incoming')
|
2018-08-15 19:31:29 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName('__reference-warning__text'),
|
2018-08-15 19:31:29 +00:00
|
|
|
isIncoming
|
2022-03-16 17:30:14 +00:00
|
|
|
? this.getClassName('__reference-warning__text--incoming')
|
2018-08-15 19:31:29 +00:00
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('originalMessageNotFound')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-12 23:44:20 +00:00
|
|
|
public override render(): JSX.Element | null {
|
2018-07-09 21:29:13 +00:00
|
|
|
const {
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor,
|
|
|
|
customColor,
|
2022-06-15 17:53:08 +00:00
|
|
|
isCompose,
|
2018-07-09 21:29:13 +00:00
|
|
|
isIncoming,
|
|
|
|
onClick,
|
2022-05-10 19:02:21 +00:00
|
|
|
rawAttachment,
|
|
|
|
reactionEmoji,
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound,
|
2018-07-09 21:29:13 +00:00
|
|
|
} = this.props;
|
2018-04-10 01:31:52 +00:00
|
|
|
|
|
|
|
if (!validateQuote(this.props)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-07-06 16:34:01 +00:00
|
|
|
let colorClassName: string;
|
2022-06-15 17:53:08 +00:00
|
|
|
let directionClassName: string;
|
|
|
|
if (isCompose) {
|
|
|
|
directionClassName = this.getClassName('--compose');
|
2022-07-06 16:34:01 +00:00
|
|
|
colorClassName = this.getClassName(`--compose-${conversationColor}`);
|
2022-06-15 17:53:08 +00:00
|
|
|
} else if (isIncoming) {
|
|
|
|
directionClassName = this.getClassName('--incoming');
|
2022-07-06 16:34:01 +00:00
|
|
|
colorClassName = this.getClassName(`--incoming-${conversationColor}`);
|
2022-06-15 17:53:08 +00:00
|
|
|
} else {
|
|
|
|
directionClassName = this.getClassName('--outgoing');
|
2022-07-06 16:34:01 +00:00
|
|
|
colorClassName = this.getClassName(`--outgoing-${conversationColor}`);
|
2022-06-15 17:53:08 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 22:56:12 +00:00
|
|
|
return (
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__container')}>
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2020-09-14 19:51:27 +00:00
|
|
|
type="button"
|
2020-01-22 19:34:36 +00:00
|
|
|
onClick={this.handleClick}
|
2019-11-07 21:36:16 +00:00
|
|
|
onKeyDown={this.handleKeyDown}
|
2018-08-15 19:31:29 +00:00
|
|
|
className={classNames(
|
2022-03-16 17:30:14 +00:00
|
|
|
this.getClassName(''),
|
2022-06-15 17:53:08 +00:00
|
|
|
directionClassName,
|
|
|
|
colorClassName,
|
2022-03-16 17:30:14 +00:00
|
|
|
!onClick && this.getClassName('--no-click'),
|
|
|
|
referencedMessageNotFound &&
|
2022-05-11 20:59:58 +00:00
|
|
|
this.getClassName('--with-reference-warning')
|
2018-08-15 19:31:29 +00:00
|
|
|
)}
|
2021-05-28 16:15:17 +00:00
|
|
|
style={{ ...getCustomColorStyle(customColor, true) }}
|
2018-08-15 19:31:29 +00:00
|
|
|
>
|
2022-03-16 17:30:14 +00:00
|
|
|
<div className={this.getClassName('__primary')}>
|
2018-08-15 19:31:29 +00:00
|
|
|
{this.renderAuthor()}
|
|
|
|
{this.renderGenericFile()}
|
2022-11-30 21:47:54 +00:00
|
|
|
{this.renderPayment()}
|
2018-08-15 19:31:29 +00:00
|
|
|
{this.renderText()}
|
|
|
|
</div>
|
2022-05-10 19:02:21 +00:00
|
|
|
{reactionEmoji && (
|
|
|
|
<div
|
|
|
|
className={
|
|
|
|
rawAttachment
|
|
|
|
? this.getClassName('__reaction-emoji')
|
|
|
|
: this.getClassName('__reaction-emoji--story-unavailable')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Emojify text={reactionEmoji} />
|
|
|
|
</div>
|
|
|
|
)}
|
2018-08-15 19:31:29 +00:00
|
|
|
{this.renderIconContainer()}
|
|
|
|
{this.renderClose()}
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2018-08-15 19:31:29 +00:00
|
|
|
{this.renderReferenceWarning()}
|
2018-04-10 01:31:52 +00:00
|
|
|
</div>
|
2018-04-03 22:56:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-01-21 23:57:07 +00:00
|
|
|
|
|
|
|
function ThumbnailImage({
|
2022-03-16 17:30:14 +00:00
|
|
|
className,
|
2021-01-21 23:57:07 +00:00
|
|
|
src,
|
|
|
|
onError,
|
|
|
|
children,
|
|
|
|
}: Readonly<{
|
2022-03-16 17:30:14 +00:00
|
|
|
className: string;
|
2021-01-21 23:57:07 +00:00
|
|
|
src: string;
|
|
|
|
onError: () => void;
|
|
|
|
children: ReactNode;
|
|
|
|
}>): JSX.Element {
|
|
|
|
const imageRef = useRef(new Image());
|
|
|
|
const [loadedSrc, setLoadedSrc] = useState<null | string>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const image = new Image();
|
|
|
|
image.onload = () => {
|
|
|
|
setLoadedSrc(src);
|
|
|
|
};
|
|
|
|
image.src = src;
|
|
|
|
imageRef.current = image;
|
|
|
|
return () => {
|
|
|
|
image.onload = noop;
|
|
|
|
};
|
|
|
|
}, [src]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setLoadedSrc(null);
|
|
|
|
}, [src]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const image = imageRef.current;
|
|
|
|
image.onerror = onError;
|
|
|
|
return () => {
|
|
|
|
image.onerror = noop;
|
|
|
|
};
|
|
|
|
}, [onError]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2022-03-16 17:30:14 +00:00
|
|
|
className={className}
|
2021-01-21 23:57:07 +00:00
|
|
|
style={
|
2021-02-19 17:50:32 +00:00
|
|
|
loadedSrc ? { backgroundImage: `url('${encodeURI(loadedSrc)}')` } : {}
|
2021-01-21 23:57:07 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|