2022-03-04 21:14:52 +00:00
|
|
|
// Copyright 2019-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { MutableRefObject } from 'react';
|
|
|
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
2021-09-29 20:23:06 +00:00
|
|
|
import { get } from 'lodash';
|
2019-08-06 19:18:37 +00:00
|
|
|
import classNames from 'classnames';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
|
|
|
BodyRangeType,
|
|
|
|
BodyRangesType,
|
|
|
|
LocalizerType,
|
2021-11-02 23:01:13 +00:00
|
|
|
ThemeType,
|
2021-10-26 19:15:33 +00:00
|
|
|
} from '../types/Util';
|
2022-02-11 20:18:04 +00:00
|
|
|
import type { ErrorDialogAudioRecorderType } from '../state/ducks/audioRecorder';
|
|
|
|
import { RecordingState } from '../state/ducks/audioRecorder';
|
2021-09-29 20:23:06 +00:00
|
|
|
import type { HandleAttachmentsProcessingArgsType } from '../util/handleAttachmentsProcessing';
|
2021-05-13 20:57:27 +00:00
|
|
|
import { Spinner } from './Spinner';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props as EmojiButtonProps } from './emoji/EmojiButton';
|
|
|
|
import { EmojiButton } from './emoji/EmojiButton';
|
|
|
|
import type { Props as StickerButtonProps } from './stickers/StickerButton';
|
|
|
|
import { StickerButton } from './stickers/StickerButton';
|
|
|
|
import type {
|
2019-06-27 20:35:21 +00:00
|
|
|
InputApi,
|
|
|
|
Props as CompositionInputProps,
|
|
|
|
} from './CompositionInput';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { CompositionInput } from './CompositionInput';
|
|
|
|
import type { Props as MessageRequestActionsProps } from './conversation/MessageRequestActions';
|
|
|
|
import { MessageRequestActions } from './conversation/MessageRequestActions';
|
|
|
|
import type { PropsType as GroupV1DisabledActionsPropsType } from './conversation/GroupV1DisabledActions';
|
|
|
|
import { GroupV1DisabledActions } from './conversation/GroupV1DisabledActions';
|
|
|
|
import type { PropsType as GroupV2PendingApprovalActionsPropsType } from './conversation/GroupV2PendingApprovalActions';
|
|
|
|
import { GroupV2PendingApprovalActions } from './conversation/GroupV2PendingApprovalActions';
|
2021-09-29 20:23:06 +00:00
|
|
|
import { AnnouncementsOnlyGroupBanner } from './AnnouncementsOnlyGroupBanner';
|
2021-06-25 16:08:16 +00:00
|
|
|
import { AttachmentList } from './conversation/AttachmentList';
|
2021-11-15 21:54:33 +00:00
|
|
|
import type {
|
|
|
|
AttachmentDraftType,
|
|
|
|
InMemoryAttachmentDraftType,
|
|
|
|
} from '../types/Attachment';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { isImageAttachment } from '../types/Attachment';
|
2021-09-29 20:23:06 +00:00
|
|
|
import { AudioCapture } from './conversation/AudioCapture';
|
|
|
|
import { CompositionUpload } from './CompositionUpload';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
|
|
|
import type { EmojiPickDataType } from './emoji/EmojiPicker';
|
|
|
|
import type { LinkPreviewWithDomain } from '../types/LinkPreview';
|
|
|
|
|
2021-09-29 20:23:06 +00:00
|
|
|
import { MandatoryProfileSharingActions } from './conversation/MandatoryProfileSharingActions';
|
2021-06-25 16:08:16 +00:00
|
|
|
import { MediaQualitySelector } from './MediaQualitySelector';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props as QuoteProps } from './conversation/Quote';
|
|
|
|
import { Quote } from './conversation/Quote';
|
2021-06-25 16:08:16 +00:00
|
|
|
import { StagedLinkPreview } from './conversation/StagedLinkPreview';
|
2021-09-29 20:23:06 +00:00
|
|
|
import { countStickers } from './stickers/lib';
|
2021-10-15 18:51:58 +00:00
|
|
|
import {
|
|
|
|
useAttachFileShortcut,
|
|
|
|
useKeyboardShortcuts,
|
|
|
|
} from '../hooks/useKeyboardShortcuts';
|
2021-12-01 02:14:25 +00:00
|
|
|
import { MediaEditor } from './MediaEditor';
|
|
|
|
import { IMAGE_PNG } from '../types/MIME';
|
|
|
|
import { isImageTypeSupported } from '../util/GoogleChrome';
|
2019-06-27 20:35:21 +00:00
|
|
|
|
2021-10-05 16:47:06 +00:00
|
|
|
export type CompositionAPIType =
|
|
|
|
| {
|
|
|
|
focusInput: () => void;
|
|
|
|
isDirty: () => boolean;
|
|
|
|
setDisabled: (disabled: boolean) => void;
|
|
|
|
reset: InputApi['reset'];
|
|
|
|
resetEmojiResults: InputApi['resetEmojiResults'];
|
|
|
|
}
|
|
|
|
| undefined;
|
2021-08-30 21:32:56 +00:00
|
|
|
|
2021-09-13 02:36:41 +00:00
|
|
|
export type OwnProps = Readonly<{
|
2021-09-24 20:02:30 +00:00
|
|
|
acceptedMessageRequest?: boolean;
|
|
|
|
addAttachment: (
|
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
attachment: InMemoryAttachmentDraftType
|
2021-09-24 20:02:30 +00:00
|
|
|
) => unknown;
|
|
|
|
addPendingAttachment: (
|
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
pendingAttachment: AttachmentDraftType
|
2021-09-24 20:02:30 +00:00
|
|
|
) => unknown;
|
2021-09-13 02:36:41 +00:00
|
|
|
announcementsOnly?: boolean;
|
|
|
|
areWeAdmin?: boolean;
|
2021-09-24 20:02:30 +00:00
|
|
|
areWePending?: boolean;
|
|
|
|
areWePendingApproval?: boolean;
|
2021-09-29 20:23:06 +00:00
|
|
|
cancelRecording: () => unknown;
|
|
|
|
completeRecording: (
|
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
onSendAudioRecording?: (rec: InMemoryAttachmentDraftType) => unknown
|
2021-09-29 20:23:06 +00:00
|
|
|
) => unknown;
|
2021-09-24 20:02:30 +00:00
|
|
|
compositionApi?: MutableRefObject<CompositionAPIType>;
|
|
|
|
conversationId: string;
|
2021-11-15 21:54:33 +00:00
|
|
|
draftAttachments: ReadonlyArray<AttachmentDraftType>;
|
2021-09-29 20:23:06 +00:00
|
|
|
errorDialogAudioRecorderType?: ErrorDialogAudioRecorderType;
|
|
|
|
errorRecording: (e: ErrorDialogAudioRecorderType) => unknown;
|
2021-09-13 02:36:41 +00:00
|
|
|
groupAdmins: Array<ConversationType>;
|
|
|
|
groupVersion?: 1 | 2;
|
2021-09-24 20:02:30 +00:00
|
|
|
i18n: LocalizerType;
|
|
|
|
isFetchingUUID?: boolean;
|
2021-09-13 02:36:41 +00:00
|
|
|
isGroupV1AndDisabled?: boolean;
|
|
|
|
isMissingMandatoryProfileSharing?: boolean;
|
2021-11-11 23:33:35 +00:00
|
|
|
recordingState: RecordingState;
|
2021-09-13 02:36:41 +00:00
|
|
|
isSMSOnly?: boolean;
|
|
|
|
left?: boolean;
|
2021-09-24 20:02:30 +00:00
|
|
|
linkPreviewLoading: boolean;
|
|
|
|
linkPreviewResult?: LinkPreviewWithDomain;
|
2021-09-13 02:36:41 +00:00
|
|
|
messageRequestsEnabled?: boolean;
|
2021-06-25 16:08:16 +00:00
|
|
|
onClearAttachments(): unknown;
|
2021-09-24 20:02:30 +00:00
|
|
|
onClickQuotedMessage(): unknown;
|
|
|
|
onCloseLinkPreview(): unknown;
|
|
|
|
processAttachments: (options: HandleAttachmentsProcessingArgsType) => unknown;
|
2021-06-25 16:08:16 +00:00
|
|
|
onSelectMediaQuality(isHQ: boolean): unknown;
|
2021-09-29 20:23:06 +00:00
|
|
|
onSendMessage(options: {
|
2021-11-15 21:54:33 +00:00
|
|
|
draftAttachments?: ReadonlyArray<AttachmentDraftType>;
|
2021-09-29 20:23:06 +00:00
|
|
|
mentions?: BodyRangesType;
|
|
|
|
message?: string;
|
|
|
|
timestamp?: number;
|
2021-11-15 21:54:33 +00:00
|
|
|
voiceNoteAttachment?: InMemoryAttachmentDraftType;
|
2021-09-29 20:23:06 +00:00
|
|
|
}): unknown;
|
2021-09-24 20:02:30 +00:00
|
|
|
openConversation(conversationId: string): unknown;
|
2021-09-13 02:36:41 +00:00
|
|
|
quotedMessageProps?: Omit<
|
|
|
|
QuoteProps,
|
|
|
|
'i18n' | 'onClick' | 'onClose' | 'withContentAbove'
|
|
|
|
>;
|
2021-09-24 20:02:30 +00:00
|
|
|
removeAttachment: (conversationId: string, filePath: string) => unknown;
|
2021-06-25 16:08:16 +00:00
|
|
|
setQuotedMessage(message: undefined): unknown;
|
2021-09-24 20:02:30 +00:00
|
|
|
shouldSendHighQualityAttachments: boolean;
|
2021-09-29 20:23:06 +00:00
|
|
|
startRecording: () => unknown;
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: ThemeType;
|
2021-09-13 02:36:41 +00:00
|
|
|
}>;
|
2019-06-27 20:35:21 +00:00
|
|
|
|
2019-08-06 19:18:37 +00:00
|
|
|
export type Props = Pick<
|
|
|
|
CompositionInputProps,
|
2021-01-29 21:19:24 +00:00
|
|
|
| 'sortedGroupMembers'
|
2019-09-13 21:54:19 +00:00
|
|
|
| 'onEditorStateChange'
|
|
|
|
| 'onTextTooLong'
|
2020-11-03 01:19:52 +00:00
|
|
|
| 'draftText'
|
|
|
|
| 'draftBodyRanges'
|
2020-07-01 18:05:41 +00:00
|
|
|
| 'clearQuotedMessage'
|
2021-11-17 18:38:52 +00:00
|
|
|
| 'getPreferredBadge'
|
2020-07-01 18:05:41 +00:00
|
|
|
| 'getQuotedMessage'
|
2019-08-06 19:18:37 +00:00
|
|
|
> &
|
2019-06-27 20:35:21 +00:00
|
|
|
Pick<
|
|
|
|
EmojiButtonProps,
|
|
|
|
'onPickEmoji' | 'onSetSkinTone' | 'recentEmojis' | 'skinTone'
|
|
|
|
> &
|
|
|
|
Pick<
|
|
|
|
StickerButtonProps,
|
|
|
|
| 'knownPacks'
|
|
|
|
| 'receivedPacks'
|
2019-12-16 14:41:43 +00:00
|
|
|
| 'installedPack'
|
2019-06-27 20:35:21 +00:00
|
|
|
| 'installedPacks'
|
|
|
|
| 'blessedPacks'
|
|
|
|
| 'recentStickers'
|
|
|
|
| 'clearInstalledStickerPack'
|
|
|
|
| 'onClickAddPack'
|
|
|
|
| 'onPickSticker'
|
|
|
|
| 'clearShowIntroduction'
|
|
|
|
| 'showPickerHint'
|
|
|
|
| 'clearShowPickerHint'
|
|
|
|
> &
|
2020-05-27 21:37:06 +00:00
|
|
|
MessageRequestActionsProps &
|
2020-12-01 16:42:35 +00:00
|
|
|
Pick<GroupV1DisabledActionsPropsType, 'onStartGroupMigration'> &
|
2021-01-29 22:16:48 +00:00
|
|
|
Pick<GroupV2PendingApprovalActionsPropsType, 'onCancelJoinRequest'> &
|
2019-06-27 20:35:21 +00:00
|
|
|
OwnProps;
|
|
|
|
|
|
|
|
export const CompositionArea = ({
|
2021-09-24 20:02:30 +00:00
|
|
|
// Base props
|
|
|
|
addAttachment,
|
|
|
|
addPendingAttachment,
|
|
|
|
conversationId,
|
2019-06-27 20:35:21 +00:00
|
|
|
i18n,
|
2021-09-29 20:23:06 +00:00
|
|
|
onSendMessage,
|
2021-09-24 20:02:30 +00:00
|
|
|
processAttachments,
|
|
|
|
removeAttachment,
|
2021-11-02 23:01:13 +00:00
|
|
|
theme,
|
2021-09-24 20:02:30 +00:00
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
// AttachmentList
|
|
|
|
draftAttachments,
|
|
|
|
onClearAttachments,
|
2021-09-29 20:23:06 +00:00
|
|
|
// AudioCapture
|
|
|
|
cancelRecording,
|
|
|
|
completeRecording,
|
|
|
|
errorDialogAudioRecorderType,
|
|
|
|
errorRecording,
|
2021-11-11 23:33:35 +00:00
|
|
|
recordingState,
|
2021-09-29 20:23:06 +00:00
|
|
|
startRecording,
|
2021-06-25 16:08:16 +00:00
|
|
|
// StagedLinkPreview
|
|
|
|
linkPreviewLoading,
|
|
|
|
linkPreviewResult,
|
|
|
|
onCloseLinkPreview,
|
|
|
|
// Quote
|
|
|
|
quotedMessageProps,
|
|
|
|
onClickQuotedMessage,
|
|
|
|
setQuotedMessage,
|
|
|
|
// MediaQualitySelector
|
|
|
|
onSelectMediaQuality,
|
|
|
|
shouldSendHighQualityAttachments,
|
2019-06-27 20:35:21 +00:00
|
|
|
// CompositionInput
|
|
|
|
compositionApi,
|
|
|
|
onEditorStateChange,
|
2019-09-13 21:54:19 +00:00
|
|
|
onTextTooLong,
|
2020-11-03 01:19:52 +00:00
|
|
|
draftText,
|
|
|
|
draftBodyRanges,
|
2020-05-27 21:37:06 +00:00
|
|
|
clearQuotedMessage,
|
2021-11-17 18:38:52 +00:00
|
|
|
getPreferredBadge,
|
2020-05-27 21:37:06 +00:00
|
|
|
getQuotedMessage,
|
2021-01-29 21:19:24 +00:00
|
|
|
sortedGroupMembers,
|
2019-06-27 20:35:21 +00:00
|
|
|
// EmojiButton
|
|
|
|
onPickEmoji,
|
|
|
|
onSetSkinTone,
|
|
|
|
recentEmojis,
|
|
|
|
skinTone,
|
|
|
|
// StickerButton
|
|
|
|
knownPacks,
|
|
|
|
receivedPacks,
|
2019-12-16 14:41:43 +00:00
|
|
|
installedPack,
|
2019-06-27 20:35:21 +00:00
|
|
|
installedPacks,
|
|
|
|
blessedPacks,
|
|
|
|
recentStickers,
|
|
|
|
clearInstalledStickerPack,
|
|
|
|
onClickAddPack,
|
|
|
|
onPickSticker,
|
|
|
|
clearShowIntroduction,
|
|
|
|
showPickerHint,
|
|
|
|
clearShowPickerHint,
|
2020-05-27 21:37:06 +00:00
|
|
|
// Message Requests
|
|
|
|
acceptedMessageRequest,
|
2020-10-26 14:39:45 +00:00
|
|
|
areWePending,
|
2021-01-29 22:16:48 +00:00
|
|
|
areWePendingApproval,
|
2020-05-27 21:37:06 +00:00
|
|
|
conversationType,
|
2020-10-16 18:31:57 +00:00
|
|
|
groupVersion,
|
2020-05-27 21:37:06 +00:00
|
|
|
isBlocked,
|
2020-10-16 18:31:57 +00:00
|
|
|
isMissingMandatoryProfileSharing,
|
2021-01-12 15:44:44 +00:00
|
|
|
left,
|
2020-07-24 01:35:32 +00:00
|
|
|
messageRequestsEnabled,
|
2020-05-27 21:37:06 +00:00
|
|
|
onAccept,
|
|
|
|
onBlock,
|
2021-05-27 20:17:05 +00:00
|
|
|
onBlockAndReportSpam,
|
2020-05-27 21:37:06 +00:00
|
|
|
onDelete,
|
2020-07-24 01:35:32 +00:00
|
|
|
onUnblock,
|
|
|
|
title,
|
2020-12-01 16:42:35 +00:00
|
|
|
// GroupV1 Disabled Actions
|
|
|
|
isGroupV1AndDisabled,
|
|
|
|
onStartGroupMigration,
|
2021-07-20 20:18:35 +00:00
|
|
|
// GroupV2
|
|
|
|
announcementsOnly,
|
|
|
|
areWeAdmin,
|
|
|
|
groupAdmins,
|
2021-01-29 22:16:48 +00:00
|
|
|
onCancelJoinRequest,
|
2021-07-20 20:18:35 +00:00
|
|
|
openConversation,
|
2021-05-13 20:57:27 +00:00
|
|
|
// SMS-only contacts
|
|
|
|
isSMSOnly,
|
|
|
|
isFetchingUUID,
|
2020-09-12 00:46:52 +00:00
|
|
|
}: Props): JSX.Element => {
|
2021-09-24 20:02:30 +00:00
|
|
|
const [disabled, setDisabled] = useState(false);
|
|
|
|
const [dirty, setDirty] = useState(false);
|
|
|
|
const [large, setLarge] = useState(false);
|
2021-12-01 02:14:25 +00:00
|
|
|
const [attachmentToEdit, setAttachmentToEdit] = useState<
|
|
|
|
AttachmentDraftType | undefined
|
|
|
|
>();
|
2021-09-24 20:02:30 +00:00
|
|
|
const inputApiRef = useRef<InputApi | undefined>();
|
|
|
|
const fileInputRef = useRef<null | HTMLInputElement>(null);
|
|
|
|
|
|
|
|
const handleForceSend = useCallback(() => {
|
2020-01-08 17:44:54 +00:00
|
|
|
setLarge(false);
|
|
|
|
if (inputApiRef.current) {
|
|
|
|
inputApiRef.current.submit();
|
|
|
|
}
|
|
|
|
}, [inputApiRef, setLarge]);
|
2019-08-06 19:18:37 +00:00
|
|
|
|
2021-09-29 20:23:06 +00:00
|
|
|
const handleSubmit = useCallback(
|
|
|
|
(message: string, mentions: Array<BodyRangeType>, timestamp: number) => {
|
2019-08-06 19:18:37 +00:00
|
|
|
setLarge(false);
|
2021-09-29 20:23:06 +00:00
|
|
|
onSendMessage({
|
|
|
|
draftAttachments,
|
|
|
|
mentions,
|
|
|
|
message,
|
|
|
|
timestamp,
|
|
|
|
});
|
2019-08-06 19:18:37 +00:00
|
|
|
},
|
2021-09-29 20:23:06 +00:00
|
|
|
[draftAttachments, onSendMessage, setLarge]
|
2019-06-27 20:35:21 +00:00
|
|
|
);
|
|
|
|
|
2021-10-15 18:51:58 +00:00
|
|
|
const launchAttachmentPicker = useCallback(() => {
|
2021-09-24 20:02:30 +00:00
|
|
|
const fileInput = fileInputRef.current;
|
|
|
|
if (fileInput) {
|
|
|
|
// Setting the value to empty so that onChange always fires in case
|
|
|
|
// you add multiple photos.
|
|
|
|
fileInput.value = '';
|
|
|
|
fileInput.click();
|
|
|
|
}
|
2021-10-15 18:51:58 +00:00
|
|
|
}, []);
|
|
|
|
|
2021-12-01 02:14:25 +00:00
|
|
|
function maybeEditAttachment(attachment: AttachmentDraftType) {
|
2021-12-15 00:53:15 +00:00
|
|
|
if (!isImageTypeSupported(attachment.contentType)) {
|
2021-12-01 02:14:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setAttachmentToEdit(attachment);
|
|
|
|
}
|
|
|
|
|
2021-10-15 18:51:58 +00:00
|
|
|
const attachFileShortcut = useAttachFileShortcut(launchAttachmentPicker);
|
|
|
|
useKeyboardShortcuts(attachFileShortcut);
|
2021-09-24 20:02:30 +00:00
|
|
|
|
|
|
|
const focusInput = useCallback(() => {
|
2020-10-21 16:53:32 +00:00
|
|
|
if (inputApiRef.current) {
|
|
|
|
inputApiRef.current.focus();
|
2020-01-08 17:44:54 +00:00
|
|
|
}
|
2020-10-21 16:53:32 +00:00
|
|
|
}, [inputApiRef]);
|
2019-06-27 20:35:21 +00:00
|
|
|
|
|
|
|
const withStickers =
|
|
|
|
countStickers({
|
|
|
|
knownPacks,
|
|
|
|
blessedPacks,
|
|
|
|
installedPacks,
|
|
|
|
receivedPacks,
|
|
|
|
}) > 0;
|
|
|
|
|
|
|
|
if (compositionApi) {
|
2020-09-12 00:46:52 +00:00
|
|
|
// Using a React.MutableRefObject, so we need to reassign this prop.
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
2019-06-27 20:35:21 +00:00
|
|
|
compositionApi.current = {
|
2019-11-07 21:36:16 +00:00
|
|
|
isDirty: () => dirty,
|
2019-06-27 20:35:21 +00:00
|
|
|
focusInput,
|
|
|
|
setDisabled,
|
|
|
|
reset: () => {
|
|
|
|
if (inputApiRef.current) {
|
|
|
|
inputApiRef.current.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resetEmojiResults: () => {
|
|
|
|
if (inputApiRef.current) {
|
|
|
|
inputApiRef.current.resetEmojiResults();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const insertEmoji = useCallback(
|
2019-06-27 20:35:21 +00:00
|
|
|
(e: EmojiPickDataType) => {
|
|
|
|
if (inputApiRef.current) {
|
|
|
|
inputApiRef.current.insertEmoji(e);
|
|
|
|
onPickEmoji(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[inputApiRef, onPickEmoji]
|
|
|
|
);
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const handleToggleLarge = useCallback(() => {
|
2020-01-08 17:44:54 +00:00
|
|
|
setLarge(l => !l);
|
|
|
|
}, [setLarge]);
|
2019-08-06 19:18:37 +00:00
|
|
|
|
2021-10-05 16:47:06 +00:00
|
|
|
const shouldShowMicrophone = !large && !draftAttachments.length && !draftText;
|
2021-09-24 20:02:30 +00:00
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
const showMediaQualitySelector = draftAttachments.some(isImageAttachment);
|
|
|
|
|
|
|
|
const leftHandSideButtonsFragment = (
|
|
|
|
<>
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__button-cell">
|
2021-06-25 16:08:16 +00:00
|
|
|
<EmojiButton
|
|
|
|
i18n={i18n}
|
|
|
|
doSend={handleForceSend}
|
|
|
|
onPickEmoji={insertEmoji}
|
|
|
|
onClose={focusInput}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
skinTone={skinTone}
|
|
|
|
onSetSkinTone={onSetSkinTone}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{showMediaQualitySelector ? (
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__button-cell">
|
2021-06-25 16:08:16 +00:00
|
|
|
<MediaQualitySelector
|
|
|
|
i18n={i18n}
|
|
|
|
isHighQuality={shouldSendHighQualityAttachments}
|
|
|
|
onSelectQuality={onSelectMediaQuality}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</>
|
2019-08-06 19:18:37 +00:00
|
|
|
);
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const micButtonFragment = shouldShowMicrophone ? (
|
2021-09-29 20:23:06 +00:00
|
|
|
<AudioCapture
|
|
|
|
cancelRecording={cancelRecording}
|
|
|
|
completeRecording={completeRecording}
|
|
|
|
conversationId={conversationId}
|
|
|
|
draftAttachments={draftAttachments}
|
|
|
|
errorDialogAudioRecorderType={errorDialogAudioRecorderType}
|
|
|
|
errorRecording={errorRecording}
|
|
|
|
i18n={i18n}
|
2021-11-11 23:33:35 +00:00
|
|
|
recordingState={recordingState}
|
2021-11-15 21:54:33 +00:00
|
|
|
onSendAudioRecording={(
|
|
|
|
voiceNoteAttachment: InMemoryAttachmentDraftType
|
|
|
|
) => {
|
2021-09-29 20:23:06 +00:00
|
|
|
onSendMessage({ voiceNoteAttachment });
|
|
|
|
}}
|
|
|
|
startRecording={startRecording}
|
2019-08-06 19:18:37 +00:00
|
|
|
/>
|
|
|
|
) : null;
|
|
|
|
|
2022-02-11 20:18:04 +00:00
|
|
|
const isRecording = recordingState === RecordingState.Recording;
|
|
|
|
const attButton =
|
|
|
|
linkPreviewResult || isRecording ? undefined : (
|
|
|
|
<div className="CompositionArea__button-cell">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="CompositionArea__attach-file"
|
|
|
|
onClick={launchAttachmentPicker}
|
|
|
|
aria-label={i18n('CompositionArea--attach-file')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2019-08-06 19:18:37 +00:00
|
|
|
|
|
|
|
const sendButtonFragment = (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea__button-cell',
|
|
|
|
large ? 'CompositionArea__button-cell--large-right' : null
|
2019-08-06 19:18:37 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<button
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2021-07-20 20:18:35 +00:00
|
|
|
className="CompositionArea__send-button"
|
2019-08-06 19:18:37 +00:00
|
|
|
onClick={handleForceSend}
|
2020-09-12 00:46:52 +00:00
|
|
|
aria-label={i18n('sendMessageToContact')}
|
2019-08-06 19:18:37 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
const stickerButtonPlacement = large ? 'top-start' : 'top-end';
|
|
|
|
const stickerButtonFragment = withStickers ? (
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__button-cell">
|
2019-08-06 19:18:37 +00:00
|
|
|
<StickerButton
|
|
|
|
i18n={i18n}
|
|
|
|
knownPacks={knownPacks}
|
|
|
|
receivedPacks={receivedPacks}
|
2019-12-16 14:41:43 +00:00
|
|
|
installedPack={installedPack}
|
2019-08-06 19:18:37 +00:00
|
|
|
installedPacks={installedPacks}
|
|
|
|
blessedPacks={blessedPacks}
|
|
|
|
recentStickers={recentStickers}
|
|
|
|
clearInstalledStickerPack={clearInstalledStickerPack}
|
|
|
|
onClickAddPack={onClickAddPack}
|
|
|
|
onPickSticker={onPickSticker}
|
|
|
|
clearShowIntroduction={clearShowIntroduction}
|
|
|
|
showPickerHint={showPickerHint}
|
|
|
|
clearShowPickerHint={clearShowPickerHint}
|
|
|
|
position={stickerButtonPlacement}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
|
2019-08-20 17:02:13 +00:00
|
|
|
// Listen for cmd/ctrl-shift-x to toggle large composition mode
|
2021-09-24 20:02:30 +00:00
|
|
|
useEffect(() => {
|
2020-01-08 17:44:54 +00:00
|
|
|
const handler = (e: KeyboardEvent) => {
|
|
|
|
const { key, shiftKey, ctrlKey, metaKey } = e;
|
|
|
|
// When using the ctrl key, `key` is `'X'`. When using the cmd key, `key` is `'x'`
|
|
|
|
const xKey = key === 'x' || key === 'X';
|
|
|
|
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
|
|
|
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
|
|
|
const commandOrCtrl = commandKey || controlKey;
|
2019-12-17 18:52:36 +00:00
|
|
|
|
2020-01-08 17:44:54 +00:00
|
|
|
// cmd/ctrl-shift-x
|
|
|
|
if (xKey && shiftKey && commandOrCtrl) {
|
|
|
|
e.preventDefault();
|
|
|
|
setLarge(x => !x);
|
|
|
|
}
|
|
|
|
};
|
2019-08-20 17:02:13 +00:00
|
|
|
|
2020-01-08 17:44:54 +00:00
|
|
|
document.addEventListener('keydown', handler);
|
2019-08-20 17:02:13 +00:00
|
|
|
|
2020-01-08 17:44:54 +00:00
|
|
|
return () => {
|
|
|
|
document.removeEventListener('keydown', handler);
|
|
|
|
};
|
|
|
|
}, [setLarge]);
|
2019-08-20 17:02:13 +00:00
|
|
|
|
2020-10-26 14:39:45 +00:00
|
|
|
if (
|
2020-11-20 17:30:45 +00:00
|
|
|
isBlocked ||
|
|
|
|
areWePending ||
|
|
|
|
(messageRequestsEnabled && !acceptedMessageRequest)
|
2020-10-26 14:39:45 +00:00
|
|
|
) {
|
2020-05-27 21:37:06 +00:00
|
|
|
return (
|
|
|
|
<MessageRequestActions
|
|
|
|
i18n={i18n}
|
|
|
|
conversationType={conversationType}
|
|
|
|
isBlocked={isBlocked}
|
|
|
|
onBlock={onBlock}
|
2021-05-27 20:17:05 +00:00
|
|
|
onBlockAndReportSpam={onBlockAndReportSpam}
|
2020-05-27 21:37:06 +00:00
|
|
|
onUnblock={onUnblock}
|
|
|
|
onDelete={onDelete}
|
|
|
|
onAccept={onAccept}
|
2020-07-24 01:35:32 +00:00
|
|
|
title={title}
|
2020-05-27 21:37:06 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:57:27 +00:00
|
|
|
if (conversationType === 'direct' && isSMSOnly) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames([
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea',
|
|
|
|
'CompositionArea--sms-only',
|
|
|
|
isFetchingUUID ? 'CompositionArea--pending' : null,
|
2021-05-13 20:57:27 +00:00
|
|
|
])}
|
|
|
|
>
|
|
|
|
{isFetchingUUID ? (
|
|
|
|
<Spinner
|
|
|
|
ariaLabel={i18n('CompositionArea--sms-only__spinner-label')}
|
|
|
|
role="presentation"
|
|
|
|
moduleClassName="module-image-spinner"
|
|
|
|
svgSize="small"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
2021-07-20 20:18:35 +00:00
|
|
|
<h2 className="CompositionArea--sms-only__title">
|
2021-05-13 20:57:27 +00:00
|
|
|
{i18n('CompositionArea--sms-only__title')}
|
|
|
|
</h2>
|
2021-07-20 20:18:35 +00:00
|
|
|
<p className="CompositionArea--sms-only__body">
|
2021-05-13 20:57:27 +00:00
|
|
|
{i18n('CompositionArea--sms-only__body')}
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-16 18:31:57 +00:00
|
|
|
// If no message request, but we haven't shared profile yet, we show profile-sharing UI
|
|
|
|
if (
|
2021-01-12 15:44:44 +00:00
|
|
|
!left &&
|
2020-10-16 18:31:57 +00:00
|
|
|
(conversationType === 'direct' ||
|
|
|
|
(conversationType === 'group' && groupVersion === 1)) &&
|
|
|
|
isMissingMandatoryProfileSharing
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<MandatoryProfileSharingActions
|
|
|
|
i18n={i18n}
|
|
|
|
conversationType={conversationType}
|
|
|
|
onBlock={onBlock}
|
2021-05-27 20:17:05 +00:00
|
|
|
onBlockAndReportSpam={onBlockAndReportSpam}
|
2020-10-16 18:31:57 +00:00
|
|
|
onDelete={onDelete}
|
|
|
|
onAccept={onAccept}
|
|
|
|
title={title}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:42:35 +00:00
|
|
|
// If this is a V1 group, now disabled entirely, we show UI to help them upgrade
|
2021-01-12 15:44:44 +00:00
|
|
|
if (!left && isGroupV1AndDisabled) {
|
2020-12-01 16:42:35 +00:00
|
|
|
return (
|
|
|
|
<GroupV1DisabledActions
|
|
|
|
i18n={i18n}
|
|
|
|
onStartGroupMigration={onStartGroupMigration}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
if (areWePendingApproval) {
|
|
|
|
return (
|
|
|
|
<GroupV2PendingApprovalActions
|
|
|
|
i18n={i18n}
|
|
|
|
onCancelJoinRequest={onCancelJoinRequest}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-20 20:18:35 +00:00
|
|
|
if (announcementsOnly && !areWeAdmin) {
|
|
|
|
return (
|
|
|
|
<AnnouncementsOnlyGroupBanner
|
|
|
|
groupAdmins={groupAdmins}
|
|
|
|
i18n={i18n}
|
|
|
|
openConversation={openConversation}
|
2021-11-02 23:01:13 +00:00
|
|
|
theme={theme}
|
2021-07-20 20:18:35 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
return (
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea">
|
2021-12-01 02:14:25 +00:00
|
|
|
{attachmentToEdit && 'url' in attachmentToEdit && attachmentToEdit.url && (
|
|
|
|
<MediaEditor
|
|
|
|
i18n={i18n}
|
|
|
|
imageSrc={attachmentToEdit.url}
|
|
|
|
onClose={() => setAttachmentToEdit(undefined)}
|
|
|
|
onDone={data => {
|
|
|
|
const newAttachment = {
|
|
|
|
...attachmentToEdit,
|
|
|
|
contentType: IMAGE_PNG,
|
|
|
|
data,
|
|
|
|
size: data.byteLength,
|
|
|
|
};
|
|
|
|
|
|
|
|
addAttachment(conversationId, newAttachment);
|
|
|
|
setAttachmentToEdit(undefined);
|
|
|
|
}}
|
|
|
|
installedPacks={installedPacks}
|
|
|
|
recentStickers={recentStickers}
|
|
|
|
/>
|
|
|
|
)}
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__toggle-large">
|
2019-08-06 19:18:37 +00:00
|
|
|
<button
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2019-08-06 19:18:37 +00:00
|
|
|
className={classNames(
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea__toggle-large__button',
|
|
|
|
large ? 'CompositionArea__toggle-large__button--large-active' : null
|
2019-08-06 19:18:37 +00:00
|
|
|
)}
|
2019-11-07 21:36:16 +00:00
|
|
|
// This prevents the user from tabbing here
|
|
|
|
tabIndex={-1}
|
2019-08-06 19:18:37 +00:00
|
|
|
onClick={handleToggleLarge}
|
2020-09-12 00:46:52 +00:00
|
|
|
aria-label={i18n('CompositionArea--expand')}
|
2019-06-27 20:35:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2019-08-06 19:18:37 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea__row',
|
|
|
|
'CompositionArea__row--column'
|
2019-08-06 19:18:37 +00:00
|
|
|
)}
|
2021-06-25 16:08:16 +00:00
|
|
|
>
|
|
|
|
{quotedMessageProps && (
|
|
|
|
<div className="quote-wrapper">
|
|
|
|
<Quote
|
|
|
|
{...quotedMessageProps}
|
|
|
|
i18n={i18n}
|
|
|
|
onClick={onClickQuotedMessage}
|
|
|
|
onClose={() => {
|
|
|
|
// This one is for redux...
|
|
|
|
setQuotedMessage(undefined);
|
|
|
|
// and this is for conversation_view.
|
2022-03-04 21:14:52 +00:00
|
|
|
clearQuotedMessage?.();
|
2021-06-25 16:08:16 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{linkPreviewLoading && (
|
|
|
|
<div className="preview-wrapper">
|
|
|
|
<StagedLinkPreview
|
|
|
|
{...(linkPreviewResult || {})}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={onCloseLinkPreview}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{draftAttachments.length ? (
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__attachment-list">
|
2021-06-25 16:08:16 +00:00
|
|
|
<AttachmentList
|
|
|
|
attachments={draftAttachments}
|
2022-02-02 15:31:16 +00:00
|
|
|
canEditImages
|
2021-06-25 16:08:16 +00:00
|
|
|
i18n={i18n}
|
2021-09-24 20:02:30 +00:00
|
|
|
onAddAttachment={launchAttachmentPicker}
|
2021-12-01 02:14:25 +00:00
|
|
|
onClickAttachment={maybeEditAttachment}
|
2021-06-25 16:08:16 +00:00
|
|
|
onClose={onClearAttachments}
|
2021-09-24 20:02:30 +00:00
|
|
|
onCloseAttachment={attachment => {
|
|
|
|
if (attachment.path) {
|
|
|
|
removeAttachment(conversationId, attachment.path);
|
|
|
|
}
|
|
|
|
}}
|
2021-06-25 16:08:16 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2019-08-06 19:18:37 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea__row',
|
|
|
|
large ? 'CompositionArea__row--padded' : null
|
2019-08-06 19:18:37 +00:00
|
|
|
)}
|
|
|
|
>
|
2021-06-25 16:08:16 +00:00
|
|
|
{!large ? leftHandSideButtonsFragment : null}
|
2021-07-20 20:18:35 +00:00
|
|
|
<div className="CompositionArea__input">
|
2019-08-06 19:18:37 +00:00
|
|
|
<CompositionInput
|
2021-11-03 02:00:54 +00:00
|
|
|
clearQuotedMessage={clearQuotedMessage}
|
2019-08-06 19:18:37 +00:00
|
|
|
disabled={disabled}
|
2021-11-03 02:00:54 +00:00
|
|
|
draftBodyRanges={draftBodyRanges}
|
|
|
|
draftText={draftText}
|
2021-11-17 18:38:52 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2021-11-03 02:00:54 +00:00
|
|
|
getQuotedMessage={getQuotedMessage}
|
2021-11-30 11:25:24 +00:00
|
|
|
i18n={i18n}
|
2019-08-06 19:18:37 +00:00
|
|
|
inputApi={inputApiRef}
|
2021-11-03 02:00:54 +00:00
|
|
|
large={large}
|
|
|
|
onDirtyChange={setDirty}
|
|
|
|
onEditorStateChange={onEditorStateChange}
|
2019-08-06 19:18:37 +00:00
|
|
|
onPickEmoji={onPickEmoji}
|
|
|
|
onSubmit={handleSubmit}
|
2019-09-13 21:54:19 +00:00
|
|
|
onTextTooLong={onTextTooLong}
|
2019-08-06 19:18:37 +00:00
|
|
|
skinTone={skinTone}
|
2021-01-29 21:19:24 +00:00
|
|
|
sortedGroupMembers={sortedGroupMembers}
|
2021-11-17 18:38:52 +00:00
|
|
|
theme={theme}
|
2019-06-27 20:35:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2019-08-06 19:18:37 +00:00
|
|
|
{!large ? (
|
|
|
|
<>
|
|
|
|
{stickerButtonFragment}
|
|
|
|
{!dirty ? micButtonFragment : null}
|
2019-08-07 00:40:25 +00:00
|
|
|
{attButton}
|
2019-08-06 19:18:37 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
{large ? (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2021-07-20 20:18:35 +00:00
|
|
|
'CompositionArea__row',
|
|
|
|
'CompositionArea__row--control-row'
|
2019-08-06 19:18:37 +00:00
|
|
|
)}
|
|
|
|
>
|
2021-06-25 16:08:16 +00:00
|
|
|
{leftHandSideButtonsFragment}
|
2019-08-06 19:18:37 +00:00
|
|
|
{stickerButtonFragment}
|
2019-08-07 00:40:25 +00:00
|
|
|
{attButton}
|
2019-08-06 19:18:37 +00:00
|
|
|
{!dirty ? micButtonFragment : null}
|
2021-09-24 20:02:30 +00:00
|
|
|
{dirty || !shouldShowMicrophone ? sendButtonFragment : null}
|
2019-08-06 19:18:37 +00:00
|
|
|
</div>
|
2019-06-27 20:35:21 +00:00
|
|
|
) : null}
|
2021-09-24 20:02:30 +00:00
|
|
|
<CompositionUpload
|
|
|
|
addAttachment={addAttachment}
|
|
|
|
addPendingAttachment={addPendingAttachment}
|
|
|
|
conversationId={conversationId}
|
|
|
|
draftAttachments={draftAttachments}
|
|
|
|
i18n={i18n}
|
|
|
|
processAttachments={processAttachments}
|
|
|
|
removeAttachment={removeAttachment}
|
|
|
|
ref={fileInputRef}
|
|
|
|
/>
|
2019-06-27 20:35:21 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|