signal-desktop/ts/state/smart/StoryCreator.tsx

159 lines
6.3 KiB
TypeScript
Raw Normal View History

2022-06-17 00:48:57 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { useSelector } from 'react-redux';
import { ThemeType, type LocalizerType } from '../../types/Util';
2022-06-17 00:48:57 +00:00
import type { StateType } from '../reducer';
import { LinkPreviewSourceType } from '../../types/LinkPreview';
import { StoryCreator } from '../../components/StoryCreator';
2022-08-10 18:37:19 +00:00
import {
getAllSignalConnections,
getCandidateContactsForNewGroup,
getGroupStories,
getMe,
getNonGroupStories,
selectMostRecentActiveStoryTimestampByGroupOrDistributionList,
2022-08-10 18:37:19 +00:00
} from '../selectors/conversations';
2022-08-30 19:13:32 +00:00
import { getDistributionListsWithMembers } from '../selectors/storyDistributionLists';
2023-09-14 17:04:48 +00:00
import { getIntl, getPlatform, getUserConversationId } from '../selectors/user';
2022-08-04 19:23:24 +00:00
import {
getInstalledStickerPacks,
getRecentStickers,
} from '../selectors/stickers';
import { getAddStoryData } from '../selectors/stories';
2023-09-14 17:04:48 +00:00
import { getLinkPreview } from '../selectors/linkPreviews';
import { getPreferredBadgeSelector } from '../selectors/badges';
import {
getEmojiSkinTone,
getHasSetMyStoriesPrivacy,
2023-09-14 17:04:48 +00:00
getTextFormattingEnabled,
} from '../selectors/items';
2022-11-16 21:41:38 +00:00
import { imageToBlurHash } from '../../util/imageToBlurHash';
import { processAttachment } from '../../util/processAttachment';
2024-03-12 16:29:31 +00:00
import { useEmojisActions } from '../ducks/emojis';
2023-09-14 17:04:48 +00:00
import { useAudioPlayerActions } from '../ducks/audioPlayer';
import { useComposerActions } from '../ducks/composer';
import { useConversationsActions } from '../ducks/conversations';
2022-08-23 17:24:55 +00:00
import { useGlobalModalActions } from '../ducks/globalModals';
2023-08-09 00:53:06 +00:00
import { useItemsActions } from '../ducks/items';
2022-06-17 00:48:57 +00:00
import { useLinkPreviewActions } from '../ducks/linkPreviews';
import { useRecentEmojis } from '../selectors/emojis';
2022-08-02 19:31:55 +00:00
import { useStoriesActions } from '../ducks/stories';
2022-08-10 18:37:19 +00:00
import { useStoryDistributionListsActions } from '../ducks/storyDistributionLists';
2022-06-17 00:48:57 +00:00
export type PropsType = {
2022-08-04 19:23:24 +00:00
file?: File;
2022-06-17 00:48:57 +00:00
onClose: () => unknown;
};
export function SmartStoryCreator(): JSX.Element | null {
2022-06-17 00:48:57 +00:00
const { debouncedMaybeGrabLinkPreview } = useLinkPreviewActions();
const {
sendStoryModalOpenStateChanged,
sendStoryMessage,
verifyStoryListMembers,
setAddStoryData,
} = useStoriesActions();
2022-08-30 19:13:32 +00:00
const { toggleGroupsForStorySend } = useConversationsActions();
2022-08-23 17:24:55 +00:00
const {
2022-08-30 19:13:32 +00:00
allowsRepliesChanged,
2022-08-23 17:24:55 +00:00
createDistributionList,
2022-08-30 19:13:32 +00:00
deleteDistributionList,
2022-08-23 17:24:55 +00:00
hideMyStoriesFrom,
removeMembersFromDistributionList,
2022-08-23 17:24:55 +00:00
setMyStoriesToAllSignalConnections,
updateStoryViewers,
} = useStoryDistributionListsActions();
const { toggleSignalConnectionsModal } = useGlobalModalActions();
2022-06-17 00:48:57 +00:00
const ourConversationId = useSelector(getUserConversationId);
2022-08-10 18:37:19 +00:00
const candidateConversations = useSelector(getCandidateContactsForNewGroup);
2022-08-30 19:13:32 +00:00
const distributionLists = useSelector(getDistributionListsWithMembers);
2022-08-10 18:37:19 +00:00
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const groupConversations = useSelector(getNonGroupStories);
const groupStories = useSelector(getGroupStories);
2022-08-23 17:24:55 +00:00
const hasSetMyStoriesPrivacy = useSelector(getHasSetMyStoriesPrivacy);
2022-08-10 18:37:19 +00:00
const i18n = useSelector<StateType, LocalizerType>(getIntl);
2022-08-04 19:23:24 +00:00
const installedPacks = useSelector(getInstalledStickerPacks);
const linkPreviewForSource = useSelector(getLinkPreview);
2022-08-02 19:31:55 +00:00
const me = useSelector(getMe);
2022-08-04 19:23:24 +00:00
const recentStickers = useSelector(getRecentStickers);
2022-08-02 19:31:55 +00:00
const signalConnections = useSelector(getAllSignalConnections);
const mostRecentActiveStoryTimestampByGroupOrDistributionList = useSelector(
selectMostRecentActiveStoryTimestampByGroupOrDistributionList
);
2022-06-17 00:48:57 +00:00
const addStoryData = useSelector(getAddStoryData);
2023-05-10 19:58:35 +00:00
let file: File | undefined;
const isSending = addStoryData?.sending || false;
2023-05-10 19:58:35 +00:00
if (addStoryData?.type === 'Media') {
// Note that the source type is ReadonlyDeep<File>, but browser APIs don't
// support that. Hence the cast.
file = addStoryData.file as File;
}
const recentEmojis = useRecentEmojis();
const skinTone = useSelector<StateType, number>(getEmojiSkinTone);
const { onSetSkinTone } = useItemsActions();
const { onUseEmoji } = useEmojisActions();
2023-02-24 23:18:57 +00:00
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
2023-09-14 17:04:48 +00:00
const { onTextTooLong } = useComposerActions();
const { onUseEmoji: onPickEmoji } = useEmojisActions();
const isFormattingEnabled = useSelector(getTextFormattingEnabled);
const platform = useSelector(getPlatform);
2022-06-17 00:48:57 +00:00
return (
<StoryCreator
2022-08-10 18:37:19 +00:00
candidateConversations={candidateConversations}
2022-06-17 00:48:57 +00:00
debouncedMaybeGrabLinkPreview={debouncedMaybeGrabLinkPreview}
2022-08-02 19:31:55 +00:00
distributionLists={distributionLists}
2022-08-10 18:37:19 +00:00
file={file}
getPreferredBadge={getPreferredBadge}
groupConversations={groupConversations}
groupStories={groupStories}
2022-08-23 17:24:55 +00:00
hasFirstStoryPostExperience={!hasSetMyStoriesPrivacy}
2022-06-17 00:48:57 +00:00
i18n={i18n}
2022-11-16 21:41:38 +00:00
imageToBlurHash={imageToBlurHash}
2022-08-04 19:23:24 +00:00
installedPacks={installedPacks}
2023-09-14 17:04:48 +00:00
isFormattingEnabled={isFormattingEnabled}
isSending={isSending}
2022-06-17 00:48:57 +00:00
linkPreview={linkPreviewForSource(LinkPreviewSourceType.StoryCreator)}
2022-08-02 19:31:55 +00:00
me={me}
mostRecentActiveStoryTimestampByGroupOrDistributionList={
mostRecentActiveStoryTimestampByGroupOrDistributionList
}
onClose={() => setAddStoryData(undefined)}
2022-08-30 19:13:32 +00:00
onDeleteList={deleteDistributionList}
2022-08-10 18:37:19 +00:00
onDistributionListCreated={createDistributionList}
2022-08-23 17:24:55 +00:00
onHideMyStoriesFrom={hideMyStoriesFrom}
2023-09-14 17:04:48 +00:00
onMediaPlaybackStart={pauseVoiceNotePlayer}
onPickEmoji={onPickEmoji}
onRemoveMembers={removeMembersFromDistributionList}
2022-08-30 19:13:32 +00:00
onRepliesNReactionsChanged={allowsRepliesChanged}
onSelectedStoryList={verifyStoryListMembers}
2022-08-02 19:31:55 +00:00
onSend={sendStoryMessage}
onSetSkinTone={onSetSkinTone}
2023-09-14 17:04:48 +00:00
onTextTooLong={onTextTooLong}
onUseEmoji={onUseEmoji}
2022-08-23 17:24:55 +00:00
onViewersUpdated={updateStoryViewers}
ourConversationId={ourConversationId}
2023-09-14 17:04:48 +00:00
platform={platform}
2022-08-04 19:23:24 +00:00
processAttachment={processAttachment}
recentEmojis={recentEmojis}
2022-08-04 19:23:24 +00:00
recentStickers={recentStickers}
sendStoryModalOpenStateChanged={sendStoryModalOpenStateChanged}
2022-08-23 17:24:55 +00:00
setMyStoriesToAllSignalConnections={setMyStoriesToAllSignalConnections}
2022-08-02 19:31:55 +00:00
signalConnections={signalConnections}
2024-03-12 16:29:31 +00:00
sortedGroupMembers={null}
skinTone={skinTone}
theme={ThemeType.dark}
2022-08-30 19:13:32 +00:00
toggleGroupsForStorySend={toggleGroupsForStorySend}
2022-08-23 17:24:55 +00:00
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
2022-06-17 00:48:57 +00:00
/>
);
}