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

101 lines
3.9 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 type { LocalizerType } from '../../types/Util';
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,
} from '../selectors/conversations';
2022-08-02 19:31:55 +00:00
import { getDistributionLists } from '../selectors/storyDistributionLists';
2022-06-17 00:48:57 +00:00
import { getIntl } from '../selectors/user';
2022-08-04 19:23:24 +00:00
import {
getInstalledStickerPacks,
getRecentStickers,
} from '../selectors/stickers';
2022-08-23 17:24:55 +00:00
import { getHasSetMyStoriesPrivacy } from '../selectors/items';
2022-06-17 00:48:57 +00:00
import { getLinkPreview } from '../selectors/linkPreviews';
2022-08-10 18:37:19 +00:00
import { getPreferredBadgeSelector } from '../selectors/badges';
2022-08-04 19:23:24 +00:00
import { processAttachment } from '../../util/processAttachment';
2022-08-10 18:37:19 +00:00
import { useConversationsActions } from '../ducks/conversations';
2022-08-23 17:24:55 +00:00
import { useGlobalModalActions } from '../ducks/globalModals';
2022-06-17 00:48:57 +00:00
import { useLinkPreviewActions } from '../ducks/linkPreviews';
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;
};
2022-08-04 19:23:24 +00:00
export function SmartStoryCreator({
file,
onClose,
}: PropsType): JSX.Element | null {
2022-06-17 00:48:57 +00:00
const { debouncedMaybeGrabLinkPreview } = useLinkPreviewActions();
const {
sendStoryModalOpenStateChanged,
sendStoryMessage,
verifyStoryListMembers,
} = useStoriesActions();
2022-08-10 18:37:19 +00:00
const { tagGroupsAsNewGroupStory } = useConversationsActions();
2022-08-23 17:24:55 +00:00
const {
createDistributionList,
hideMyStoriesFrom,
setMyStoriesToAllSignalConnections,
updateStoryViewers,
} = useStoryDistributionListsActions();
const { toggleSignalConnectionsModal } = useGlobalModalActions();
2022-06-17 00:48:57 +00:00
2022-08-10 18:37:19 +00:00
const candidateConversations = useSelector(getCandidateContactsForNewGroup);
2022-08-02 19:31:55 +00:00
const distributionLists = useSelector(getDistributionLists);
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);
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-08-04 19:23:24 +00:00
installedPacks={installedPacks}
2022-06-17 00:48:57 +00:00
linkPreview={linkPreviewForSource(LinkPreviewSourceType.StoryCreator)}
2022-08-02 19:31:55 +00:00
me={me}
2022-06-17 00:48:57 +00:00
onClose={onClose}
2022-08-10 18:37:19 +00:00
onDistributionListCreated={createDistributionList}
2022-08-23 17:24:55 +00:00
onHideMyStoriesFrom={hideMyStoriesFrom}
onSelectedStoryList={verifyStoryListMembers}
2022-08-02 19:31:55 +00:00
onSend={sendStoryMessage}
2022-08-23 17:24:55 +00:00
onViewersUpdated={updateStoryViewers}
2022-08-04 19:23:24 +00:00
processAttachment={processAttachment}
recentStickers={recentStickers}
sendStoryModalOpenStateChanged={sendStoryModalOpenStateChanged}
2022-08-23 17:24:55 +00:00
setMyStoriesToAllSignalConnections={setMyStoriesToAllSignalConnections}
2022-08-02 19:31:55 +00:00
signalConnections={signalConnections}
2022-08-10 18:37:19 +00:00
tagGroupsAsNewGroupStory={tagGroupsAsNewGroupStory}
2022-08-23 17:24:55 +00:00
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
2022-06-17 00:48:57 +00:00
/>
);
}