2021-01-27 21:15:43 +00:00
|
|
|
// Copyright 2018-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-20 19:36:27 +00:00
|
|
|
import React, { RefObject } from 'react';
|
2020-01-17 22:23:19 +00:00
|
|
|
import ReactDOM, { createPortal } from 'react-dom';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2021-07-18 23:04:34 +00:00
|
|
|
import { drop, groupBy, orderBy, take, unescape } from 'lodash';
|
2020-09-14 19:51:27 +00:00
|
|
|
import { ContextMenu, ContextMenuTrigger, MenuItem } from 'react-contextmenu';
|
2020-01-17 22:23:19 +00:00
|
|
|
import { Manager, Popper, Reference } from 'react-popper';
|
2021-08-20 19:36:27 +00:00
|
|
|
import type { PreventOverflowModifier } from '@popperjs/core/lib/modifiers/preventOverflow';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
import {
|
|
|
|
ConversationType,
|
|
|
|
ConversationTypeType,
|
|
|
|
InteractionModeType,
|
|
|
|
} from '../../state/ducks/conversations';
|
2021-08-12 18:15:55 +00:00
|
|
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
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';
|
2021-07-09 20:27:16 +00:00
|
|
|
import { MessageMetadata } from './MessageMetadata';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { ImageGrid } from './ImageGrid';
|
2021-04-27 22:11:59 +00:00
|
|
|
import { GIF } from './GIF';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { Image } from './Image';
|
|
|
|
import { ContactName } from './ContactName';
|
|
|
|
import { Quote, QuotedAttachmentType } from './Quote';
|
|
|
|
import { EmbeddedContact } from './EmbeddedContact';
|
2020-01-17 22:23:19 +00:00
|
|
|
import {
|
|
|
|
OwnProps as ReactionViewerProps,
|
|
|
|
ReactionViewer,
|
|
|
|
} from './ReactionViewer';
|
2020-10-02 20:05:09 +00:00
|
|
|
import { Props as ReactionPickerProps } from './ReactionPicker';
|
2020-01-17 22:23:19 +00:00
|
|
|
import { Emoji } from '../emoji/Emoji';
|
2020-09-28 23:46:31 +00:00
|
|
|
import { LinkPreviewDate } from './LinkPreviewDate';
|
2021-01-08 19:39:32 +00:00
|
|
|
import { LinkPreviewType } from '../../types/message/LinkPreviews';
|
|
|
|
import { shouldUseFullSizeLinkPreviewImage } from '../../linkPreviews/shouldUseFullSizeLinkPreviewImage';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2018-11-14 18:47:19 +00:00
|
|
|
import {
|
2020-09-14 19:51:27 +00:00
|
|
|
AttachmentType,
|
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,
|
2021-01-29 22:58:28 +00:00
|
|
|
hasNotDownloaded,
|
2018-11-14 18:47:19 +00:00
|
|
|
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,
|
2021-04-27 22:11:59 +00:00
|
|
|
isGIF,
|
2020-09-14 19:51:27 +00:00
|
|
|
} from '../../types/Attachment';
|
2021-08-20 01:56:39 +00:00
|
|
|
import { EmbeddedContactType } from '../../types/EmbeddedContact';
|
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';
|
2021-07-27 15:42:25 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2021-02-12 01:50:11 +00:00
|
|
|
import { BodyRangesType, LocalizerType, ThemeType } from '../../types/Util';
|
2021-05-28 16:15:17 +00:00
|
|
|
import {
|
|
|
|
ContactNameColorType,
|
|
|
|
ConversationColorType,
|
|
|
|
CustomColorType,
|
|
|
|
} from '../../types/Colors';
|
2021-10-01 23:53:00 +00:00
|
|
|
import { createRefMerger } from '../../util/refMerger';
|
2021-10-06 17:37:53 +00:00
|
|
|
import { emojiToData, getEmojiCount } from '../emoji/lib';
|
|
|
|
import { isEmojiOnlyText } from '../../util/isEmojiOnlyText';
|
2021-09-10 18:00:31 +00:00
|
|
|
import type { SmartReactionPicker } from '../../state/smart/ReactionPicker';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { getCustomColorStyle } from '../../util/getCustomColorStyle';
|
2021-08-03 17:04:49 +00:00
|
|
|
import { offsetDistanceModifier } from '../../util/popperUtil';
|
2021-09-29 21:20:52 +00:00
|
|
|
import * as KeyboardLayout from '../../services/keyboardLayout';
|
2021-10-04 20:56:34 +00:00
|
|
|
import { StopPropagation } from '../StopPropagation';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type Trigger = {
|
2018-07-09 21:29:13 +00:00
|
|
|
handleContextClick: (event: React.MouseEvent<HTMLDivElement>) => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-01-09 19:26:49 +00:00
|
|
|
const STICKER_SIZE = 200;
|
2021-04-27 22:11:59 +00:00
|
|
|
const GIF_SIZE = 300;
|
2019-11-21 19:16:06 +00:00
|
|
|
const SELECTED_TIMEOUT = 1000;
|
2020-09-29 22:55:56 +00:00
|
|
|
const THREE_HOURS = 3 * 60 * 60 * 1000;
|
2019-01-16 03:03:56 +00:00
|
|
|
|
2020-08-27 18:10:35 +00:00
|
|
|
export const MessageStatuses = [
|
2020-08-27 16:57:12 +00:00
|
|
|
'delivered',
|
|
|
|
'error',
|
2021-05-06 00:09:29 +00:00
|
|
|
'paused',
|
2020-08-27 16:57:12 +00:00
|
|
|
'partial-sent',
|
|
|
|
'read',
|
|
|
|
'sending',
|
|
|
|
'sent',
|
2021-07-27 15:42:25 +00:00
|
|
|
'viewed',
|
2020-08-27 16:57:12 +00:00
|
|
|
] as const;
|
2020-08-27 18:10:35 +00:00
|
|
|
export type MessageStatusType = typeof MessageStatuses[number];
|
|
|
|
|
|
|
|
export const Directions = ['incoming', 'outgoing'] as const;
|
|
|
|
export type DirectionType = typeof Directions[number];
|
|
|
|
|
2021-03-10 20:36:58 +00:00
|
|
|
export type AudioAttachmentProps = {
|
2021-06-29 19:58:29 +00:00
|
|
|
renderingContext: string;
|
2021-03-10 20:36:58 +00:00
|
|
|
i18n: LocalizerType;
|
|
|
|
buttonRef: React.RefObject<HTMLButtonElement>;
|
|
|
|
theme: ThemeType | undefined;
|
2021-03-16 00:59:48 +00:00
|
|
|
attachment: AttachmentType;
|
2021-03-10 20:36:58 +00:00
|
|
|
withContentAbove: boolean;
|
|
|
|
withContentBelow: boolean;
|
2021-03-16 00:59:48 +00:00
|
|
|
|
2021-07-09 20:27:16 +00:00
|
|
|
direction: DirectionType;
|
|
|
|
expirationLength?: number;
|
|
|
|
expirationTimestamp?: number;
|
|
|
|
id: string;
|
2021-07-27 15:42:25 +00:00
|
|
|
played: boolean;
|
2021-07-09 20:27:16 +00:00
|
|
|
showMessageDetail: (id: string) => void;
|
|
|
|
status?: MessageStatusType;
|
|
|
|
textPending?: boolean;
|
|
|
|
timestamp: number;
|
|
|
|
|
2021-03-16 00:59:48 +00:00
|
|
|
kickOffAttachmentDownload(): void;
|
2021-03-22 18:51:53 +00:00
|
|
|
onCorrupted(): void;
|
2021-08-12 18:15:55 +00:00
|
|
|
onFirstPlayed(): void;
|
2021-03-10 20:36:58 +00:00
|
|
|
};
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
export type PropsData = {
|
2019-03-15 22:18:00 +00:00
|
|
|
id: string;
|
2021-06-29 19:58:29 +00:00
|
|
|
renderingContext: string;
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor?: ContactNameColorType;
|
|
|
|
conversationColor: ConversationColorType;
|
|
|
|
customColor?: CustomColorType;
|
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;
|
2020-02-07 19:07:22 +00:00
|
|
|
isSticker?: boolean;
|
|
|
|
isSelected?: boolean;
|
|
|
|
isSelectedCounter?: number;
|
2020-08-27 18:10:35 +00:00
|
|
|
direction: DirectionType;
|
2018-06-27 20:53:49 +00:00
|
|
|
timestamp: number;
|
2020-08-27 18:10:35 +00:00
|
|
|
status?: MessageStatusType;
|
2021-08-20 01:56:39 +00:00
|
|
|
contact?: EmbeddedContactType;
|
2021-04-27 19:55:21 +00:00
|
|
|
author: Pick<
|
|
|
|
ConversationType,
|
2021-04-30 19:40:25 +00:00
|
|
|
| 'acceptedMessageRequest'
|
2021-04-27 19:55:21 +00:00
|
|
|
| 'avatarPath'
|
|
|
|
| 'color'
|
|
|
|
| 'id'
|
2021-04-30 19:40:25 +00:00
|
|
|
| 'isMe'
|
2021-04-27 19:55:21 +00:00
|
|
|
| 'name'
|
|
|
|
| 'phoneNumber'
|
|
|
|
| 'profileName'
|
2021-04-30 19:40:25 +00:00
|
|
|
| 'sharedGroupNames'
|
2021-04-27 19:55:21 +00:00
|
|
|
| 'title'
|
2021-04-30 19:40:25 +00:00
|
|
|
| 'unblurredAvatarPath'
|
2021-04-27 19:55:21 +00:00
|
|
|
>;
|
2021-04-27 22:11:59 +00:00
|
|
|
reducedMotion?: boolean;
|
2021-06-17 17:15:10 +00:00
|
|
|
conversationType: ConversationTypeType;
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments?: Array<AttachmentType>;
|
2018-06-27 20:53:49 +00:00
|
|
|
quote?: {
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor: ConversationColorType;
|
|
|
|
customColor?: CustomColorType;
|
2018-06-27 20:53:49 +00:00
|
|
|
text: string;
|
2021-04-02 21:35:28 +00:00
|
|
|
rawAttachment?: QuotedAttachmentType;
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe: boolean;
|
2019-03-15 22:18:00 +00:00
|
|
|
sentAt: number;
|
|
|
|
authorId: string;
|
2020-07-24 01:35:32 +00:00
|
|
|
authorPhoneNumber?: string;
|
2018-06-27 20:53:49 +00:00
|
|
|
authorProfileName?: string;
|
2020-07-24 01:35:32 +00:00
|
|
|
authorTitle: string;
|
2018-07-09 21:29:13 +00:00
|
|
|
authorName?: string;
|
2020-09-16 22:42:48 +00:00
|
|
|
bodyRanges?: BodyRangesType;
|
2018-08-15 19:31:29 +00:00
|
|
|
referencedMessageNotFound: boolean;
|
2021-06-02 16:42:19 +00:00
|
|
|
isViewOnce: boolean;
|
2018-06-27 20:53:49 +00:00
|
|
|
};
|
2019-01-16 03:03:56 +00:00
|
|
|
previews: Array<LinkPreviewType>;
|
2019-06-26 19:33:13 +00:00
|
|
|
|
|
|
|
isTapToView?: boolean;
|
|
|
|
isTapToViewExpired?: boolean;
|
|
|
|
isTapToViewError?: boolean;
|
|
|
|
|
2021-08-12 18:15:55 +00:00
|
|
|
readStatus: ReadStatus;
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
expirationLength?: number;
|
|
|
|
expirationTimestamp?: number;
|
2020-01-17 22:23:19 +00:00
|
|
|
|
|
|
|
reactions?: ReactionViewerProps['reactions'];
|
2020-01-23 23:57:37 +00:00
|
|
|
selectedReaction?: string;
|
2020-02-07 23:13:46 +00:00
|
|
|
|
2020-04-29 21:24:12 +00:00
|
|
|
deletedForEveryone?: boolean;
|
|
|
|
|
2020-02-07 23:13:46 +00:00
|
|
|
canReply: boolean;
|
2020-10-16 18:31:57 +00:00
|
|
|
canDownload: boolean;
|
2020-09-29 22:55:56 +00:00
|
|
|
canDeleteForEveryone: boolean;
|
2021-02-02 17:09:53 +00:00
|
|
|
isBlocked: boolean;
|
|
|
|
isMessageRequestAccepted: boolean;
|
2020-09-16 22:42:48 +00:00
|
|
|
bodyRanges?: BodyRangesType;
|
2019-03-15 22:18:00 +00:00
|
|
|
};
|
|
|
|
|
2020-02-07 19:07:22 +00:00
|
|
|
export type PropsHousekeeping = {
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef: RefObject<HTMLElement>;
|
2019-03-15 22:18:00 +00:00
|
|
|
i18n: LocalizerType;
|
2021-03-24 22:06:12 +00:00
|
|
|
interactionMode: InteractionModeType;
|
2021-02-12 01:50:11 +00:00
|
|
|
theme?: ThemeType;
|
2019-03-15 22:18:00 +00:00
|
|
|
disableMenu?: boolean;
|
|
|
|
disableScroll?: boolean;
|
|
|
|
collapseMetadata?: boolean;
|
2021-03-24 22:06:12 +00:00
|
|
|
renderAudioAttachment: (props: AudioAttachmentProps) => JSX.Element;
|
2021-09-10 18:00:31 +00:00
|
|
|
renderReactionPicker: (
|
|
|
|
props: React.ComponentProps<typeof SmartReactionPicker>
|
|
|
|
) => JSX.Element;
|
2019-03-15 22:18:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsActions = {
|
2019-05-31 22:42:01 +00:00
|
|
|
clearSelectedMessage: () => unknown;
|
2021-06-17 17:15:10 +00:00
|
|
|
doubleCheckMissingQuoteReference: (messageId: string) => unknown;
|
|
|
|
onHeightChange: () => unknown;
|
|
|
|
checkForAccount: (identifier: string) => unknown;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
reactToMessage: (
|
|
|
|
id: string,
|
|
|
|
{ emoji, remove }: { emoji: string; remove: boolean }
|
|
|
|
) => void;
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage: (id: string) => void;
|
|
|
|
retrySend: (id: string) => void;
|
2021-04-27 22:35:35 +00:00
|
|
|
showForwardMessageModal: (id: string) => void;
|
2019-03-15 22:18:00 +00:00
|
|
|
deleteMessage: (id: string) => void;
|
2020-09-29 22:55:56 +00:00
|
|
|
deleteMessageForEveryone: (id: string) => void;
|
2019-03-15 22:18:00 +00:00
|
|
|
showMessageDetail: (id: string) => void;
|
|
|
|
|
|
|
|
openConversation: (conversationId: string, messageId?: string) => void;
|
2020-01-08 17:44:54 +00:00
|
|
|
showContactDetail: (options: {
|
2021-08-20 01:56:39 +00:00
|
|
|
contact: EmbeddedContactType;
|
2020-01-08 17:44:54 +00:00
|
|
|
signalAccount?: string;
|
|
|
|
}) => void;
|
2020-11-11 17:36:05 +00:00
|
|
|
showContactModal: (contactId: string) => void;
|
2020-01-08 17:44:54 +00:00
|
|
|
|
2021-01-29 22:58:28 +00:00
|
|
|
kickOffAttachmentDownload: (options: {
|
|
|
|
attachment: AttachmentType;
|
|
|
|
messageId: string;
|
|
|
|
}) => void;
|
2021-03-22 18:51:53 +00:00
|
|
|
markAttachmentAsCorrupted: (options: {
|
|
|
|
attachment: AttachmentType;
|
|
|
|
messageId: string;
|
|
|
|
}) => void;
|
2021-08-12 18:15:55 +00:00
|
|
|
markViewed(messageId: string): void;
|
2020-01-08 17:44:54 +00:00
|
|
|
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-12-11 18:06:04 +00:00
|
|
|
scrollToQuotedMessage: (options: {
|
|
|
|
authorId: string;
|
|
|
|
sentAt: number;
|
|
|
|
}) => void;
|
2019-11-21 19:16:06 +00:00
|
|
|
selectMessage?: (messageId: string, conversationId: string) => unknown;
|
2020-01-10 16:29:51 +00:00
|
|
|
|
|
|
|
showExpiredIncomingTapToViewToast: () => unknown;
|
|
|
|
showExpiredOutgoingTapToViewToast: () => unknown;
|
2019-03-15 22:18:00 +00:00
|
|
|
};
|
|
|
|
|
2020-05-05 19:49:34 +00:00
|
|
|
export type Props = PropsData &
|
|
|
|
PropsHousekeeping &
|
|
|
|
PropsActions &
|
|
|
|
Pick<ReactionPickerProps, 'renderEmojiPicker'>;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type State = {
|
2018-07-09 21:29:13 +00:00
|
|
|
expiring: boolean;
|
|
|
|
expired: boolean;
|
|
|
|
imageBroken: boolean;
|
2019-11-21 19:16:06 +00:00
|
|
|
|
2020-02-07 19:07:22 +00:00
|
|
|
isSelected?: boolean;
|
|
|
|
prevSelectedCounter?: number;
|
2020-01-17 22:23:19 +00:00
|
|
|
|
|
|
|
reactionViewerRoot: HTMLDivElement | null;
|
2020-01-23 23:57:37 +00:00
|
|
|
reactionPickerRoot: HTMLDivElement | null;
|
|
|
|
|
|
|
|
isWide: boolean;
|
2020-02-03 20:02:49 +00:00
|
|
|
|
2020-09-29 22:55:56 +00:00
|
|
|
canDeleteForEveryone: boolean;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
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
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
export class Message extends React.PureComponent<Props, State> {
|
2019-01-14 21:49:58 +00:00
|
|
|
public menuTriggerRef: Trigger | undefined;
|
2020-09-14 19:51:27 +00:00
|
|
|
|
2020-01-17 22:23:19 +00:00
|
|
|
public focusRef: React.RefObject<HTMLDivElement> = React.createRef();
|
2020-09-14 19:51:27 +00:00
|
|
|
|
2021-03-10 20:36:58 +00:00
|
|
|
public audioButtonRef: React.RefObject<HTMLButtonElement> = React.createRef();
|
|
|
|
|
2021-04-26 16:38:50 +00:00
|
|
|
public reactionsContainerRef: React.RefObject<HTMLDivElement> = React.createRef();
|
2020-09-14 19:51:27 +00:00
|
|
|
|
2020-03-23 21:09:12 +00:00
|
|
|
public reactionsContainerRefMerger = createRefMerger();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
public wideMl: MediaQueryList;
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public expirationCheckInterval: NodeJS.Timeout | undefined;
|
|
|
|
|
|
|
|
public expiredTimeout: NodeJS.Timeout | undefined;
|
|
|
|
|
|
|
|
public selectedTimeout: NodeJS.Timeout | undefined;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-09-29 22:55:56 +00:00
|
|
|
public deleteForEveryoneTimeout: NodeJS.Timeout | undefined;
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
this.wideMl = window.matchMedia('(min-width: 926px)');
|
|
|
|
this.wideMl.addEventListener('change', this.handleWideMlChange);
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
this.state = {
|
|
|
|
expiring: false,
|
|
|
|
expired: false,
|
|
|
|
imageBroken: false,
|
|
|
|
|
|
|
|
isSelected: props.isSelected,
|
|
|
|
prevSelectedCounter: props.isSelectedCounter,
|
2020-01-17 22:23:19 +00:00
|
|
|
|
|
|
|
reactionViewerRoot: null,
|
2020-01-23 23:57:37 +00:00
|
|
|
reactionPickerRoot: null,
|
|
|
|
|
|
|
|
isWide: this.wideMl.matches,
|
2020-02-03 20:02:49 +00:00
|
|
|
|
2020-10-08 22:26:57 +00:00
|
|
|
canDeleteForEveryone: props.canDeleteForEveryone,
|
2019-11-21 19:16:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getDerivedStateFromProps(props: Props, state: State): State {
|
2020-10-08 22:26:57 +00:00
|
|
|
const newState = {
|
|
|
|
...state,
|
|
|
|
canDeleteForEveryone:
|
|
|
|
props.canDeleteForEveryone && state.canDeleteForEveryone,
|
|
|
|
};
|
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
if (!props.isSelected) {
|
|
|
|
return {
|
2020-10-08 22:26:57 +00:00
|
|
|
...newState,
|
2019-11-21 19:16:06 +00:00
|
|
|
isSelected: false,
|
|
|
|
prevSelectedCounter: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
props.isSelected &&
|
|
|
|
props.isSelectedCounter !== state.prevSelectedCounter
|
|
|
|
) {
|
|
|
|
return {
|
2020-10-08 22:26:57 +00:00
|
|
|
...newState,
|
2019-11-21 19:16:06 +00:00
|
|
|
isSelected: props.isSelected,
|
|
|
|
prevSelectedCounter: props.isSelectedCounter,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-08 22:26:57 +00:00
|
|
|
return newState;
|
2019-11-21 19:16:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 21:15:43 +00:00
|
|
|
private hasReactions(): boolean {
|
|
|
|
const { reactions } = this.props;
|
|
|
|
return Boolean(reactions && reactions.length);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleWideMlChange = (event: MediaQueryListEvent): void => {
|
2020-01-23 23:57:37 +00:00
|
|
|
this.setState({ isWide: event.matches });
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public captureMenuTrigger = (triggerRef: Trigger): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
this.menuTriggerRef = triggerRef;
|
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public showMenu = (event: React.MouseEvent<HTMLDivElement>): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
if (this.menuTriggerRef) {
|
|
|
|
this.menuTriggerRef.handleContextClick(event);
|
|
|
|
}
|
|
|
|
};
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-06-14 18:49:12 +00:00
|
|
|
public showContextMenu = (event: React.MouseEvent<HTMLDivElement>): void => {
|
2021-06-09 22:30:05 +00:00
|
|
|
const selection = window.getSelection();
|
|
|
|
if (selection && !selection.isCollapsed) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-14 18:49:12 +00:00
|
|
|
if (event.target instanceof HTMLAnchorElement) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-09 22:30:05 +00:00
|
|
|
this.showMenu(event);
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleImageError = (): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
const { id } = this.props;
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info(
|
2019-11-07 21:36:16 +00:00
|
|
|
`Message ${id}: Image failed to load; failing over to placeholder`
|
|
|
|
);
|
|
|
|
this.setState({
|
|
|
|
imageBroken: true,
|
|
|
|
});
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleFocus = (): void => {
|
2019-11-21 19:16:06 +00:00
|
|
|
const { interactionMode } = this.props;
|
|
|
|
|
|
|
|
if (interactionMode === 'keyboard') {
|
|
|
|
this.setSelected();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public setSelected = (): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
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
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public setFocus = (): void => {
|
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
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public componentDidMount(): void {
|
2019-11-21 19:16:06 +00:00
|
|
|
this.startSelectedTimer();
|
2020-09-29 22:55:56 +00:00
|
|
|
this.startDeleteForEveryoneTimer();
|
2019-11-21 19:16:06 +00:00
|
|
|
|
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;
|
2021-06-17 17:15:10 +00:00
|
|
|
if (expirationLength) {
|
|
|
|
const increment = getIncrement(expirationLength);
|
|
|
|
const checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment);
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
this.checkExpired();
|
2018-04-03 22:56:12 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
this.expirationCheckInterval = setInterval(() => {
|
|
|
|
this.checkExpired();
|
|
|
|
}, checkFrequency);
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const { contact, checkForAccount } = this.props;
|
|
|
|
if (contact && contact.firstNumber && !contact.isNumberOnSignal) {
|
|
|
|
checkForAccount(contact.firstNumber);
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public componentWillUnmount(): void {
|
2019-05-31 22:42:01 +00:00
|
|
|
if (this.selectedTimeout) {
|
2020-12-14 19:46:55 +00:00
|
|
|
clearTimeout(this.selectedTimeout);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.expirationCheckInterval) {
|
|
|
|
clearInterval(this.expirationCheckInterval);
|
|
|
|
}
|
|
|
|
if (this.expiredTimeout) {
|
|
|
|
clearTimeout(this.expiredTimeout);
|
|
|
|
}
|
2020-09-29 22:55:56 +00:00
|
|
|
if (this.deleteForEveryoneTimeout) {
|
|
|
|
clearTimeout(this.deleteForEveryoneTimeout);
|
|
|
|
}
|
2020-01-17 22:23:19 +00:00
|
|
|
this.toggleReactionViewer(true);
|
2020-01-23 23:57:37 +00:00
|
|
|
this.toggleReactionPicker(true);
|
|
|
|
|
|
|
|
this.wideMl.removeEventListener('change', this.handleWideMlChange);
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public componentDidUpdate(prevProps: Props): void {
|
2021-07-30 18:37:03 +00:00
|
|
|
const { canDeleteForEveryone, isSelected, status, timestamp } = this.props;
|
2020-09-14 19:51:27 +00:00
|
|
|
|
2019-11-21 19:16:06 +00:00
|
|
|
this.startSelectedTimer();
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
if (!prevProps.isSelected && isSelected) {
|
2019-11-07 21:36:16 +00:00
|
|
|
this.setFocus();
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
this.checkExpired();
|
2021-06-17 17:15:10 +00:00
|
|
|
this.checkForHeightChange(prevProps);
|
2020-09-29 22:55:56 +00:00
|
|
|
|
|
|
|
if (canDeleteForEveryone !== prevProps.canDeleteForEveryone) {
|
|
|
|
this.startDeleteForEveryoneTimer();
|
|
|
|
}
|
2021-07-30 18:37:03 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
prevProps.status === 'sending' &&
|
|
|
|
(status === 'sent' ||
|
|
|
|
status === 'delivered' ||
|
|
|
|
status === 'read' ||
|
|
|
|
status === 'viewed')
|
|
|
|
) {
|
|
|
|
const delta = Date.now() - timestamp;
|
2021-08-11 19:29:07 +00:00
|
|
|
window.CI?.handleEvent('message:send-complete', {
|
|
|
|
timestamp,
|
|
|
|
delta,
|
|
|
|
});
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info(
|
2021-07-30 18:37:03 +00:00
|
|
|
`Message.tsx: Rendered 'send complete' for message ${timestamp}; took ${delta}ms`
|
|
|
|
);
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
public checkForHeightChange(prevProps: Props): void {
|
|
|
|
const { contact, onHeightChange } = this.props;
|
|
|
|
const willRenderSendMessageButton = Boolean(
|
|
|
|
contact && contact.firstNumber && contact.isNumberOnSignal
|
|
|
|
);
|
|
|
|
|
|
|
|
const { contact: previousContact } = prevProps;
|
|
|
|
const previouslyRenderedSendMessageButton = Boolean(
|
|
|
|
previousContact &&
|
|
|
|
previousContact.firstNumber &&
|
|
|
|
previousContact.isNumberOnSignal
|
|
|
|
);
|
|
|
|
|
|
|
|
if (willRenderSendMessageButton !== previouslyRenderedSendMessageButton) {
|
|
|
|
onHeightChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public startSelectedTimer(): void {
|
|
|
|
const { clearSelectedMessage, interactionMode } = this.props;
|
2019-11-21 19:16:06 +00:00
|
|
|
const { isSelected } = this.state;
|
|
|
|
|
|
|
|
if (interactionMode === 'keyboard' || !isSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.selectedTimeout) {
|
|
|
|
this.selectedTimeout = setTimeout(() => {
|
|
|
|
this.selectedTimeout = undefined;
|
|
|
|
this.setState({ isSelected: false });
|
2020-09-14 19:51:27 +00:00
|
|
|
clearSelectedMessage();
|
2019-11-21 19:16:06 +00:00
|
|
|
}, SELECTED_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:55:56 +00:00
|
|
|
public startDeleteForEveryoneTimer(): void {
|
|
|
|
if (this.deleteForEveryoneTimeout) {
|
|
|
|
clearTimeout(this.deleteForEveryoneTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { canDeleteForEveryone } = this.props;
|
|
|
|
|
|
|
|
if (!canDeleteForEveryone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { timestamp } = this.props;
|
|
|
|
const timeToDeletion = timestamp - Date.now() + THREE_HOURS;
|
|
|
|
|
|
|
|
if (timeToDeletion <= 0) {
|
|
|
|
this.setState({ canDeleteForEveryone: false });
|
|
|
|
} else {
|
|
|
|
this.deleteForEveryoneTimeout = setTimeout(() => {
|
|
|
|
this.setState({ canDeleteForEveryone: false });
|
|
|
|
}, timeToDeletion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public checkExpired(): void {
|
2018-07-09 21:29:13 +00:00
|
|
|
const now = Date.now();
|
2021-06-16 22:20:17 +00:00
|
|
|
const { 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
|
|
|
|
2021-06-16 22:20:17 +00:00
|
|
|
if (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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:09:53 +00:00
|
|
|
private areLinksEnabled(): boolean {
|
|
|
|
const { isMessageRequestAccepted, isBlocked } = this.props;
|
|
|
|
return isMessageRequestAccepted && !isBlocked;
|
|
|
|
}
|
|
|
|
|
2021-10-08 00:27:46 +00:00
|
|
|
private canRenderStickerLikeEmoji(): boolean {
|
|
|
|
const { text, quote, attachments, previews } = this.props;
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
text &&
|
|
|
|
isEmojiOnlyText(text) &&
|
|
|
|
getEmojiCount(text) < 6 &&
|
|
|
|
!quote &&
|
|
|
|
(!attachments || !attachments.length) &&
|
|
|
|
(!previews || !previews.length)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderMetadata(): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
2021-07-09 20:27:16 +00:00
|
|
|
attachments,
|
2018-06-27 20:53:49 +00:00
|
|
|
collapseMetadata,
|
2021-09-10 14:23:04 +00:00
|
|
|
deletedForEveryone,
|
2018-06-27 20:53:49 +00:00
|
|
|
direction,
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
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,
|
2021-07-09 20:27:16 +00:00
|
|
|
i18n,
|
2018-06-27 20:53:49 +00:00
|
|
|
text,
|
2019-03-13 20:38:28 +00:00
|
|
|
textPending,
|
2021-07-09 20:27:16 +00:00
|
|
|
timestamp,
|
|
|
|
id,
|
|
|
|
showMessageDetail,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (collapseMetadata) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:27:16 +00:00
|
|
|
// The message audio component renders its own metadata because it positions the
|
|
|
|
// metadata in line with some of its own.
|
|
|
|
if (isAudio(attachments) && !text) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-10-08 00:27:46 +00:00
|
|
|
const isStickerLike = isSticker || this.canRenderStickerLikeEmoji();
|
2021-10-06 17:37:53 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
return (
|
2021-07-09 20:27:16 +00:00
|
|
|
<MessageMetadata
|
2021-09-10 14:23:04 +00:00
|
|
|
deletedForEveryone={deletedForEveryone}
|
2021-07-09 20:27:16 +00:00
|
|
|
direction={direction}
|
|
|
|
expirationLength={expirationLength}
|
|
|
|
expirationTimestamp={expirationTimestamp}
|
|
|
|
hasText={Boolean(text)}
|
|
|
|
i18n={i18n}
|
|
|
|
id={id}
|
|
|
|
isShowingImage={this.isShowingImage()}
|
2021-10-06 17:37:53 +00:00
|
|
|
isSticker={isStickerLike}
|
2021-07-09 20:27:16 +00:00
|
|
|
isTapToViewExpired={isTapToViewExpired}
|
|
|
|
showMessageDetail={showMessageDetail}
|
|
|
|
status={status}
|
|
|
|
textPending={textPending}
|
|
|
|
timestamp={timestamp}
|
|
|
|
/>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAuthor(): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
2021-04-27 19:55:21 +00:00
|
|
|
author,
|
2019-05-16 22:32:11 +00:00
|
|
|
collapseMetadata,
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor,
|
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) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return null;
|
2019-05-16 22:32:11 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 01:35:32 +00:00
|
|
|
if (
|
|
|
|
direction !== 'incoming' ||
|
|
|
|
conversationType !== 'group' ||
|
2021-04-27 19:55:21 +00:00
|
|
|
!author.title
|
2020-07-24 01:35:32 +00:00
|
|
|
) {
|
2018-06-27 20:53:49 +00:00
|
|
|
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
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor={contactNameColor}
|
2021-04-27 19:55:21 +00:00
|
|
|
title={author.title}
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAttachment(): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2018-06-27 20:53:49 +00:00
|
|
|
collapseMetadata,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
2021-07-09 20:27:16 +00:00
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
2018-11-14 18:47:19 +00:00
|
|
|
i18n,
|
2019-05-16 22:32:11 +00:00
|
|
|
id,
|
2021-07-09 20:27:16 +00:00
|
|
|
isSticker,
|
2021-01-29 22:58:28 +00:00
|
|
|
kickOffAttachmentDownload,
|
2021-03-22 18:51:53 +00:00
|
|
|
markAttachmentAsCorrupted,
|
2021-08-12 18:15:55 +00:00
|
|
|
markViewed,
|
2018-06-27 20:53:49 +00:00
|
|
|
quote,
|
2021-08-12 18:15:55 +00:00
|
|
|
readStatus,
|
2021-07-09 20:27:16 +00:00
|
|
|
reducedMotion,
|
|
|
|
renderAudioAttachment,
|
|
|
|
renderingContext,
|
|
|
|
showMessageDetail,
|
2019-03-15 22:18:00 +00:00
|
|
|
showVisualAttachment,
|
2021-07-09 20:27:16 +00:00
|
|
|
status,
|
2019-05-16 22:32:11 +00:00
|
|
|
text,
|
2021-07-09 20:27:16 +00:00
|
|
|
textPending,
|
2021-02-12 01:50:11 +00:00
|
|
|
theme,
|
2021-07-09 20:27:16 +00:00
|
|
|
timestamp,
|
2018-06-27 20:53:49 +00:00
|
|
|
} = this.props;
|
2021-02-12 01:50:11 +00:00
|
|
|
|
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
|
|
|
|
2021-04-27 22:11:59 +00:00
|
|
|
if (displayImage && !imageBroken) {
|
2019-05-16 22:32:11 +00:00
|
|
|
const prefix = isSticker ? 'sticker' : 'attachment';
|
2021-04-27 22:11:59 +00:00
|
|
|
const containerClassName = classNames(
|
|
|
|
`module-message__${prefix}-container`,
|
|
|
|
withContentAbove
|
|
|
|
? `module-message__${prefix}-container--with-content-above`
|
|
|
|
: null,
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__attachment-container--with-content-below'
|
|
|
|
: null,
|
|
|
|
isSticker && !collapseMetadata
|
|
|
|
? 'module-message__sticker-container--with-content-below'
|
|
|
|
: null
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
2021-04-27 22:11:59 +00:00
|
|
|
|
|
|
|
if (isGIF(attachments)) {
|
|
|
|
return (
|
|
|
|
<div className={containerClassName}>
|
|
|
|
<GIF
|
|
|
|
attachment={firstAttachment}
|
|
|
|
size={GIF_SIZE}
|
|
|
|
theme={theme}
|
|
|
|
i18n={i18n}
|
|
|
|
tabIndex={0}
|
|
|
|
reducedMotion={reducedMotion}
|
|
|
|
onError={this.handleImageError}
|
2021-07-14 23:39:52 +00:00
|
|
|
showVisualAttachment={() => {
|
|
|
|
showVisualAttachment({
|
|
|
|
attachment: firstAttachment,
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
}}
|
2021-04-27 22:11:59 +00:00
|
|
|
kickOffAttachmentDownload={() => {
|
|
|
|
kickOffAttachmentDownload({
|
|
|
|
attachment: firstAttachment,
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isImage(attachments) || isVideo(attachments)) {
|
|
|
|
const bottomOverlay = !isSticker && !collapseMetadata;
|
|
|
|
// We only want users to tab into this if there's more than one
|
|
|
|
const tabIndex = attachments.length > 1 ? 0 : -1;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={containerClassName}>
|
|
|
|
<ImageGrid
|
|
|
|
attachments={attachments}
|
|
|
|
withContentAbove={isSticker || withContentAbove}
|
|
|
|
withContentBelow={isSticker || withContentBelow}
|
|
|
|
isSticker={isSticker}
|
|
|
|
stickerSize={STICKER_SIZE}
|
|
|
|
bottomOverlay={bottomOverlay}
|
|
|
|
i18n={i18n}
|
|
|
|
theme={theme}
|
|
|
|
onError={this.handleImageError}
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
onClick={attachment => {
|
|
|
|
if (hasNotDownloaded(attachment)) {
|
|
|
|
kickOffAttachmentDownload({ attachment, messageId: id });
|
|
|
|
} else {
|
|
|
|
showVisualAttachment({ attachment, messageId: id });
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-09-14 19:51:27 +00:00
|
|
|
}
|
2021-03-16 00:59:48 +00:00
|
|
|
if (isAudio(attachments)) {
|
2021-07-27 15:42:25 +00:00
|
|
|
let played: boolean;
|
|
|
|
switch (direction) {
|
|
|
|
case 'outgoing':
|
|
|
|
played = status === 'viewed';
|
|
|
|
break;
|
|
|
|
case 'incoming':
|
2021-08-12 18:15:55 +00:00
|
|
|
played = readStatus === ReadStatus.Viewed;
|
2021-07-27 15:42:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error(missingCaseError(direction));
|
2021-07-27 15:42:25 +00:00
|
|
|
played = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-10 20:36:58 +00:00
|
|
|
return renderAudioAttachment({
|
|
|
|
i18n,
|
|
|
|
buttonRef: this.audioButtonRef,
|
2021-06-29 19:58:29 +00:00
|
|
|
renderingContext,
|
2021-03-10 20:36:58 +00:00
|
|
|
theme,
|
2021-03-16 00:59:48 +00:00
|
|
|
attachment: firstAttachment,
|
2021-03-10 20:36:58 +00:00
|
|
|
withContentAbove,
|
|
|
|
withContentBelow,
|
2021-03-16 00:59:48 +00:00
|
|
|
|
2021-07-09 20:27:16 +00:00
|
|
|
direction,
|
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp,
|
|
|
|
id,
|
2021-07-27 15:42:25 +00:00
|
|
|
played,
|
2021-07-09 20:27:16 +00:00
|
|
|
showMessageDetail,
|
|
|
|
status,
|
|
|
|
textPending,
|
|
|
|
timestamp,
|
|
|
|
|
2021-03-16 00:59:48 +00:00
|
|
|
kickOffAttachmentDownload() {
|
|
|
|
kickOffAttachmentDownload({
|
|
|
|
attachment: firstAttachment,
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
},
|
2021-03-22 18:51:53 +00:00
|
|
|
onCorrupted() {
|
|
|
|
markAttachmentAsCorrupted({
|
|
|
|
attachment: firstAttachment,
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
},
|
2021-08-12 18:15:55 +00:00
|
|
|
onFirstPlayed() {
|
|
|
|
markViewed(id);
|
|
|
|
},
|
2021-03-10 20:36:58 +00:00
|
|
|
});
|
2020-09-14 19:51:27 +00:00
|
|
|
}
|
|
|
|
const { pending, fileName, fileSize, contentType } = firstAttachment;
|
|
|
|
const extension = getExtensionForDisplay({ contentType, fileName });
|
|
|
|
const isDangerous = isFileDangerous(fileName || '');
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-message__generic-attachment',
|
|
|
|
withContentBelow
|
|
|
|
? 'module-message__generic-attachment--with-content-below'
|
|
|
|
: null,
|
|
|
|
withContentAbove
|
|
|
|
? 'module-message__generic-attachment--with-content-above'
|
|
|
|
: null,
|
|
|
|
!firstAttachment.url
|
|
|
|
? 'module-message__generic-attachment--not-active'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
// There's only ever one of these, so we don't want users to tab into it
|
|
|
|
tabIndex={-1}
|
2021-03-19 18:47:57 +00:00
|
|
|
onClick={this.openGenericAttachment}
|
2020-09-14 19:51:27 +00:00
|
|
|
>
|
|
|
|
{pending ? (
|
|
|
|
<div className="module-message__generic-attachment__spinner-container">
|
|
|
|
<Spinner svgSize="small" size="24px" direction={direction} />
|
|
|
|
</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}
|
2018-10-04 01:12:42 +00:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2020-09-14 19:51:27 +00:00
|
|
|
{isDangerous ? (
|
|
|
|
<div className="module-message__generic-attachment__icon-dangerous-container">
|
|
|
|
<div className="module-message__generic-attachment__icon-dangerous" />
|
|
|
|
</div>
|
|
|
|
) : null}
|
2018-04-03 22:56:12 +00:00
|
|
|
</div>
|
2020-09-14 19:51:27 +00:00
|
|
|
)}
|
|
|
|
<div className="module-message__generic-attachment__text">
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__generic-attachment__file-name',
|
|
|
|
`module-message__generic-attachment__file-name--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{fileName}
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__generic-attachment__file-size',
|
|
|
|
`module-message__generic-attachment__file-size--${direction}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{fileSize}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
);
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderPreview(): JSX.Element | null {
|
2019-01-16 03:03:56 +00:00
|
|
|
const {
|
2021-03-15 22:57:02 +00:00
|
|
|
id,
|
2019-01-16 03:03:56 +00:00
|
|
|
attachments,
|
|
|
|
conversationType,
|
|
|
|
direction,
|
|
|
|
i18n,
|
2019-03-15 22:18:00 +00:00
|
|
|
openLink,
|
2019-01-16 03:03:56 +00:00
|
|
|
previews,
|
|
|
|
quote,
|
2021-02-12 01:50:11 +00:00
|
|
|
theme,
|
2021-03-15 22:57:02 +00:00
|
|
|
kickOffAttachmentDownload,
|
2019-01-16 03:03:56 +00:00
|
|
|
} = 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');
|
|
|
|
|
2021-01-08 19:39:32 +00:00
|
|
|
const previewHasImage = isImageAttachment(first.image);
|
|
|
|
const isFullSizeImage = shouldUseFullSizeLinkPreviewImage(first);
|
2019-01-16 03:03:56 +00:00
|
|
|
|
2020-09-28 23:46:31 +00:00
|
|
|
const linkPreviewDate = first.date || null;
|
2020-08-29 01:27:45 +00:00
|
|
|
|
2021-02-02 17:09:53 +00:00
|
|
|
const isClickable = this.areLinksEnabled();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2021-02-02 17:09:53 +00:00
|
|
|
const className = classNames(
|
|
|
|
'module-message__link-preview',
|
|
|
|
`module-message__link-preview--${direction}`,
|
|
|
|
{
|
|
|
|
'module-message__link-preview--with-content-above': withContentAbove,
|
|
|
|
'module-message__link-preview--nonclickable': !isClickable,
|
|
|
|
}
|
|
|
|
);
|
2021-03-15 22:57:02 +00:00
|
|
|
const onPreviewImageClick = () => {
|
|
|
|
if (first.image && hasNotDownloaded(first.image)) {
|
|
|
|
kickOffAttachmentDownload({
|
|
|
|
attachment: first.image,
|
|
|
|
messageId: id,
|
|
|
|
});
|
2021-06-04 00:42:01 +00:00
|
|
|
return;
|
2021-03-15 22:57:02 +00:00
|
|
|
}
|
2021-06-04 00:42:01 +00:00
|
|
|
openLink(first.url);
|
2021-03-15 22:57:02 +00:00
|
|
|
};
|
2021-02-02 17:09:53 +00:00
|
|
|
const contents = (
|
|
|
|
<>
|
2019-01-16 03:03:56 +00:00
|
|
|
{first.image && previewHasImage && isFullSizeImage ? (
|
|
|
|
<ImageGrid
|
|
|
|
attachments={[first.image]}
|
|
|
|
withContentAbove={withContentAbove}
|
2020-09-14 19:51:27 +00:00
|
|
|
withContentBelow
|
2019-11-07 21:36:16 +00:00
|
|
|
onError={this.handleImageError}
|
2019-01-16 03:03:56 +00:00
|
|
|
i18n={i18n}
|
2021-02-12 01:50:11 +00:00
|
|
|
theme={theme}
|
2021-03-15 22:57:02 +00:00
|
|
|
onClick={onPreviewImageClick}
|
2019-01-16 03:03:56 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2021-01-07 19:32:12 +00:00
|
|
|
<div className="module-message__link-preview__content">
|
2019-01-16 03:03:56 +00:00
|
|
|
{first.image && previewHasImage && !isFullSizeImage ? (
|
|
|
|
<div className="module-message__link-preview__icon_container">
|
|
|
|
<Image
|
|
|
|
smallCurveTopLeft={!withContentAbove}
|
2020-09-14 19:51:27 +00:00
|
|
|
noBorder
|
|
|
|
noBackground
|
|
|
|
softCorners
|
2019-01-16 03:03:56 +00:00
|
|
|
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}
|
2021-03-15 22:57:02 +00:00
|
|
|
onClick={onPreviewImageClick}
|
2019-01-16 03:03:56 +00:00
|
|
|
/>
|
|
|
|
</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>
|
2020-08-29 01:27:45 +00:00
|
|
|
{first.description && (
|
|
|
|
<div className="module-message__link-preview__description">
|
2021-07-18 23:04:34 +00:00
|
|
|
{unescape(first.description)}
|
2020-08-29 01:27:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="module-message__link-preview__footer">
|
|
|
|
<div className="module-message__link-preview__location">
|
|
|
|
{first.domain}
|
|
|
|
</div>
|
2020-09-28 23:46:31 +00:00
|
|
|
<LinkPreviewDate
|
|
|
|
date={linkPreviewDate}
|
|
|
|
className="module-message__link-preview__date"
|
|
|
|
/>
|
2019-01-16 03:03:56 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-02 17:09:53 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
return isClickable ? (
|
2021-03-15 22:57:02 +00:00
|
|
|
<div
|
|
|
|
role="link"
|
|
|
|
tabIndex={0}
|
2021-02-02 17:09:53 +00:00
|
|
|
className={className}
|
|
|
|
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();
|
|
|
|
|
|
|
|
openLink(first.url);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{contents}
|
2021-03-15 22:57:02 +00:00
|
|
|
</div>
|
2021-02-02 17:09:53 +00:00
|
|
|
) : (
|
|
|
|
<div className={className}>{contents}</div>
|
2019-01-16 03:03:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderQuote(): JSX.Element | null {
|
2018-10-18 18:57:10 +00:00
|
|
|
const {
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor,
|
|
|
|
customColor,
|
2018-10-18 18:57:10 +00:00
|
|
|
direction,
|
2019-03-15 22:18:00 +00:00
|
|
|
disableScroll,
|
2021-06-17 17:15:10 +00:00
|
|
|
doubleCheckMissingQuoteReference,
|
2018-10-18 18:57:10 +00:00
|
|
|
i18n,
|
2021-06-17 17:15:10 +00:00
|
|
|
id,
|
2018-10-18 18:57:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-06-02 16:42:19 +00:00
|
|
|
const { isViewOnce, 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({
|
2020-12-11 18:06:04 +00:00
|
|
|
authorId: quote.authorId,
|
2019-03-15 22:18:00 +00:00
|
|
|
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}
|
2021-04-02 21:35:28 +00:00
|
|
|
rawAttachment={quote.rawAttachment}
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming={direction === 'incoming'}
|
2020-07-24 01:35:32 +00:00
|
|
|
authorTitle={quote.authorTitle}
|
2020-09-16 22:42:48 +00:00
|
|
|
bodyRanges={quote.bodyRanges}
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor={conversationColor}
|
|
|
|
customColor={customColor}
|
2021-06-02 16:42:19 +00:00
|
|
|
isViewOnce={isViewOnce}
|
2019-03-15 22:18:00 +00:00
|
|
|
referencedMessageNotFound={referencedMessageNotFound}
|
2018-06-27 20:53:49 +00:00
|
|
|
isFromMe={quote.isFromMe}
|
2021-06-17 17:15:10 +00:00
|
|
|
doubleCheckMissingQuoteReference={() =>
|
|
|
|
doubleCheckMissingQuoteReference(id)
|
|
|
|
}
|
2018-06-27 20:53:49 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderEmbeddedContact(): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
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;
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const otherContent =
|
|
|
|
(contact && contact.firstNumber && contact.isNumberOnSignal) ||
|
|
|
|
withCaption;
|
2019-11-15 02:12:31 +00:00
|
|
|
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={() => {
|
2021-06-17 17:15:10 +00:00
|
|
|
showContactDetail({ contact, signalAccount: contact.firstNumber });
|
2019-03-15 22:18:00 +00:00
|
|
|
}}
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderSendMessageButton(): JSX.Element | null {
|
2019-03-15 22:18:00 +00:00
|
|
|
const { contact, openConversation, i18n } = this.props;
|
2021-06-17 17:15:10 +00:00
|
|
|
if (!contact) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const { firstNumber, isNumberOnSignal } = contact;
|
|
|
|
if (!firstNumber || !isNumberOnSignal) {
|
2018-06-27 20:53:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2020-09-14 19:51:27 +00:00
|
|
|
type="button"
|
2021-06-17 17:15:10 +00:00
|
|
|
onClick={() => openConversation(firstNumber)}
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-30 21:24:23 +00:00
|
|
|
public hasAvatar(): boolean {
|
|
|
|
const { collapseMetadata, conversationType, direction } = this.props;
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
!collapseMetadata &&
|
|
|
|
conversationType === 'group' &&
|
|
|
|
direction !== 'outgoing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAvatar(): JSX.Element | undefined {
|
2021-09-30 21:24:23 +00:00
|
|
|
const { author, i18n, showContactModal } = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-09-30 21:24:23 +00:00
|
|
|
if (!this.hasAvatar()) {
|
2020-11-11 17:36:05 +00:00
|
|
|
return undefined;
|
2018-06-27 20:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-01-27 21:15:43 +00:00
|
|
|
<div
|
|
|
|
className={classNames('module-message__author-avatar-container', {
|
|
|
|
'module-message__author-avatar-container--with-reactions': this.hasReactions(),
|
|
|
|
})}
|
2020-11-11 17:36:05 +00:00
|
|
|
>
|
2021-01-27 21:15:43 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="module-message__author-avatar"
|
2021-09-07 19:38:32 +00:00
|
|
|
onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
showContactModal(author.id);
|
|
|
|
}}
|
2021-01-27 21:15:43 +00:00
|
|
|
tabIndex={0}
|
|
|
|
>
|
|
|
|
<Avatar
|
2021-04-30 19:40:25 +00:00
|
|
|
acceptedMessageRequest={author.acceptedMessageRequest}
|
2021-04-27 19:55:21 +00:00
|
|
|
avatarPath={author.avatarPath}
|
|
|
|
color={author.color}
|
2021-01-27 21:15:43 +00:00
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
2021-04-30 19:40:25 +00:00
|
|
|
isMe={author.isMe}
|
2021-04-27 19:55:21 +00:00
|
|
|
name={author.name}
|
|
|
|
phoneNumber={author.phoneNumber}
|
|
|
|
profileName={author.profileName}
|
2021-04-30 19:40:25 +00:00
|
|
|
sharedGroupNames={author.sharedGroupNames}
|
2021-01-27 21:15:43 +00:00
|
|
|
size={28}
|
2021-04-30 19:40:25 +00:00
|
|
|
title={author.title}
|
|
|
|
unblurredAvatarPath={author.unblurredAvatarPath}
|
2021-01-27 21:15:43 +00:00
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderText(): JSX.Element | null {
|
2020-04-29 21:24:12 +00:00
|
|
|
const {
|
2020-09-16 22:42:48 +00:00
|
|
|
bodyRanges,
|
2020-04-29 21:24:12 +00:00
|
|
|
deletedForEveryone,
|
|
|
|
direction,
|
|
|
|
i18n,
|
2020-09-16 22:42:48 +00:00
|
|
|
openConversation,
|
2020-04-29 21:24:12 +00:00
|
|
|
status,
|
|
|
|
text,
|
|
|
|
textPending,
|
|
|
|
} = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2020-04-29 21:24:12 +00:00
|
|
|
const contents = deletedForEveryone
|
|
|
|
? i18n('message--deletedForEveryone')
|
|
|
|
: 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
|
2020-09-16 22:42:48 +00:00
|
|
|
bodyRanges={bodyRanges}
|
2021-02-02 17:09:53 +00:00
|
|
|
disableLinks={!this.areLinksEnabled()}
|
2020-09-16 22:42:48 +00:00
|
|
|
direction={direction}
|
2019-03-13 20:38:28 +00:00
|
|
|
i18n={i18n}
|
2020-09-16 22:42:48 +00:00
|
|
|
openConversation={openConversation}
|
|
|
|
text={contents || ''}
|
2019-03-13 20:38:28 +00:00
|
|
|
textPending={textPending}
|
|
|
|
/>
|
2018-06-27 20:53:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderError(isCorrectSide: boolean): JSX.Element | null {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { status, direction } = this.props;
|
|
|
|
|
2021-05-06 00:09:29 +00:00
|
|
|
if (!isCorrectSide) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
status !== 'paused' &&
|
|
|
|
status !== 'error' &&
|
|
|
|
status !== 'partial-sent'
|
|
|
|
) {
|
2018-07-09 21:29:13 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-message__error-container">
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__error',
|
2021-05-06 00:09:29 +00:00
|
|
|
`module-message__error--${direction}`,
|
|
|
|
`module-message__error--${status}`
|
2018-07-09 21:29:13 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderMenu(
|
|
|
|
isCorrectSide: boolean,
|
|
|
|
triggerId: string
|
|
|
|
): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
const {
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2020-10-16 18:31:57 +00:00
|
|
|
canDownload,
|
2020-02-07 23:13:46 +00:00
|
|
|
canReply,
|
2018-07-09 21:29:13 +00:00
|
|
|
direction,
|
|
|
|
disableMenu,
|
2020-05-05 19:49:34 +00:00
|
|
|
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,
|
2020-09-14 19:51:27 +00:00
|
|
|
reactToMessage,
|
2020-05-05 19:49:34 +00:00
|
|
|
renderEmojiPicker,
|
2021-09-10 18:00:31 +00:00
|
|
|
renderReactionPicker,
|
2019-03-15 22:18:00 +00:00
|
|
|
replyToMessage,
|
2020-09-14 19:51:27 +00:00
|
|
|
selectedReaction,
|
2018-07-09 21:29:13 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!isCorrectSide || disableMenu) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
const { reactionPickerRoot, isWide } = this.state;
|
2020-01-17 22:23:19 +00:00
|
|
|
|
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 ? (
|
2020-09-14 19:51:27 +00:00
|
|
|
// This a menu meant for mouse use only
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus, jsx-a11y/click-events-have-key-events
|
2018-11-14 18:47:19 +00:00
|
|
|
<div
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={this.openGenericAttachment}
|
2018-11-14 18:47:19 +00:00
|
|
|
role="button"
|
2020-09-14 19:51:27 +00:00
|
|
|
aria-label={i18n('downloadAttachment')}
|
2018-11-14 18:47:19 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__download',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
const reactButton = (
|
|
|
|
<Reference>
|
|
|
|
{({ ref: popperRef }) => {
|
|
|
|
// Only attach the popper reference to the reaction button if it is
|
|
|
|
// visible in the page (it is hidden when the page is narrow)
|
|
|
|
const maybePopperRef = isWide ? popperRef : undefined;
|
|
|
|
|
|
|
|
return (
|
2020-09-14 19:51:27 +00:00
|
|
|
// This a menu meant for mouse use only
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus, jsx-a11y/click-events-have-key-events
|
2020-01-23 23:57:37 +00:00
|
|
|
<div
|
|
|
|
ref={maybePopperRef}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.toggleReactionPicker();
|
|
|
|
}}
|
|
|
|
role="button"
|
|
|
|
className="module-message__buttons__react"
|
2020-09-14 19:51:27 +00:00
|
|
|
aria-label={i18n('reactToMessage')}
|
2020-01-23 23:57:37 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Reference>
|
|
|
|
);
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const replyButton = (
|
2020-09-14 19:51:27 +00:00
|
|
|
// This a menu meant for mouse use only
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
// eslint-disable-next-line jsx-a11y/interactive-supports-focus, jsx-a11y/click-events-have-key-events
|
2018-07-09 21:29:13 +00:00
|
|
|
<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"
|
2020-09-14 19:51:27 +00:00
|
|
|
aria-label={i18n('replyToMessage')}
|
2018-07-09 21:29:13 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__reply',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
// This a menu meant for mouse use only
|
|
|
|
/* eslint-disable jsx-a11y/interactive-supports-focus */
|
|
|
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
2018-07-09 21:29:13 +00:00
|
|
|
const menuButton = (
|
2020-01-23 23:57:37 +00:00
|
|
|
<Reference>
|
|
|
|
{({ ref: popperRef }) => {
|
|
|
|
// Only attach the popper reference to the collapsed menu button if
|
|
|
|
// the reaction button is not visible in the page (it is hidden when
|
|
|
|
// the page is narrow)
|
|
|
|
const maybePopperRef = !isWide ? popperRef : undefined;
|
|
|
|
|
|
|
|
return (
|
2021-10-05 13:58:34 +00:00
|
|
|
<StopPropagation className="module-message__buttons__menu--container">
|
|
|
|
<ContextMenuTrigger
|
|
|
|
id={triggerId}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
ref={this.captureMenuTrigger as any}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
ref={maybePopperRef}
|
|
|
|
role="button"
|
|
|
|
onClick={this.showMenu}
|
|
|
|
aria-label={i18n('messageContextMenuButton')}
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons__menu',
|
|
|
|
`module-message__buttons__download--${direction}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</ContextMenuTrigger>
|
|
|
|
</StopPropagation>
|
2020-01-23 23:57:37 +00:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Reference>
|
2018-07-09 21:29:13 +00:00
|
|
|
);
|
2020-09-14 19:51:27 +00:00
|
|
|
/* eslint-enable jsx-a11y/interactive-supports-focus */
|
|
|
|
/* eslint-enable jsx-a11y/click-events-have-key-events */
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
return (
|
2020-01-23 23:57:37 +00:00
|
|
|
<Manager>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-message__buttons',
|
2020-02-03 20:02:49 +00:00
|
|
|
`module-message__buttons--${direction}`
|
2020-01-23 23:57:37 +00:00
|
|
|
)}
|
|
|
|
>
|
2020-02-07 23:13:46 +00:00
|
|
|
{canReply ? reactButton : null}
|
2020-10-16 18:31:57 +00:00
|
|
|
{canDownload ? downloadButton : null}
|
2020-02-07 23:13:46 +00:00
|
|
|
{canReply ? replyButton : null}
|
2020-01-23 23:57:37 +00:00
|
|
|
{menuButton}
|
|
|
|
</div>
|
|
|
|
{reactionPickerRoot &&
|
|
|
|
createPortal(
|
2021-10-04 20:56:34 +00:00
|
|
|
<StopPropagation>
|
|
|
|
<Popper
|
|
|
|
placement="top"
|
|
|
|
modifiers={[
|
|
|
|
offsetDistanceModifier(4),
|
|
|
|
this.popperPreventOverflowModifier(),
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
{({ ref, style }) =>
|
|
|
|
renderReactionPicker({
|
|
|
|
ref,
|
|
|
|
style,
|
|
|
|
selected: selectedReaction,
|
|
|
|
onClose: this.toggleReactionPicker,
|
|
|
|
onPick: emoji => {
|
|
|
|
this.toggleReactionPicker(true);
|
|
|
|
reactToMessage(id, {
|
|
|
|
emoji,
|
|
|
|
remove: emoji === selectedReaction,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
renderEmojiPicker,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</Popper>
|
|
|
|
</StopPropagation>,
|
2020-01-23 23:57:37 +00:00
|
|
|
reactionPickerRoot
|
|
|
|
)}
|
|
|
|
</Manager>
|
2018-07-09 21:29:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderContextMenu(triggerId: string): JSX.Element {
|
2018-07-09 21:29:13 +00:00
|
|
|
const {
|
2018-11-14 18:47:19 +00:00
|
|
|
attachments,
|
2020-10-16 18:31:57 +00:00
|
|
|
canDownload,
|
2020-02-07 23:13:46 +00:00
|
|
|
canReply,
|
2019-06-26 19:33:13 +00:00
|
|
|
deleteMessage,
|
2020-09-29 22:55:56 +00:00
|
|
|
deleteMessageForEveryone,
|
2021-04-27 22:35:35 +00:00
|
|
|
deletedForEveryone,
|
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,
|
2021-04-27 22:35:35 +00:00
|
|
|
showForwardMessageModal,
|
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;
|
|
|
|
|
2021-04-27 22:35:35 +00:00
|
|
|
const canForward = !isTapToView && !deletedForEveryone;
|
|
|
|
|
2020-09-29 22:55:56 +00:00
|
|
|
const { canDeleteForEveryone } = this.state;
|
|
|
|
|
2020-10-21 18:26:35 +00:00
|
|
|
const showRetry =
|
2021-05-06 00:09:29 +00:00
|
|
|
(status === 'paused' ||
|
|
|
|
status === 'error' ||
|
|
|
|
status === 'partial-sent') &&
|
2020-10-21 18:26:35 +00:00
|
|
|
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}>
|
2020-10-16 18:31:57 +00:00
|
|
|
{canDownload &&
|
|
|
|
!isSticker &&
|
2019-06-26 19:33:13 +00:00
|
|
|
!multipleAttachments &&
|
|
|
|
!isTapToView &&
|
|
|
|
attachments &&
|
|
|
|
attachments[0] ? (
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__download',
|
2018-08-11 00:15:00 +00:00
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={this.openGenericAttachment}
|
2018-08-11 00:15:00 +00:00
|
|
|
>
|
|
|
|
{i18n('downloadAttachment')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
2020-02-07 23:13:46 +00:00
|
|
|
{canReply ? (
|
|
|
|
<>
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__reply',
|
2020-02-07 23:13:46 +00:00
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2020-01-23 23:57:37 +00:00
|
|
|
|
2020-10-21 18:26:35 +00:00
|
|
|
replyToMessage(id);
|
2020-02-07 23:13:46 +00:00
|
|
|
}}
|
|
|
|
>
|
2020-10-21 18:26:35 +00:00
|
|
|
{i18n('replyToMessage')}
|
2020-02-07 23:13:46 +00:00
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__react',
|
2020-02-07 23:13:46 +00:00
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2020-10-21 18:26:35 +00:00
|
|
|
this.toggleReactionPicker();
|
2020-02-07 23:13:46 +00:00
|
|
|
}}
|
|
|
|
>
|
2020-10-21 18:26:35 +00:00
|
|
|
{i18n('reactToMessage')}
|
2020-02-07 23:13:46 +00:00
|
|
|
</MenuItem>
|
|
|
|
</>
|
|
|
|
) : null}
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__more-info',
|
2018-08-11 00:15:00 +00:00
|
|
|
}}
|
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={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__retry-send',
|
2018-08-11 00:15:00 +00:00
|
|
|
}}
|
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}
|
2021-04-27 22:35:35 +00:00
|
|
|
{canForward ? (
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__forward-message',
|
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
showForwardMessageModal(id);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{i18n('forwardMessage')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
2018-08-11 00:15:00 +00:00
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__delete-message',
|
2018-08-11 00:15:00 +00:00
|
|
|
}}
|
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>
|
2020-09-29 22:55:56 +00:00
|
|
|
{canDeleteForEveryone ? (
|
|
|
|
<MenuItem
|
|
|
|
attributes={{
|
2020-10-21 18:26:35 +00:00
|
|
|
className:
|
|
|
|
'module-message__context--icon module-message__context__delete-message-for-everyone',
|
2020-09-29 22:55:56 +00:00
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
deleteMessageForEveryone(id);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{i18n('deleteMessageForEveryone')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
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) {
|
2021-04-27 22:11:59 +00:00
|
|
|
if (isGIF(attachments)) {
|
2021-06-24 21:00:11 +00:00
|
|
|
// Message container border
|
|
|
|
return GIF_SIZE + 2;
|
2021-04-27 22:11:59 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 19:39:32 +00:00
|
|
|
const firstLinkPreview = (previews || [])[0];
|
|
|
|
if (
|
|
|
|
firstLinkPreview &&
|
|
|
|
firstLinkPreview.image &&
|
|
|
|
shouldUseFullSizeLinkPreviewImage(firstLinkPreview)
|
|
|
|
) {
|
|
|
|
const dimensions = getImageDimensions(firstLinkPreview.image);
|
|
|
|
if (dimensions) {
|
|
|
|
// Add two for 1px border
|
|
|
|
return dimensions.width + 2;
|
2019-01-16 03:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
return undefined;
|
2019-01-16 03:03:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 20:27:16 +00:00
|
|
|
public isShowingImage(): boolean {
|
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);
|
|
|
|
|
2021-02-12 01:50:11 +00:00
|
|
|
return displayImage && (isImage(attachments) || isVideo(attachments));
|
2019-01-16 03:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (previews && previews.length) {
|
|
|
|
const first = previews[0];
|
|
|
|
const { image } = first;
|
|
|
|
|
|
|
|
return isImageAttachment(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public isAttachmentPending(): boolean {
|
2019-06-26 19:33:13 +00:00
|
|
|
const { attachments } = this.props;
|
|
|
|
|
|
|
|
if (!attachments || attachments.length < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const first = attachments[0];
|
|
|
|
|
|
|
|
return Boolean(first.pending);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderTapToViewIcon(): JSX.Element {
|
2019-06-26 19:33:13 +00:00
|
|
|
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
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderTapToViewText(): string | undefined {
|
2019-06-26 19:33:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-09-16 20:25:55 +00:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2019-06-26 19:33:13 +00:00
|
|
|
return isTapToViewError
|
|
|
|
? i18n('incomingError')
|
|
|
|
: direction === 'outgoing'
|
2020-01-08 17:44:54 +00:00
|
|
|
? outgoingString
|
|
|
|
: incomingString;
|
2019-06-26 19:33:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderTapToView(): JSX.Element {
|
2019-06-26 19:33:13 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-20 19:36:27 +00:00
|
|
|
private popperPreventOverflowModifier(): Partial<PreventOverflowModifier> {
|
|
|
|
const { containerElementRef } = this.props;
|
|
|
|
return {
|
|
|
|
name: 'preventOverflow',
|
|
|
|
options: {
|
|
|
|
altAxis: true,
|
|
|
|
boundary: containerElementRef.current || undefined,
|
|
|
|
padding: {
|
|
|
|
bottom: 16,
|
|
|
|
left: 8,
|
|
|
|
right: 8,
|
|
|
|
top: 16,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public toggleReactionViewer = (onlyRemove = false): void => {
|
2020-01-17 22:23:19 +00:00
|
|
|
this.setState(({ reactionViewerRoot }) => {
|
|
|
|
if (reactionViewerRoot) {
|
|
|
|
document.body.removeChild(reactionViewerRoot);
|
|
|
|
document.body.removeEventListener(
|
|
|
|
'click',
|
2020-01-23 23:57:37 +00:00
|
|
|
this.handleClickOutsideReactionViewer,
|
2020-01-17 22:23:19 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2020-03-03 22:33:54 +00:00
|
|
|
return { reactionViewerRoot: null };
|
2020-01-17 22:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!onlyRemove) {
|
|
|
|
const root = document.createElement('div');
|
|
|
|
document.body.appendChild(root);
|
2020-01-23 23:57:37 +00:00
|
|
|
document.body.addEventListener(
|
|
|
|
'click',
|
|
|
|
this.handleClickOutsideReactionViewer,
|
|
|
|
true
|
|
|
|
);
|
2020-01-17 22:23:19 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
reactionViewerRoot: root,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:33:54 +00:00
|
|
|
return { reactionViewerRoot: null };
|
2020-01-17 22:23:19 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public toggleReactionPicker = (onlyRemove = false): void => {
|
2020-01-23 23:57:37 +00:00
|
|
|
this.setState(({ reactionPickerRoot }) => {
|
|
|
|
if (reactionPickerRoot) {
|
|
|
|
document.body.removeChild(reactionPickerRoot);
|
|
|
|
document.body.removeEventListener(
|
|
|
|
'click',
|
|
|
|
this.handleClickOutsideReactionPicker,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
return { reactionPickerRoot: null };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!onlyRemove) {
|
|
|
|
const root = document.createElement('div');
|
|
|
|
document.body.appendChild(root);
|
|
|
|
document.body.addEventListener(
|
|
|
|
'click',
|
|
|
|
this.handleClickOutsideReactionPicker,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
reactionPickerRoot: root,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return { reactionPickerRoot: null };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleClickOutsideReactionViewer = (e: MouseEvent): void => {
|
2020-01-17 22:23:19 +00:00
|
|
|
const { reactionViewerRoot } = this.state;
|
|
|
|
const { current: reactionsContainer } = this.reactionsContainerRef;
|
|
|
|
if (reactionViewerRoot && reactionsContainer) {
|
|
|
|
if (
|
|
|
|
!reactionViewerRoot.contains(e.target as HTMLElement) &&
|
|
|
|
!reactionsContainer.contains(e.target as HTMLElement)
|
|
|
|
) {
|
|
|
|
this.toggleReactionViewer(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleClickOutsideReactionPicker = (e: MouseEvent): void => {
|
2020-01-23 23:57:37 +00:00
|
|
|
const { reactionPickerRoot } = this.state;
|
|
|
|
if (reactionPickerRoot) {
|
|
|
|
if (!reactionPickerRoot.contains(e.target as HTMLElement)) {
|
|
|
|
this.toggleReactionPicker(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderReactions(outgoing: boolean): JSX.Element | null {
|
2021-01-27 21:15:43 +00:00
|
|
|
const { reactions = [], i18n } = this.props;
|
2020-01-17 22:23:19 +00:00
|
|
|
|
2021-01-27 21:15:43 +00:00
|
|
|
if (!this.hasReactions()) {
|
2020-01-17 22:23:19 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-02 20:05:09 +00:00
|
|
|
const reactionsWithEmojiData = reactions.map(reaction => ({
|
|
|
|
...reaction,
|
|
|
|
...emojiToData(reaction.emoji),
|
|
|
|
}));
|
|
|
|
|
2020-01-17 22:23:19 +00:00
|
|
|
// Group by emoji and order each group by timestamp descending
|
2020-10-02 20:05:09 +00:00
|
|
|
const groupedAndSortedReactions = Object.values(
|
|
|
|
groupBy(reactionsWithEmojiData, 'short_name')
|
|
|
|
).map(groupedReactions =>
|
|
|
|
orderBy(
|
|
|
|
groupedReactions,
|
|
|
|
[reaction => reaction.from.isMe, 'timestamp'],
|
|
|
|
['desc', 'desc']
|
|
|
|
)
|
2020-01-17 22:23:19 +00:00
|
|
|
);
|
|
|
|
// Order groups by length and subsequently by most recent reaction
|
|
|
|
const ordered = orderBy(
|
2020-10-02 20:05:09 +00:00
|
|
|
groupedAndSortedReactions,
|
2020-01-17 22:23:19 +00:00
|
|
|
['length', ([{ timestamp }]) => timestamp],
|
|
|
|
['desc', 'desc']
|
|
|
|
);
|
2020-02-03 20:02:49 +00:00
|
|
|
// Take the first three groups for rendering
|
|
|
|
const toRender = take(ordered, 3).map(res => ({
|
2020-01-17 22:23:19 +00:00
|
|
|
emoji: res[0].emoji,
|
2020-02-03 20:02:49 +00:00
|
|
|
count: res.length,
|
2020-01-17 22:23:19 +00:00
|
|
|
isMe: res.some(re => Boolean(re.from.isMe)),
|
|
|
|
}));
|
2020-02-03 20:02:49 +00:00
|
|
|
const someNotRendered = ordered.length > 3;
|
|
|
|
// We only drop two here because the third emoji would be replaced by the
|
|
|
|
// more button
|
|
|
|
const maybeNotRendered = drop(ordered, 2);
|
|
|
|
const maybeNotRenderedTotal = maybeNotRendered.reduce(
|
|
|
|
(sum, res) => sum + res.length,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
const notRenderedIsMe =
|
|
|
|
someNotRendered &&
|
|
|
|
maybeNotRendered.some(res => res.some(re => Boolean(re.from.isMe)));
|
|
|
|
|
2021-01-27 21:15:43 +00:00
|
|
|
const { reactionViewerRoot } = this.state;
|
2020-01-17 22:23:19 +00:00
|
|
|
|
|
|
|
const popperPlacement = outgoing ? 'bottom-end' : 'bottom-start';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Manager>
|
|
|
|
<Reference>
|
|
|
|
{({ ref: popperRef }) => (
|
2020-02-03 20:02:49 +00:00
|
|
|
<div
|
2020-03-23 21:09:12 +00:00
|
|
|
ref={this.reactionsContainerRefMerger(
|
|
|
|
this.reactionsContainerRef,
|
|
|
|
popperRef
|
|
|
|
)}
|
2020-02-03 20:02:49 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-message__reactions',
|
|
|
|
outgoing
|
|
|
|
? 'module-message__reactions--outgoing'
|
|
|
|
: 'module-message__reactions--incoming'
|
|
|
|
)}
|
2020-01-17 22:23:19 +00:00
|
|
|
>
|
2020-02-03 20:02:49 +00:00
|
|
|
{toRender.map((re, i) => {
|
|
|
|
const isLast = i === toRender.length - 1;
|
|
|
|
const isMore = isLast && someNotRendered;
|
|
|
|
const isMoreWithMe = isMore && notRenderedIsMe;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
2020-09-14 19:51:27 +00:00
|
|
|
type="button"
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
2020-02-03 20:02:49 +00:00
|
|
|
key={`${re.emoji}-${i}`}
|
|
|
|
className={classNames(
|
|
|
|
'module-message__reactions__reaction',
|
|
|
|
re.count > 1
|
|
|
|
? 'module-message__reactions__reaction--with-count'
|
|
|
|
: null,
|
|
|
|
outgoing
|
|
|
|
? 'module-message__reactions__reaction--outgoing'
|
|
|
|
: 'module-message__reactions__reaction--incoming',
|
|
|
|
isMoreWithMe || (re.isMe && !isMoreWithMe)
|
|
|
|
? 'module-message__reactions__reaction--is-me'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
onClick={e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2020-03-03 22:33:54 +00:00
|
|
|
this.toggleReactionViewer(false);
|
2020-02-03 20:02:49 +00:00
|
|
|
}}
|
|
|
|
onKeyDown={e => {
|
|
|
|
// Prevent enter key from opening stickers/attachments
|
|
|
|
if (e.key === 'Enter') {
|
2020-01-17 22:23:19 +00:00
|
|
|
e.stopPropagation();
|
2020-02-03 20:02:49 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{isMore ? (
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
'module-message__reactions__reaction__count',
|
|
|
|
'module-message__reactions__reaction__count--no-emoji',
|
|
|
|
isMoreWithMe
|
|
|
|
? 'module-message__reactions__reaction__count--is-me'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
+{maybeNotRenderedTotal}
|
|
|
|
</span>
|
|
|
|
) : (
|
2020-09-14 19:51:27 +00:00
|
|
|
<>
|
2020-02-03 20:02:49 +00:00
|
|
|
<Emoji size={16} emoji={re.emoji} />
|
|
|
|
{re.count > 1 ? (
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
'module-message__reactions__reaction__count',
|
|
|
|
re.isMe
|
|
|
|
? 'module-message__reactions__reaction__count--is-me'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{re.count}
|
|
|
|
</span>
|
|
|
|
) : null}
|
2020-09-14 19:51:27 +00:00
|
|
|
</>
|
2020-02-03 20:02:49 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
2020-01-17 22:23:19 +00:00
|
|
|
)}
|
|
|
|
</Reference>
|
|
|
|
{reactionViewerRoot &&
|
|
|
|
createPortal(
|
2021-10-04 20:56:34 +00:00
|
|
|
<StopPropagation>
|
|
|
|
<Popper
|
|
|
|
placement={popperPlacement}
|
|
|
|
strategy="fixed"
|
|
|
|
modifiers={[this.popperPreventOverflowModifier()]}
|
|
|
|
>
|
|
|
|
{({ ref, style }) => (
|
|
|
|
<ReactionViewer
|
|
|
|
ref={ref}
|
|
|
|
style={{
|
|
|
|
...style,
|
|
|
|
zIndex: 2,
|
|
|
|
}}
|
|
|
|
reactions={reactions}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={this.toggleReactionViewer}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Popper>
|
|
|
|
</StopPropagation>,
|
2020-01-17 22:23:19 +00:00
|
|
|
reactionViewerRoot
|
|
|
|
)}
|
|
|
|
</Manager>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderContents(): JSX.Element | null {
|
2020-04-29 21:24:12 +00:00
|
|
|
const { isTapToView, deletedForEveryone } = this.props;
|
|
|
|
|
|
|
|
if (deletedForEveryone) {
|
2021-09-10 14:23:04 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.renderText()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
</>
|
|
|
|
);
|
2020-04-29 21:24:12 +00:00
|
|
|
}
|
2019-06-26 19:33:13 +00:00
|
|
|
|
|
|
|
if (isTapToView) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.renderTapToView()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.renderQuote()}
|
|
|
|
{this.renderAttachment()}
|
|
|
|
{this.renderPreview()}
|
|
|
|
{this.renderEmbeddedContact()}
|
|
|
|
{this.renderText()}
|
|
|
|
{this.renderMetadata()}
|
|
|
|
{this.renderSendMessageButton()}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
public handleOpen = (
|
|
|
|
event: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent
|
2020-09-14 19:51:27 +00:00
|
|
|
): void => {
|
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,
|
2020-01-10 16:29:51 +00:00
|
|
|
direction,
|
2018-06-27 20:53:49 +00:00
|
|
|
id,
|
2019-11-07 21:36:16 +00:00
|
|
|
isTapToView,
|
|
|
|
isTapToViewExpired,
|
2021-01-29 22:58:28 +00:00
|
|
|
kickOffAttachmentDownload,
|
2019-11-15 02:12:31 +00:00
|
|
|
openConversation,
|
|
|
|
showContactDetail,
|
2019-11-07 21:36:16 +00:00
|
|
|
showVisualAttachment,
|
2020-01-10 16:29:51 +00:00
|
|
|
showExpiredIncomingTapToViewToast,
|
|
|
|
showExpiredOutgoingTapToViewToast,
|
2019-11-07 21:36:16 +00:00
|
|
|
} = this.props;
|
|
|
|
const { imageBroken } = this.state;
|
|
|
|
|
|
|
|
const isAttachmentPending = this.isAttachmentPending();
|
|
|
|
|
|
|
|
if (isTapToView) {
|
2020-01-10 16:29:51 +00:00
|
|
|
if (isAttachmentPending) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info(
|
2021-08-12 16:20:22 +00:00
|
|
|
'<Message> handleOpen: tap-to-view attachment is pending; not showing the lightbox'
|
|
|
|
);
|
2020-01-10 16:29:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:48:07 +00:00
|
|
|
if (attachments && hasNotDownloaded(attachments[0])) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
kickOffAttachmentDownload({
|
|
|
|
attachment: attachments[0],
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-10 16:29:51 +00:00
|
|
|
if (isTapToViewExpired) {
|
|
|
|
const action =
|
|
|
|
direction === 'outgoing'
|
|
|
|
? showExpiredOutgoingTapToViewToast
|
|
|
|
: showExpiredIncomingTapToViewToast;
|
|
|
|
action();
|
|
|
|
} else {
|
2019-11-07 21:36:16 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
displayTapToViewMessage(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:58:28 +00:00
|
|
|
if (
|
|
|
|
!imageBroken &&
|
|
|
|
attachments &&
|
|
|
|
attachments.length > 0 &&
|
|
|
|
!isAttachmentPending &&
|
|
|
|
(isImage(attachments) || isVideo(attachments)) &&
|
|
|
|
hasNotDownloaded(attachments[0])
|
|
|
|
) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const attachment = attachments[0];
|
|
|
|
|
|
|
|
kickOffAttachmentDownload({ attachment, messageId: id });
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
if (
|
|
|
|
!imageBroken &&
|
|
|
|
attachments &&
|
|
|
|
attachments.length > 0 &&
|
|
|
|
!isAttachmentPending &&
|
|
|
|
canDisplayImage(attachments) &&
|
|
|
|
((isImage(attachments) && hasImage(attachments)) ||
|
2021-02-12 01:50:11 +00:00
|
|
|
(isVideo(attachments) && hasVideoScreenshot(attachments)))
|
2019-11-07 21:36:16 +00:00
|
|
|
) {
|
|
|
|
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) &&
|
2021-03-10 20:36:58 +00:00
|
|
|
this.audioButtonRef &&
|
|
|
|
this.audioButtonRef.current
|
2019-11-07 21:36:16 +00:00
|
|
|
) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2021-03-10 20:36:58 +00:00
|
|
|
this.audioButtonRef.current.click();
|
2019-11-07 21:36:16 +00:00
|
|
|
}
|
2019-11-15 02:12:31 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
if (contact && contact.firstNumber && contact.isNumberOnSignal) {
|
|
|
|
openConversation(contact.firstNumber);
|
2019-11-15 02:12:31 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact) {
|
2021-06-17 17:15:10 +00:00
|
|
|
showContactDetail({ contact, signalAccount: contact.firstNumber });
|
2019-11-15 02:12:31 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public openGenericAttachment = (event?: React.MouseEvent): void => {
|
2021-03-19 18:47:57 +00:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
attachments,
|
|
|
|
downloadAttachment,
|
|
|
|
timestamp,
|
|
|
|
kickOffAttachmentDownload,
|
|
|
|
} = this.props;
|
2019-11-07 21:36:16 +00:00
|
|
|
|
|
|
|
if (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!attachments || attachments.length !== 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const attachment = attachments[0];
|
2021-03-19 18:47:57 +00:00
|
|
|
if (hasNotDownloaded(attachment)) {
|
|
|
|
kickOffAttachmentDownload({
|
|
|
|
attachment,
|
|
|
|
messageId: id,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
const { fileName } = attachment;
|
|
|
|
const isDangerous = isFileDangerous(fileName || '');
|
|
|
|
|
|
|
|
downloadAttachment({
|
|
|
|
isDangerous,
|
|
|
|
attachment,
|
|
|
|
timestamp,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {
|
2020-02-07 23:13:46 +00:00
|
|
|
// Do not allow reactions to error messages
|
|
|
|
const { canReply } = this.props;
|
|
|
|
|
2021-09-29 21:20:52 +00:00
|
|
|
const key = KeyboardLayout.lookup(event.nativeEvent);
|
|
|
|
|
2020-01-23 23:57:37 +00:00
|
|
|
if (
|
2021-09-29 21:20:52 +00:00
|
|
|
(key === 'E' || key === 'e') &&
|
2020-01-23 23:57:37 +00:00
|
|
|
(event.metaKey || event.ctrlKey) &&
|
2020-02-07 23:13:46 +00:00
|
|
|
event.shiftKey &&
|
|
|
|
canReply
|
2020-01-23 23:57:37 +00:00
|
|
|
) {
|
|
|
|
this.toggleReactionPicker();
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
if (event.key !== 'Enter' && event.key !== 'Space') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.handleOpen(event);
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public handleClick = (event: React.MouseEvent): void => {
|
2019-11-07 21:36:16 +00:00
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderContainer(): JSX.Element {
|
2019-11-07 21:36:16 +00:00
|
|
|
const {
|
2021-04-27 22:11:59 +00:00
|
|
|
attachments,
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor,
|
|
|
|
customColor,
|
2020-04-29 21:24:12 +00:00
|
|
|
deletedForEveryone,
|
2019-11-07 21:36:16 +00:00
|
|
|
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();
|
|
|
|
|
2021-10-08 00:27:46 +00:00
|
|
|
const isEmojiOnly = this.canRenderStickerLikeEmoji();
|
2021-10-06 17:37:53 +00:00
|
|
|
const isStickerLike = isSticker || isEmojiOnly;
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
const containerClassnames = classNames(
|
|
|
|
'module-message__container',
|
2021-04-27 22:11:59 +00:00
|
|
|
isGIF(attachments) ? 'module-message__container--gif' : null,
|
2021-10-06 17:37:53 +00:00
|
|
|
isSelected && !isStickerLike
|
|
|
|
? 'module-message__container--selected'
|
|
|
|
: null,
|
|
|
|
isStickerLike ? 'module-message__container--with-sticker' : null,
|
|
|
|
!isStickerLike ? `module-message__container--${direction}` : null,
|
|
|
|
isEmojiOnly ? 'module-message__container--emoji' : null,
|
2019-11-07 21:36:16 +00:00
|
|
|
isTapToView ? 'module-message__container--with-tap-to-view' : null,
|
|
|
|
isTapToView && isTapToViewExpired
|
|
|
|
? 'module-message__container--with-tap-to-view-expired'
|
|
|
|
: null,
|
2021-10-06 17:37:53 +00:00
|
|
|
!isStickerLike && direction === 'outgoing'
|
2021-05-28 16:15:17 +00:00
|
|
|
? `module-message__container--outgoing-${conversationColor}`
|
2019-11-07 21:36:16 +00:00
|
|
|
: null,
|
|
|
|
isTapToView && isAttachmentPending && !isTapToViewExpired
|
|
|
|
? 'module-message__container--with-tap-to-view-pending'
|
|
|
|
: null,
|
|
|
|
isTapToView && isAttachmentPending && !isTapToViewExpired
|
2021-05-28 16:15:17 +00:00
|
|
|
? `module-message__container--${direction}-${conversationColor}-tap-to-view-pending`
|
2019-11-07 21:36:16 +00:00
|
|
|
: null,
|
|
|
|
isTapToViewError
|
|
|
|
? 'module-message__container--with-tap-to-view-error'
|
2020-02-03 20:02:49 +00:00
|
|
|
: null,
|
2021-01-27 21:15:43 +00:00
|
|
|
this.hasReactions() ? 'module-message__container--with-reactions' : null,
|
2020-04-29 21:24:12 +00:00
|
|
|
deletedForEveryone
|
|
|
|
? 'module-message__container--deleted-for-everyone'
|
2019-11-07 21:36:16 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
const containerStyles = {
|
|
|
|
width: isShowingImage ? width : undefined,
|
|
|
|
};
|
2021-10-06 17:37:53 +00:00
|
|
|
if (!isStickerLike && direction === 'outgoing') {
|
2021-05-28 16:15:17 +00:00
|
|
|
Object.assign(containerStyles, getCustomColorStyle(customColor));
|
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
|
|
|
|
return (
|
2021-01-27 21:15:43 +00:00
|
|
|
<div className="module-message__container-outer">
|
2021-06-09 22:30:05 +00:00
|
|
|
<div
|
|
|
|
className={containerClassnames}
|
|
|
|
style={containerStyles}
|
2021-06-14 18:49:12 +00:00
|
|
|
onContextMenu={this.showContextMenu}
|
2021-06-09 22:30:05 +00:00
|
|
|
>
|
2021-01-27 21:15:43 +00:00
|
|
|
{this.renderAuthor()}
|
|
|
|
{this.renderContents()}
|
|
|
|
</div>
|
|
|
|
{this.renderReactions(direction === 'outgoing')}
|
|
|
|
</div>
|
2019-11-07 21:36:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public render(): JSX.Element | null {
|
2019-11-07 21:36:16 +00:00
|
|
|
const {
|
2021-04-27 19:55:21 +00:00
|
|
|
author,
|
2019-11-07 21:36:16 +00:00
|
|
|
attachments,
|
|
|
|
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.
|
2021-04-27 19:55:21 +00:00
|
|
|
const triggerId = String(id || `${author.id}-${timestamp}`);
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
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,
|
2021-09-30 21:24:23 +00:00
|
|
|
expiring ? 'module-message--expired' : null,
|
|
|
|
this.hasAvatar() ? 'module-message--with-avatar' : 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)}
|
2021-01-27 21:15:43 +00:00
|
|
|
{this.renderAvatar()}
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|