2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-03-02 20:55:40 +00:00
|
|
|
import React from 'react';
|
2019-05-16 22:32:11 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { get } from 'lodash';
|
2023-04-20 16:31:59 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props as ComponentPropsType } from '../../components/CompositionArea';
|
|
|
|
import { CompositionArea } from '../../components/CompositionArea';
|
|
|
|
import type { StateType } from '../reducer';
|
2023-09-14 17:04:48 +00:00
|
|
|
import type {
|
|
|
|
DraftBodyRanges,
|
|
|
|
HydratedBodyRangesType,
|
|
|
|
} from '../../types/BodyRange';
|
2021-05-13 20:57:27 +00:00
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
2021-09-13 02:36:41 +00:00
|
|
|
import { dropNull } from '../../util/dropNull';
|
2022-11-16 21:41:38 +00:00
|
|
|
import { imageToBlurHash } from '../../util/imageToBlurHash';
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2021-11-17 18:38:52 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2021-04-27 22:35:35 +00:00
|
|
|
import { selectRecentEmojis } from '../selectors/emojis';
|
2023-05-10 00:40:19 +00:00
|
|
|
import {
|
|
|
|
getIntl,
|
|
|
|
getPlatform,
|
|
|
|
getTheme,
|
|
|
|
getUserConversationId,
|
|
|
|
} from '../selectors/user';
|
2023-09-01 17:03:44 +00:00
|
|
|
import {
|
|
|
|
getDefaultConversationColor,
|
|
|
|
getEmojiSkinTone,
|
|
|
|
getTextFormattingEnabled,
|
|
|
|
} from '../selectors/items';
|
2021-06-17 17:15:10 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
2021-07-20 20:18:35 +00:00
|
|
|
getGroupAdminsSelector,
|
2023-07-26 22:23:32 +00:00
|
|
|
getHasPanelOpen,
|
2023-05-12 00:27:19 +00:00
|
|
|
getLastEditableMessageId,
|
2023-03-20 22:23:53 +00:00
|
|
|
getSelectedMessageIds,
|
2021-06-17 17:15:10 +00:00
|
|
|
isMissingRequiredProfileSharing,
|
|
|
|
} from '../selectors/conversations';
|
2021-06-25 16:08:16 +00:00
|
|
|
import { getPropsForQuote } from '../selectors/message';
|
2019-05-16 22:32:11 +00:00
|
|
|
import {
|
2019-05-24 01:27:42 +00:00
|
|
|
getBlessedStickerPacks,
|
2019-05-16 22:32:11 +00:00
|
|
|
getInstalledStickerPacks,
|
2019-05-24 01:27:42 +00:00
|
|
|
getKnownStickerPacks,
|
2019-05-16 22:32:11 +00:00
|
|
|
getReceivedStickerPacks,
|
2020-01-09 14:35:33 +00:00
|
|
|
getRecentlyInstalledStickerPack,
|
2019-05-16 22:32:11 +00:00
|
|
|
getRecentStickers,
|
|
|
|
} from '../selectors/stickers';
|
2022-11-09 02:38:19 +00:00
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
2023-04-14 18:16:28 +00:00
|
|
|
import {
|
|
|
|
getComposerStateForConversationIdSelector,
|
2023-04-18 01:16:41 +00:00
|
|
|
getIsFormattingFlagEnabled,
|
|
|
|
getIsFormattingSpoilersFlagEnabled,
|
2023-04-14 18:16:28 +00:00
|
|
|
} from '../selectors/composer';
|
2023-03-02 20:55:40 +00:00
|
|
|
import type { SmartCompositionRecordingProps } from './CompositionRecording';
|
|
|
|
import { SmartCompositionRecording } from './CompositionRecording';
|
|
|
|
import type { SmartCompositionRecordingDraftProps } from './CompositionRecordingDraft';
|
|
|
|
import { SmartCompositionRecordingDraft } from './CompositionRecordingDraft';
|
2023-09-14 17:04:48 +00:00
|
|
|
import { hydrateRanges } from '../../types/BodyRange';
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2019-08-07 00:40:25 +00:00
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
|
2021-10-05 16:47:06 +00:00
|
|
|
export type CompositionAreaPropsType = ExternalProps & ComponentPropsType;
|
|
|
|
|
2019-08-07 00:40:25 +00:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
2022-12-09 19:11:14 +00:00
|
|
|
const { id } = props;
|
2023-05-10 00:40:19 +00:00
|
|
|
const platform = getPlatform(state);
|
2019-08-07 00:40:25 +00:00
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const shouldHidePopovers = getHasPanelOpen(state);
|
2023-05-10 01:23:56 +00:00
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
const conversationSelector = getConversationSelector(state);
|
|
|
|
const conversation = conversationSelector(id);
|
2019-08-07 00:40:25 +00:00
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(`Conversation id ${id} not found!`);
|
|
|
|
}
|
|
|
|
|
2023-04-20 16:31:59 +00:00
|
|
|
const {
|
|
|
|
announcementsOnly,
|
|
|
|
areWeAdmin,
|
|
|
|
draftEditMessage,
|
|
|
|
draftText,
|
|
|
|
draftBodyRanges,
|
|
|
|
} = conversation;
|
2019-08-07 00:40:25 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
const receivedPacks = getReceivedStickerPacks(state);
|
|
|
|
const installedPacks = getInstalledStickerPacks(state);
|
2019-05-24 01:27:42 +00:00
|
|
|
const blessedPacks = getBlessedStickerPacks(state);
|
|
|
|
const knownPacks = getKnownStickerPacks(state);
|
|
|
|
|
2020-01-09 14:35:33 +00:00
|
|
|
const installedPack = getRecentlyInstalledStickerPack(state);
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
const recentStickers = getRecentStickers(state);
|
|
|
|
const showIntroduction = get(
|
|
|
|
state.items,
|
2019-05-29 22:48:43 +00:00
|
|
|
['showStickersIntroduction'],
|
2019-05-16 22:32:11 +00:00
|
|
|
false
|
|
|
|
);
|
2021-09-13 02:36:41 +00:00
|
|
|
const showPickerHint = Boolean(
|
2019-05-29 22:48:43 +00:00
|
|
|
get(state.items, ['showStickerPickerHint'], false) &&
|
2021-09-13 02:36:41 +00:00
|
|
|
receivedPacks.length > 0
|
|
|
|
);
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2023-01-05 00:22:36 +00:00
|
|
|
const composerStateForConversationIdSelector =
|
|
|
|
getComposerStateForConversationIdSelector(state);
|
|
|
|
|
2023-04-20 16:31:59 +00:00
|
|
|
const composerState = composerStateForConversationIdSelector(id);
|
2021-06-25 16:08:16 +00:00
|
|
|
const {
|
|
|
|
attachments: draftAttachments,
|
2022-12-08 23:56:17 +00:00
|
|
|
focusCounter,
|
2022-12-08 07:43:48 +00:00
|
|
|
isDisabled,
|
2021-06-25 16:08:16 +00:00
|
|
|
linkPreviewLoading,
|
|
|
|
linkPreviewResult,
|
2022-12-08 07:43:48 +00:00
|
|
|
messageCompositionId,
|
2023-04-05 22:06:16 +00:00
|
|
|
sendCounter,
|
2021-06-25 16:08:16 +00:00
|
|
|
shouldSendHighQualityAttachments,
|
2023-04-20 16:31:59 +00:00
|
|
|
} = composerState;
|
|
|
|
|
|
|
|
let { quotedMessage } = composerState;
|
|
|
|
if (!quotedMessage && draftEditMessage?.quote) {
|
|
|
|
quotedMessage = {
|
|
|
|
conversationId: id,
|
|
|
|
quote: draftEditMessage.quote,
|
|
|
|
};
|
|
|
|
}
|
2021-06-25 16:08:16 +00:00
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
const recentEmojis = selectRecentEmojis(state);
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const selectedMessageIds = getSelectedMessageIds(state);
|
|
|
|
|
2023-05-10 00:40:19 +00:00
|
|
|
const isFormattingEnabled = getTextFormattingEnabled(state);
|
|
|
|
const isFormattingFlagEnabled = getIsFormattingFlagEnabled(state);
|
|
|
|
const isFormattingSpoilersFlagEnabled =
|
|
|
|
getIsFormattingSpoilersFlagEnabled(state);
|
2023-04-14 18:16:28 +00:00
|
|
|
|
2023-05-12 00:27:19 +00:00
|
|
|
const lastEditableMessageId = getLastEditableMessageId(state);
|
|
|
|
|
2023-09-14 17:04:48 +00:00
|
|
|
const convertDraftBodyRangesIntoHydrated = (
|
|
|
|
bodyRanges: DraftBodyRanges | undefined
|
|
|
|
): HydratedBodyRangesType | undefined => {
|
|
|
|
return hydrateRanges(bodyRanges, conversationSelector);
|
|
|
|
};
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
return {
|
2019-06-27 20:35:21 +00:00
|
|
|
// Base
|
2021-09-24 20:02:30 +00:00
|
|
|
conversationId: id,
|
2023-04-20 16:31:59 +00:00
|
|
|
draftEditMessage,
|
2022-12-08 23:56:17 +00:00
|
|
|
focusCounter,
|
2022-12-08 07:43:48 +00:00
|
|
|
getPreferredBadge: getPreferredBadgeSelector(state),
|
2019-06-27 20:35:21 +00:00
|
|
|
i18n: getIntl(state),
|
2022-12-08 07:43:48 +00:00
|
|
|
isDisabled,
|
2023-04-14 18:16:28 +00:00
|
|
|
isFormattingEnabled,
|
2023-05-10 00:40:19 +00:00
|
|
|
isFormattingFlagEnabled,
|
|
|
|
isFormattingSpoilersFlagEnabled,
|
2023-05-12 00:27:19 +00:00
|
|
|
lastEditableMessageId,
|
2022-12-08 07:43:48 +00:00
|
|
|
messageCompositionId,
|
2023-05-10 00:40:19 +00:00
|
|
|
platform,
|
2023-04-05 22:06:16 +00:00
|
|
|
sendCounter,
|
2023-05-10 01:23:56 +00:00
|
|
|
shouldHidePopovers,
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: getTheme(state),
|
2023-09-14 17:04:48 +00:00
|
|
|
convertDraftBodyRangesIntoHydrated,
|
2022-12-08 23:56:17 +00:00
|
|
|
|
2021-09-29 20:23:06 +00:00
|
|
|
// AudioCapture
|
|
|
|
errorDialogAudioRecorderType:
|
|
|
|
state.audioRecorder.errorDialogAudioRecorderType,
|
2021-11-11 23:33:35 +00:00
|
|
|
recordingState: state.audioRecorder.recordingState,
|
2021-06-25 16:08:16 +00:00
|
|
|
// AttachmentsList
|
|
|
|
draftAttachments,
|
2022-11-16 21:41:38 +00:00
|
|
|
// MediaEditor
|
|
|
|
imageToBlurHash,
|
2021-06-25 16:08:16 +00:00
|
|
|
// MediaQualitySelector
|
2022-12-02 23:54:37 +00:00
|
|
|
shouldSendHighQualityAttachments:
|
|
|
|
shouldSendHighQualityAttachments !== undefined
|
|
|
|
? shouldSendHighQualityAttachments
|
|
|
|
: window.storage.get('sent-media-quality') === 'high',
|
2021-06-25 16:08:16 +00:00
|
|
|
// StagedLinkPreview
|
|
|
|
linkPreviewLoading,
|
|
|
|
linkPreviewResult,
|
|
|
|
// Quote
|
2022-12-09 19:11:14 +00:00
|
|
|
quotedMessageId: quotedMessage?.quote?.messageId,
|
2021-06-25 16:08:16 +00:00
|
|
|
quotedMessageProps: quotedMessage
|
2021-08-11 23:06:20 +00:00
|
|
|
? getPropsForQuote(quotedMessage, {
|
2021-06-25 16:08:16 +00:00
|
|
|
conversationSelector,
|
2021-08-11 23:06:20 +00:00
|
|
|
ourConversationId: getUserConversationId(state),
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor: getDefaultConversationColor(state),
|
2021-08-11 23:06:20 +00:00
|
|
|
})
|
2021-06-25 16:08:16 +00:00
|
|
|
: undefined,
|
2023-08-16 20:54:39 +00:00
|
|
|
quotedMessageAuthorAci: quotedMessage?.quote?.authorAci,
|
2023-04-20 16:31:59 +00:00
|
|
|
quotedMessageSentAt: quotedMessage?.quote?.id,
|
2019-06-27 20:35:21 +00:00
|
|
|
// Emojis
|
|
|
|
recentEmojis,
|
2021-09-09 16:29:01 +00:00
|
|
|
skinTone: getEmojiSkinTone(state),
|
2019-06-27 20:35:21 +00:00
|
|
|
// Stickers
|
2019-05-16 22:32:11 +00:00
|
|
|
receivedPacks,
|
2020-01-09 14:35:33 +00:00
|
|
|
installedPack,
|
2019-05-24 01:27:42 +00:00
|
|
|
blessedPacks,
|
|
|
|
knownPacks,
|
2019-05-16 22:32:11 +00:00
|
|
|
installedPacks,
|
|
|
|
recentStickers,
|
|
|
|
showIntroduction,
|
|
|
|
showPickerHint,
|
2020-05-27 21:37:06 +00:00
|
|
|
// Message Requests
|
2020-09-01 20:14:29 +00:00
|
|
|
...conversation,
|
2020-05-27 21:37:06 +00:00
|
|
|
conversationType: conversation.type,
|
2021-05-13 20:57:27 +00:00
|
|
|
isSMSOnly: Boolean(isConversationSMSOnly(conversation)),
|
2022-11-09 02:38:19 +00:00
|
|
|
isSignalConversation: isSignalConversation(conversation),
|
2021-05-13 20:57:27 +00:00
|
|
|
isFetchingUUID: conversation.isFetchingUUID,
|
2021-11-11 22:43:05 +00:00
|
|
|
isMissingMandatoryProfileSharing:
|
|
|
|
isMissingRequiredProfileSharing(conversation),
|
2021-07-20 20:18:35 +00:00
|
|
|
// Groups
|
|
|
|
announcementsOnly,
|
|
|
|
areWeAdmin,
|
|
|
|
groupAdmins: getGroupAdminsSelector(state)(conversation.id),
|
2021-09-13 02:36:41 +00:00
|
|
|
|
|
|
|
draftText: dropNull(draftText),
|
2023-09-14 17:04:48 +00:00
|
|
|
draftBodyRanges: hydrateRanges(draftBodyRanges, conversationSelector),
|
2023-03-02 20:55:40 +00:00
|
|
|
renderSmartCompositionRecording: (
|
|
|
|
recProps: SmartCompositionRecordingProps
|
|
|
|
) => {
|
|
|
|
return <SmartCompositionRecording {...recProps} />;
|
|
|
|
},
|
|
|
|
renderSmartCompositionRecordingDraft: (
|
|
|
|
draftProps: SmartCompositionRecordingDraftProps
|
|
|
|
) => {
|
|
|
|
return <SmartCompositionRecordingDraft {...draftProps} />;
|
|
|
|
},
|
2023-03-20 22:23:53 +00:00
|
|
|
|
|
|
|
// Select Mode
|
|
|
|
selectedMessageIds,
|
2019-05-16 22:32:11 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
const dispatchPropsMap = {
|
2019-05-16 22:32:11 +00:00
|
|
|
...mapDispatchToProps,
|
2019-06-27 20:35:21 +00:00
|
|
|
onSetSkinTone: (tone: number) => mapDispatchToProps.putItem('skinTone', tone),
|
2019-05-16 22:32:11 +00:00
|
|
|
clearShowIntroduction: () =>
|
|
|
|
mapDispatchToProps.removeItem('showStickersIntroduction'),
|
|
|
|
clearShowPickerHint: () =>
|
|
|
|
mapDispatchToProps.removeItem('showStickerPickerHint'),
|
2020-05-05 19:49:34 +00:00
|
|
|
onPickEmoji: mapDispatchToProps.onUseEmoji,
|
2019-06-27 20:35:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, dispatchPropsMap);
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2021-09-13 02:36:41 +00:00
|
|
|
export const SmartCompositionArea = smart(CompositionArea);
|