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';
|
|
|
|
|
2023-08-10 22:16:51 +00:00
|
|
|
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,
|
2022-11-08 20:01:59 +00:00
|
|
|
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';
|
2022-11-28 18:52:16 +00:00
|
|
|
import { getAddStoryData } from '../selectors/stories';
|
2023-09-14 17:04:48 +00:00
|
|
|
import {
|
|
|
|
getIsFormattingFlagEnabled,
|
|
|
|
getIsFormattingSpoilersFlagEnabled,
|
|
|
|
} from '../selectors/composer';
|
|
|
|
import { getLinkPreview } from '../selectors/linkPreviews';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2022-11-28 18:52:16 +00:00
|
|
|
import {
|
|
|
|
getEmojiSkinTone,
|
|
|
|
getHasSetMyStoriesPrivacy,
|
2023-09-14 17:04:48 +00:00
|
|
|
getTextFormattingEnabled,
|
2022-11-28 18:52:16 +00:00
|
|
|
} from '../selectors/items';
|
2022-11-16 21:41:38 +00:00
|
|
|
import { imageToBlurHash } from '../../util/imageToBlurHash';
|
2022-11-28 18:52:16 +00:00
|
|
|
import { processAttachment } from '../../util/processAttachment';
|
|
|
|
import { useActions as 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';
|
2022-11-28 18:52:16 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
export function SmartStoryCreator(): JSX.Element | null {
|
2022-06-17 00:48:57 +00:00
|
|
|
const { debouncedMaybeGrabLinkPreview } = useLinkPreviewActions();
|
2022-08-19 18:05:31 +00:00
|
|
|
const {
|
|
|
|
sendStoryModalOpenStateChanged,
|
|
|
|
sendStoryMessage,
|
|
|
|
verifyStoryListMembers,
|
2022-11-02 00:36:16 +00:00
|
|
|
setAddStoryData,
|
2022-08-19 18:05:31 +00:00
|
|
|
} = 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,
|
2022-11-11 04:10:30 +00:00
|
|
|
removeMembersFromDistributionList,
|
2022-08-23 17:24:55 +00:00
|
|
|
setMyStoriesToAllSignalConnections,
|
|
|
|
updateStoryViewers,
|
|
|
|
} = useStoryDistributionListsActions();
|
|
|
|
const { toggleSignalConnectionsModal } = useGlobalModalActions();
|
2022-06-17 00:48:57 +00:00
|
|
|
|
2022-11-11 04:10:30 +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);
|
2022-11-08 20:01:59 +00:00
|
|
|
const mostRecentActiveStoryTimestampByGroupOrDistributionList = useSelector(
|
|
|
|
selectMostRecentActiveStoryTimestampByGroupOrDistributionList
|
|
|
|
);
|
2022-06-17 00:48:57 +00:00
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
const addStoryData = useSelector(getAddStoryData);
|
2023-05-10 19:58:35 +00:00
|
|
|
let file: File | undefined;
|
2022-11-02 00:36:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-28 18:52:16 +00:00
|
|
|
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 isFormattingFlagEnabled = useSelector(getIsFormattingFlagEnabled);
|
|
|
|
const isFormattingSpoilersFlagEnabled = useSelector(
|
|
|
|
getIsFormattingSpoilersFlagEnabled
|
|
|
|
);
|
|
|
|
const platform = useSelector(getPlatform);
|
2022-11-28 18:52:16 +00:00
|
|
|
|
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}
|
|
|
|
isFormattingFlagEnabled={isFormattingFlagEnabled}
|
|
|
|
isFormattingSpoilersFlagEnabled={isFormattingSpoilersFlagEnabled}
|
2022-11-02 00:36:16 +00:00
|
|
|
isSending={isSending}
|
2022-06-17 00:48:57 +00:00
|
|
|
linkPreview={linkPreviewForSource(LinkPreviewSourceType.StoryCreator)}
|
2022-08-02 19:31:55 +00:00
|
|
|
me={me}
|
2022-11-28 18:52:16 +00:00
|
|
|
mostRecentActiveStoryTimestampByGroupOrDistributionList={
|
|
|
|
mostRecentActiveStoryTimestampByGroupOrDistributionList
|
|
|
|
}
|
2022-11-02 00:36:16 +00:00
|
|
|
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}
|
2022-11-11 04:10:30 +00:00
|
|
|
onRemoveMembers={removeMembersFromDistributionList}
|
2022-08-30 19:13:32 +00:00
|
|
|
onRepliesNReactionsChanged={allowsRepliesChanged}
|
2022-08-19 18:05:31 +00:00
|
|
|
onSelectedStoryList={verifyStoryListMembers}
|
2022-08-02 19:31:55 +00:00
|
|
|
onSend={sendStoryMessage}
|
2022-11-28 18:52:16 +00:00
|
|
|
onSetSkinTone={onSetSkinTone}
|
2023-09-14 17:04:48 +00:00
|
|
|
onTextTooLong={onTextTooLong}
|
2022-11-28 18:52:16 +00:00
|
|
|
onUseEmoji={onUseEmoji}
|
2022-08-23 17:24:55 +00:00
|
|
|
onViewersUpdated={updateStoryViewers}
|
2022-11-28 18:52:16 +00:00
|
|
|
ourConversationId={ourConversationId}
|
2023-09-14 17:04:48 +00:00
|
|
|
platform={platform}
|
2022-08-04 19:23:24 +00:00
|
|
|
processAttachment={processAttachment}
|
2022-11-28 18:52:16 +00:00
|
|
|
recentEmojis={recentEmojis}
|
2022-08-04 19:23:24 +00:00
|
|
|
recentStickers={recentStickers}
|
2022-08-19 18:05:31 +00:00
|
|
|
sendStoryModalOpenStateChanged={sendStoryModalOpenStateChanged}
|
2022-08-23 17:24:55 +00:00
|
|
|
setMyStoriesToAllSignalConnections={setMyStoriesToAllSignalConnections}
|
2022-08-02 19:31:55 +00:00
|
|
|
signalConnections={signalConnections}
|
2022-11-28 18:52:16 +00:00
|
|
|
skinTone={skinTone}
|
2023-08-10 22:16:51 +00:00
|
|
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|