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-04-15 00:08:46 +00:00
|
|
|
import type { GetStoriesByConversationIdType } from '../selectors/stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import { StoryViewer } from '../../components/StoryViewer';
|
|
|
|
import { ToastMessageBodyTooLong } from '../../components/ToastMessageBodyTooLong';
|
|
|
|
import {
|
|
|
|
getEmojiSkinTone,
|
2022-05-06 19:02:44 +00:00
|
|
|
getHasAllStoriesMuted,
|
2022-03-04 21:14:52 +00:00
|
|
|
getPreferredReactionEmoji,
|
|
|
|
} from '../selectors/items';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2022-04-29 17:43:24 +00:00
|
|
|
import { getStoriesSelector, getStoryReplies } from '../selectors/stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { renderEmojiPicker } from './renderEmojiPicker';
|
|
|
|
import { showToast } from '../../util/showToast';
|
|
|
|
import { useActions as useEmojisActions } from '../ducks/emojis';
|
|
|
|
import { useActions as useItemsActions } from '../ducks/items';
|
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';
|
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
conversationId: string;
|
|
|
|
onClose: () => unknown;
|
|
|
|
onNextUserStories: () => unknown;
|
|
|
|
onPrevUserStories: () => unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function SmartStoryViewer({
|
|
|
|
conversationId,
|
|
|
|
onClose,
|
|
|
|
onNextUserStories,
|
|
|
|
onPrevUserStories,
|
|
|
|
}: PropsType): JSX.Element | null {
|
|
|
|
const storiesActions = useStoriesActions();
|
2022-05-06 19:02:44 +00:00
|
|
|
const { onSetSkinTone, toggleHasAllStoriesMuted } = useItemsActions();
|
2022-03-04 21:14:52 +00:00
|
|
|
const { onUseEmoji } = useEmojisActions();
|
2022-04-29 17:43:24 +00:00
|
|
|
const { openConversationInternal, toggleHideStories } =
|
|
|
|
useConversationsActions();
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
|
|
|
const preferredReactionEmoji = useSelector<StateType, Array<string>>(
|
|
|
|
getPreferredReactionEmoji
|
|
|
|
);
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
const getStoriesByConversationId = useSelector<
|
|
|
|
StateType,
|
|
|
|
GetStoriesByConversationIdType
|
|
|
|
>(getStoriesSelector);
|
|
|
|
|
|
|
|
const { group, stories } = getStoriesByConversationId(conversationId);
|
|
|
|
|
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-05-06 19:02:44 +00:00
|
|
|
const hasAllStoriesMuted = useSelector<StateType, boolean>(
|
|
|
|
getHasAllStoriesMuted
|
|
|
|
);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<StoryViewer
|
2022-04-15 00:08:46 +00:00
|
|
|
conversationId={conversationId}
|
2022-03-04 21:14:52 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2022-04-15 00:08:46 +00:00
|
|
|
group={group}
|
2022-05-06 19:02:44 +00:00
|
|
|
hasAllStoriesMuted={hasAllStoriesMuted}
|
2022-03-04 21:14:52 +00:00
|
|
|
i18n={i18n}
|
|
|
|
onClose={onClose}
|
2022-04-29 17:43:24 +00:00
|
|
|
onHideStory={toggleHideStories}
|
|
|
|
onGoToConversation={senderId => {
|
|
|
|
openConversationInternal({ conversationId: senderId });
|
|
|
|
storiesActions.toggleStoriesView();
|
|
|
|
}}
|
2022-03-04 21:14:52 +00:00
|
|
|
onNextUserStories={onNextUserStories}
|
|
|
|
onPrevUserStories={onPrevUserStories}
|
|
|
|
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(
|
|
|
|
conversationId,
|
|
|
|
message,
|
|
|
|
mentions,
|
|
|
|
timestamp,
|
|
|
|
story
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
onSetSkinTone={onSetSkinTone}
|
|
|
|
onTextTooLong={() => showToast(ToastMessageBodyTooLong)}
|
|
|
|
onUseEmoji={onUseEmoji}
|
|
|
|
preferredReactionEmoji={preferredReactionEmoji}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
renderEmojiPicker={renderEmojiPicker}
|
2022-04-15 00:08:46 +00:00
|
|
|
replyState={replyState}
|
2022-03-04 21:14:52 +00:00
|
|
|
stories={stories}
|
|
|
|
skinTone={skinTone}
|
2022-05-06 19:02:44 +00:00
|
|
|
toggleHasAllStoriesMuted={toggleHasAllStoriesMuted}
|
2022-03-04 21:14:52 +00:00
|
|
|
{...storiesActions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|