2021-02-23 20:34:28 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-06-27 20:35:21 +00:00
|
|
|
import { createSelector } from 'reselect';
|
2019-05-16 22:32:11 +00:00
|
|
|
import { get } from 'lodash';
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
2019-06-27 20:35:21 +00:00
|
|
|
import { CompositionArea } from '../../components/CompositionArea';
|
2019-05-16 22:32:11 +00:00
|
|
|
import { StateType } from '../reducer';
|
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
import { isShortName } from '../../components/emoji/lib';
|
2019-05-16 22:32:11 +00:00
|
|
|
import { getIntl } from '../selectors/user';
|
2021-03-04 18:06:49 +00:00
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
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';
|
|
|
|
|
2019-08-07 00:40:25 +00:00
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
const selectRecentEmojis = createSelector(
|
|
|
|
({ emojis }: StateType) => emojis.recents,
|
|
|
|
recents => recents.filter(isShortName)
|
|
|
|
);
|
|
|
|
|
2019-08-07 00:40:25 +00:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
|
|
|
const { id } = props;
|
|
|
|
|
|
|
|
const conversation = getConversationSelector(state)(id);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(`Conversation id ${id} not found!`);
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:19:52 +00:00
|
|
|
const { 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
|
|
|
|
);
|
|
|
|
const showPickerHint =
|
2019-05-29 22:48:43 +00:00
|
|
|
get(state.items, ['showStickerPickerHint'], false) &&
|
2019-05-16 22:32:11 +00:00
|
|
|
receivedPacks.length > 0;
|
|
|
|
|
2019-06-27 20:35:21 +00:00
|
|
|
const recentEmojis = selectRecentEmojis(state);
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
return {
|
2019-06-27 20:35:21 +00:00
|
|
|
// Base
|
|
|
|
i18n: getIntl(state),
|
2020-11-03 01:19:52 +00:00
|
|
|
draftText,
|
|
|
|
draftBodyRanges,
|
2019-06-27 20:35:21 +00:00
|
|
|
// Emojis
|
|
|
|
recentEmojis,
|
|
|
|
skinTone: get(state, ['items', 'skinTone'], 0),
|
|
|
|
// 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-03-04 18:06:49 +00:00
|
|
|
isMissingMandatoryProfileSharing: Boolean(
|
2021-02-23 20:34:28 +00:00
|
|
|
!conversation.profileSharing &&
|
2021-03-04 18:06:49 +00:00
|
|
|
window.Signal.RemoteConfig.isEnabled(
|
|
|
|
'desktop.mandatoryProfileSharing'
|
|
|
|
) &&
|
|
|
|
conversation.messageCount &&
|
|
|
|
conversation.messageCount > 0
|
|
|
|
),
|
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
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export const SmartCompositionArea = smart(CompositionArea as any);
|