2022-03-04 16:14:52 -05:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
2022-07-06 15:06:20 -04:00
|
|
|
import type { GetConversationByIdType } from '../selectors/conversations';
|
2022-03-04 16:14:52 -05:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { StateType } from '../reducer';
|
2022-07-06 15:06:20 -04:00
|
|
|
import type { SelectedStoryDataType } from '../ducks/stories';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { StoryViewer } from '../../components/StoryViewer';
|
2022-12-14 16:48:36 -08:00
|
|
|
import { ToastType } from '../../types/Toast';
|
|
|
|
import { useToastActions } from '../ducks/toast';
|
2022-07-06 15:06:20 -04:00
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
2022-03-04 16:14:52 -05:00
|
|
|
import {
|
|
|
|
getEmojiSkinTone,
|
2022-10-25 15:18:42 -07:00
|
|
|
getHasStoryViewReceiptSetting,
|
2022-03-04 16:14:52 -05:00
|
|
|
getPreferredReactionEmoji,
|
2023-04-17 18:16:41 -07:00
|
|
|
getTextFormattingEnabled,
|
2022-11-22 14:33:15 -08:00
|
|
|
isInternalUser,
|
2022-03-04 16:14:52 -05:00
|
|
|
} from '../selectors/items';
|
2023-04-03 13:16:27 -07:00
|
|
|
import { getIntl, getPlatform } from '../selectors/user';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2022-07-06 15:06:20 -04:00
|
|
|
import {
|
|
|
|
getSelectedStoryData,
|
|
|
|
getStoryReplies,
|
2022-07-29 16:22:55 -04:00
|
|
|
getStoryByIdSelector,
|
2022-11-09 20:24:42 -08:00
|
|
|
getHasAllStoriesUnmuted,
|
2022-07-06 15:06:20 -04:00
|
|
|
} from '../selectors/stories';
|
2022-08-04 21:07:46 -04:00
|
|
|
import { isInFullScreenCall } from '../selectors/calling';
|
2022-11-08 21:38:19 -05:00
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { renderEmojiPicker } from './renderEmojiPicker';
|
2022-07-06 15:06:20 -04:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2022-11-22 14:33:15 -08:00
|
|
|
import { asyncShouldNeverBeCalled } from '../../util/shouldNeverBeCalled';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { useActions as useEmojisActions } from '../ducks/emojis';
|
2022-04-29 13:43:24 -04:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { useRecentEmojis } from '../selectors/emojis';
|
2023-08-08 17:53:06 -07:00
|
|
|
import { useItemsActions } from '../ducks/items';
|
2023-02-24 16:18:57 -07:00
|
|
|
import { useAudioPlayerActions } from '../ducks/audioPlayer';
|
2023-03-07 17:59:44 -05:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2022-03-04 16:14:52 -05:00
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
2022-11-09 20:24:42 -08:00
|
|
|
import { useIsWindowActive } from '../../hooks/useIsWindowActive';
|
2023-04-14 11:16:28 -07:00
|
|
|
import {
|
2023-04-17 18:16:41 -07:00
|
|
|
getIsFormattingFlagEnabled,
|
|
|
|
getIsFormattingSpoilersFlagEnabled,
|
2023-04-14 11:16:28 -07:00
|
|
|
} from '../selectors/composer';
|
2022-03-04 16:14:52 -05:00
|
|
|
|
2022-07-06 15:06:20 -04:00
|
|
|
export function SmartStoryViewer(): JSX.Element | null {
|
2022-03-04 16:14:52 -05:00
|
|
|
const storiesActions = useStoriesActions();
|
|
|
|
const { onUseEmoji } = useEmojisActions();
|
2022-12-19 17:04:47 -08:00
|
|
|
const {
|
|
|
|
retryMessageSend,
|
|
|
|
saveAttachment,
|
|
|
|
showConversation,
|
|
|
|
toggleHideStories,
|
|
|
|
} = useConversationsActions();
|
2022-11-09 20:24:42 -08:00
|
|
|
const { onSetSkinTone } = useItemsActions();
|
2022-07-12 12:41:41 -04:00
|
|
|
const { showToast } = useToastActions();
|
2023-03-07 17:59:44 -05:00
|
|
|
const { showContactModal } = useGlobalModalActions();
|
2022-03-04 16:14:52 -05:00
|
|
|
|
2022-11-09 20:24:42 -08:00
|
|
|
const isWindowActive = useIsWindowActive();
|
|
|
|
|
2022-03-04 16:14:52 -05:00
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
2023-04-03 13:16:27 -07:00
|
|
|
const platform = useSelector(getPlatform);
|
2022-03-04 16:14:52 -05:00
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
2022-12-21 16:07:02 -08:00
|
|
|
const preferredReactionEmoji = useSelector<StateType, ReadonlyArray<string>>(
|
2022-03-04 16:14:52 -05:00
|
|
|
getPreferredReactionEmoji
|
|
|
|
);
|
|
|
|
|
2022-07-06 15:06:20 -04:00
|
|
|
const selectedStoryData = useSelector<
|
2022-04-14 20:08:46 -04:00
|
|
|
StateType,
|
2022-07-06 15:06:20 -04:00
|
|
|
SelectedStoryDataType | undefined
|
|
|
|
>(getSelectedStoryData);
|
2022-04-14 20:08:46 -04:00
|
|
|
|
2022-11-22 14:33:15 -08:00
|
|
|
const internalUser = useSelector<StateType, boolean>(isInternalUser);
|
|
|
|
|
2022-07-06 15:06:20 -04:00
|
|
|
strictAssert(selectedStoryData, 'StoryViewer: !selectedStoryData');
|
|
|
|
|
|
|
|
const conversationSelector = useSelector<StateType, GetConversationByIdType>(
|
|
|
|
getConversationSelector
|
|
|
|
);
|
|
|
|
|
2022-07-29 16:22:55 -04:00
|
|
|
const getStoryById = useSelector(getStoryByIdSelector);
|
|
|
|
|
2022-03-04 16:14:52 -05:00
|
|
|
const recentEmojis = useRecentEmojis();
|
|
|
|
const skinTone = useSelector<StateType, number>(getEmojiSkinTone);
|
2022-04-14 20:08:46 -04:00
|
|
|
const replyState = useSelector(getStoryReplies);
|
2022-11-09 20:24:42 -08:00
|
|
|
const hasAllStoriesUnmuted = useSelector<StateType, boolean>(
|
|
|
|
getHasAllStoriesUnmuted
|
2022-05-06 15:02:44 -04:00
|
|
|
);
|
2022-03-04 16:14:52 -05:00
|
|
|
|
2022-08-04 21:07:46 -04:00
|
|
|
const hasActiveCall = useSelector(isInFullScreenCall);
|
2022-10-25 15:18:42 -07:00
|
|
|
const hasViewReceiptSetting = useSelector<StateType, boolean>(
|
|
|
|
getHasStoryViewReceiptSetting
|
2022-08-31 12:11:14 -04:00
|
|
|
);
|
2022-08-04 21:07:46 -04:00
|
|
|
|
2023-05-09 17:40:19 -07:00
|
|
|
const isFormattingEnabled = useSelector(getTextFormattingEnabled);
|
|
|
|
const isFormattingFlagEnabled = useSelector(getIsFormattingFlagEnabled);
|
|
|
|
const isFormattingSpoilersFlagEnabled = useSelector(
|
|
|
|
getIsFormattingSpoilersFlagEnabled
|
|
|
|
);
|
2023-04-14 11:16:28 -07:00
|
|
|
|
2023-02-24 16:18:57 -07:00
|
|
|
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
|
|
|
|
|
2022-10-24 13:45:51 -04:00
|
|
|
const storyInfo = getStoryById(
|
|
|
|
conversationSelector,
|
|
|
|
selectedStoryData.messageId
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!storyInfo) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { conversationStory, distributionList, storyView } = storyInfo;
|
|
|
|
|
2022-03-04 16:14:52 -05:00
|
|
|
return (
|
|
|
|
<StoryViewer
|
2022-07-06 15:06:20 -04:00
|
|
|
currentIndex={selectedStoryData.currentIndex}
|
2022-10-03 18:22:01 -04:00
|
|
|
distributionList={distributionList}
|
2022-03-04 16:14:52 -05:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2022-07-06 15:06:20 -04:00
|
|
|
group={conversationStory.group}
|
2022-08-04 21:07:46 -04:00
|
|
|
hasActiveCall={hasActiveCall}
|
2022-11-09 20:24:42 -08:00
|
|
|
hasAllStoriesUnmuted={hasAllStoriesUnmuted}
|
2022-10-25 15:18:42 -07:00
|
|
|
hasViewReceiptSetting={hasViewReceiptSetting}
|
2022-03-04 16:14:52 -05:00
|
|
|
i18n={i18n}
|
2023-04-03 13:16:27 -07:00
|
|
|
platform={platform}
|
2022-11-22 14:33:15 -08:00
|
|
|
isInternalUser={internalUser}
|
2023-04-14 11:16:28 -07:00
|
|
|
isFormattingEnabled={isFormattingEnabled}
|
2023-05-09 17:40:19 -07:00
|
|
|
isFormattingFlagEnabled={isFormattingFlagEnabled}
|
|
|
|
isFormattingSpoilersFlagEnabled={isFormattingSpoilersFlagEnabled}
|
2022-11-08 21:38:19 -05:00
|
|
|
isSignalConversation={isSignalConversation({
|
|
|
|
id: conversationStory.conversationId,
|
|
|
|
})}
|
2022-11-16 17:10:11 -05:00
|
|
|
isWindowActive={isWindowActive}
|
2022-07-06 15:06:20 -04:00
|
|
|
numStories={selectedStoryData.numStories}
|
2022-04-29 13:43:24 -04:00
|
|
|
onHideStory={toggleHideStories}
|
|
|
|
onGoToConversation={senderId => {
|
2022-06-16 15:12:50 -04:00
|
|
|
showConversation({ conversationId: senderId });
|
2022-04-29 13:43:24 -04:00
|
|
|
}}
|
2022-03-04 16:14:52 -05:00
|
|
|
onReactToStory={async (emoji, story) => {
|
2022-04-28 18:06:28 -04:00
|
|
|
const { messageId } = story;
|
|
|
|
storiesActions.reactToStory(emoji, messageId);
|
2022-03-04 16:14:52 -05:00
|
|
|
}}
|
|
|
|
onReplyToStory={(message, mentions, timestamp, story) => {
|
|
|
|
storiesActions.replyToStory(
|
2022-07-06 15:06:20 -04:00
|
|
|
conversationStory.conversationId,
|
2022-03-04 16:14:52 -05:00
|
|
|
message,
|
|
|
|
mentions,
|
|
|
|
timestamp,
|
|
|
|
story
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
onSetSkinTone={onSetSkinTone}
|
2023-04-10 14:38:34 -07:00
|
|
|
onTextTooLong={() => {
|
|
|
|
showToast({ toastType: ToastType.MessageBodyTooLong });
|
|
|
|
}}
|
2022-03-04 16:14:52 -05:00
|
|
|
onUseEmoji={onUseEmoji}
|
2023-02-24 16:18:57 -07:00
|
|
|
onMediaPlaybackStart={pauseVoiceNotePlayer}
|
2022-03-04 16:14:52 -05:00
|
|
|
preferredReactionEmoji={preferredReactionEmoji}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
renderEmojiPicker={renderEmojiPicker}
|
2022-04-14 20:08:46 -04:00
|
|
|
replyState={replyState}
|
2022-12-19 17:04:47 -08:00
|
|
|
retryMessageSend={retryMessageSend}
|
2023-04-14 11:16:28 -07:00
|
|
|
saveAttachment={internalUser ? saveAttachment : asyncShouldNeverBeCalled}
|
2023-03-07 17:59:44 -05:00
|
|
|
showContactModal={showContactModal}
|
2022-07-12 12:41:41 -04:00
|
|
|
showToast={showToast}
|
2022-03-04 16:14:52 -05:00
|
|
|
skinTone={skinTone}
|
2022-07-06 15:06:20 -04:00
|
|
|
story={storyView}
|
2022-08-22 13:44:23 -04:00
|
|
|
storyViewMode={selectedStoryData.storyViewMode}
|
2022-11-16 17:10:11 -05:00
|
|
|
viewTarget={selectedStoryData.viewTarget}
|
2022-03-04 16:14:52 -05:00
|
|
|
{...storiesActions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|