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