2021-02-23 14:34:28 -06:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-05-16 15:32:11 -07:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { get } from 'lodash';
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { Props as ComponentPropsType } from '../../components/CompositionArea';
|
|
|
|
import { CompositionArea } from '../../components/CompositionArea';
|
|
|
|
import type { StateType } from '../reducer';
|
2021-05-13 13:57:27 -07:00
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
2021-09-12 19:36:41 -07:00
|
|
|
import { dropNull } from '../../util/dropNull';
|
2019-05-16 15:32:11 -07:00
|
|
|
|
2021-11-17 12:38:52 -06:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2021-04-27 15:35:35 -07:00
|
|
|
import { selectRecentEmojis } from '../selectors/emojis';
|
2021-11-02 18:01:13 -05:00
|
|
|
import { getIntl, getTheme, getUserConversationId } from '../selectors/user';
|
2021-09-09 11:29:01 -05:00
|
|
|
import { getEmojiSkinTone } from '../selectors/items';
|
2021-06-17 10:15:10 -07:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
2021-07-20 16:18:35 -04:00
|
|
|
getGroupAdminsSelector,
|
2021-06-17 10:15:10 -07:00
|
|
|
isMissingRequiredProfileSharing,
|
|
|
|
} from '../selectors/conversations';
|
2021-06-25 12:08:16 -04:00
|
|
|
import { getPropsForQuote } from '../selectors/message';
|
2019-05-16 15:32:11 -07:00
|
|
|
import {
|
2019-05-23 18:27:42 -07:00
|
|
|
getBlessedStickerPacks,
|
2019-05-16 15:32:11 -07:00
|
|
|
getInstalledStickerPacks,
|
2019-05-23 18:27:42 -07:00
|
|
|
getKnownStickerPacks,
|
2019-05-16 15:32:11 -07:00
|
|
|
getReceivedStickerPacks,
|
2020-01-09 06:35:33 -08:00
|
|
|
getRecentlyInstalledStickerPack,
|
2019-05-16 15:32:11 -07:00
|
|
|
getRecentStickers,
|
|
|
|
} from '../selectors/stickers';
|
|
|
|
|
2019-08-06 17:40:25 -07:00
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
2021-10-05 12:47:06 -04:00
|
|
|
handleClickQuotedMessage: (id: string) => unknown;
|
2019-08-06 17:40:25 -07:00
|
|
|
};
|
|
|
|
|
2021-10-05 12:47:06 -04:00
|
|
|
export type CompositionAreaPropsType = ExternalProps & ComponentPropsType;
|
|
|
|
|
2019-08-06 17:40:25 -07:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
2021-10-05 12:47:06 -04:00
|
|
|
const { id, handleClickQuotedMessage } = props;
|
2019-08-06 17:40:25 -07:00
|
|
|
|
2021-06-25 12:08:16 -04:00
|
|
|
const conversationSelector = getConversationSelector(state);
|
|
|
|
const conversation = conversationSelector(id);
|
2019-08-06 17:40:25 -07:00
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(`Conversation id ${id} not found!`);
|
|
|
|
}
|
|
|
|
|
2021-11-11 16:43:05 -06:00
|
|
|
const { announcementsOnly, areWeAdmin, draftText, draftBodyRanges } =
|
|
|
|
conversation;
|
2019-08-06 17:40:25 -07:00
|
|
|
|
2019-05-16 15:32:11 -07:00
|
|
|
const receivedPacks = getReceivedStickerPacks(state);
|
|
|
|
const installedPacks = getInstalledStickerPacks(state);
|
2019-05-23 18:27:42 -07:00
|
|
|
const blessedPacks = getBlessedStickerPacks(state);
|
|
|
|
const knownPacks = getKnownStickerPacks(state);
|
|
|
|
|
2020-01-09 06:35:33 -08:00
|
|
|
const installedPack = getRecentlyInstalledStickerPack(state);
|
|
|
|
|
2019-05-16 15:32:11 -07:00
|
|
|
const recentStickers = getRecentStickers(state);
|
|
|
|
const showIntroduction = get(
|
|
|
|
state.items,
|
2019-05-29 15:48:43 -07:00
|
|
|
['showStickersIntroduction'],
|
2019-05-16 15:32:11 -07:00
|
|
|
false
|
|
|
|
);
|
2021-09-12 19:36:41 -07:00
|
|
|
const showPickerHint = Boolean(
|
2019-05-29 15:48:43 -07:00
|
|
|
get(state.items, ['showStickerPickerHint'], false) &&
|
2021-09-12 19:36:41 -07:00
|
|
|
receivedPacks.length > 0
|
|
|
|
);
|
2019-05-16 15:32:11 -07:00
|
|
|
|
2021-06-25 12:08:16 -04:00
|
|
|
const {
|
|
|
|
attachments: draftAttachments,
|
|
|
|
linkPreviewLoading,
|
|
|
|
linkPreviewResult,
|
|
|
|
quotedMessage,
|
|
|
|
shouldSendHighQualityAttachments,
|
|
|
|
} = state.composer;
|
|
|
|
|
2019-06-27 16:35:21 -04:00
|
|
|
const recentEmojis = selectRecentEmojis(state);
|
|
|
|
|
2019-05-16 15:32:11 -07:00
|
|
|
return {
|
2019-06-27 16:35:21 -04:00
|
|
|
// Base
|
2021-09-24 16:02:30 -04:00
|
|
|
conversationId: id,
|
2019-06-27 16:35:21 -04:00
|
|
|
i18n: getIntl(state),
|
2021-11-02 18:01:13 -05:00
|
|
|
theme: getTheme(state),
|
2021-11-17 12:38:52 -06:00
|
|
|
getPreferredBadge: getPreferredBadgeSelector(state),
|
2021-09-29 16:23:06 -04:00
|
|
|
// AudioCapture
|
|
|
|
errorDialogAudioRecorderType:
|
|
|
|
state.audioRecorder.errorDialogAudioRecorderType,
|
2021-11-11 15:33:35 -08:00
|
|
|
recordingState: state.audioRecorder.recordingState,
|
2021-06-25 12:08:16 -04:00
|
|
|
// AttachmentsList
|
|
|
|
draftAttachments,
|
|
|
|
// MediaQualitySelector
|
|
|
|
shouldSendHighQualityAttachments,
|
|
|
|
// StagedLinkPreview
|
|
|
|
linkPreviewLoading,
|
|
|
|
linkPreviewResult,
|
|
|
|
// Quote
|
|
|
|
quotedMessageProps: quotedMessage
|
2021-08-11 16:06:20 -07:00
|
|
|
? getPropsForQuote(quotedMessage, {
|
2021-06-25 12:08:16 -04:00
|
|
|
conversationSelector,
|
2021-08-11 16:06:20 -07:00
|
|
|
ourConversationId: getUserConversationId(state),
|
|
|
|
})
|
2021-06-25 12:08:16 -04:00
|
|
|
: undefined,
|
2021-08-30 14:32:56 -07:00
|
|
|
onClickQuotedMessage: () => {
|
|
|
|
const messageId = quotedMessage?.quote?.messageId;
|
|
|
|
if (messageId) {
|
2021-10-05 12:47:06 -04:00
|
|
|
handleClickQuotedMessage(messageId);
|
2021-08-30 14:32:56 -07:00
|
|
|
}
|
|
|
|
},
|
2019-06-27 16:35:21 -04:00
|
|
|
// Emojis
|
|
|
|
recentEmojis,
|
2021-09-09 11:29:01 -05:00
|
|
|
skinTone: getEmojiSkinTone(state),
|
2019-06-27 16:35:21 -04:00
|
|
|
// Stickers
|
2019-05-16 15:32:11 -07:00
|
|
|
receivedPacks,
|
2020-01-09 06:35:33 -08:00
|
|
|
installedPack,
|
2019-05-23 18:27:42 -07:00
|
|
|
blessedPacks,
|
|
|
|
knownPacks,
|
2019-05-16 15:32:11 -07:00
|
|
|
installedPacks,
|
|
|
|
recentStickers,
|
|
|
|
showIntroduction,
|
|
|
|
showPickerHint,
|
2020-05-27 17:37:06 -04:00
|
|
|
// Message Requests
|
2020-09-01 13:14:29 -07:00
|
|
|
...conversation,
|
2020-05-27 17:37:06 -04:00
|
|
|
conversationType: conversation.type,
|
2021-05-13 13:57:27 -07:00
|
|
|
isSMSOnly: Boolean(isConversationSMSOnly(conversation)),
|
|
|
|
isFetchingUUID: conversation.isFetchingUUID,
|
2021-11-11 16:43:05 -06:00
|
|
|
isMissingMandatoryProfileSharing:
|
|
|
|
isMissingRequiredProfileSharing(conversation),
|
2021-07-20 16:18:35 -04:00
|
|
|
// Groups
|
|
|
|
announcementsOnly,
|
|
|
|
areWeAdmin,
|
|
|
|
groupAdmins: getGroupAdminsSelector(state)(conversation.id),
|
2021-09-12 19:36:41 -07:00
|
|
|
|
|
|
|
draftText: dropNull(draftText),
|
|
|
|
draftBodyRanges,
|
2019-05-16 15:32:11 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-06-27 16:35:21 -04:00
|
|
|
const dispatchPropsMap = {
|
2019-05-16 15:32:11 -07:00
|
|
|
...mapDispatchToProps,
|
2019-06-27 16:35:21 -04:00
|
|
|
onSetSkinTone: (tone: number) => mapDispatchToProps.putItem('skinTone', tone),
|
2019-05-16 15:32:11 -07:00
|
|
|
clearShowIntroduction: () =>
|
|
|
|
mapDispatchToProps.removeItem('showStickersIntroduction'),
|
|
|
|
clearShowPickerHint: () =>
|
|
|
|
mapDispatchToProps.removeItem('showStickerPickerHint'),
|
2020-05-05 15:49:34 -04:00
|
|
|
onPickEmoji: mapDispatchToProps.onUseEmoji,
|
2019-06-27 16:35:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, dispatchPropsMap);
|
2019-05-16 15:32:11 -07:00
|
|
|
|
2021-09-12 19:36:41 -07:00
|
|
|
export const SmartCompositionArea = smart(CompositionArea);
|