2022-03-04 21:14:52 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { StateType } from '../reducer';
|
2022-06-17 00:48:57 +00:00
|
|
|
import { SmartStoryCreator } from './StoryCreator';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { SmartToastManager } from './ToastManager';
|
|
|
|
import type { WidthBreakpoint } from '../../components/_util';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { StoriesTab } from '../../components/StoriesTab';
|
2023-10-30 16:24:28 +00:00
|
|
|
import { getMaximumOutgoingAttachmentSizeInKb } from '../../types/AttachmentSize';
|
2023-02-28 22:17:22 +00:00
|
|
|
import type { ConfigKeyType } from '../../RemoteConfig';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { getMe } from '../selectors/conversations';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
2022-07-29 00:16:30 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2022-10-14 20:49:46 +00:00
|
|
|
import {
|
2022-10-25 22:18:42 +00:00
|
|
|
getHasStoryViewReceiptSetting,
|
2023-08-09 00:53:06 +00:00
|
|
|
getNavTabsCollapsed,
|
2022-10-14 20:49:46 +00:00
|
|
|
getPreferredLeftPaneWidth,
|
2023-02-28 22:17:22 +00:00
|
|
|
getRemoteConfig,
|
2022-10-14 20:49:46 +00:00
|
|
|
} from '../selectors/items';
|
2022-09-26 20:28:40 +00:00
|
|
|
import {
|
2022-11-02 00:36:16 +00:00
|
|
|
getAddStoryData,
|
2023-08-14 23:28:47 +00:00
|
|
|
getHasAnyFailedStorySends,
|
2022-09-26 20:28:40 +00:00
|
|
|
getSelectedStoryData,
|
|
|
|
getStories,
|
|
|
|
} from '../selectors/stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
2022-08-12 23:44:10 +00:00
|
|
|
import { useToastActions } from '../ducks/toast';
|
2023-02-24 23:18:57 +00:00
|
|
|
import { useAudioPlayerActions } from '../ducks/audioPlayer';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { useItemsActions } from '../ducks/items';
|
2023-08-14 23:28:47 +00:00
|
|
|
import { getHasPendingUpdate } from '../selectors/updates';
|
2023-08-21 20:12:27 +00:00
|
|
|
import { getOtherTabsUnreadStats } from '../selectors/nav';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
function renderStoryCreator(): JSX.Element {
|
|
|
|
return <SmartStoryCreator />;
|
2022-06-17 00:48:57 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 20:09:54 +00:00
|
|
|
function renderToastManager(props: {
|
|
|
|
containerWidthBreakpoint: WidthBreakpoint;
|
|
|
|
}): JSX.Element {
|
|
|
|
return <SmartToastManager disableMegaphone {...props} />;
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
export function SmartStoriesTab(): JSX.Element | null {
|
2022-03-04 21:14:52 +00:00
|
|
|
const storiesActions = useStoriesActions();
|
2022-12-20 01:04:47 +00:00
|
|
|
const {
|
|
|
|
retryMessageSend,
|
|
|
|
saveAttachment,
|
|
|
|
showConversation,
|
|
|
|
toggleHideStories,
|
|
|
|
} = useConversationsActions();
|
2023-03-20 22:23:53 +00:00
|
|
|
const { showStoriesSettings, toggleForwardMessagesModal } =
|
2022-07-21 00:07:09 +00:00
|
|
|
useGlobalModalActions();
|
2022-08-12 23:44:10 +00:00
|
|
|
const { showToast } = useToastActions();
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
|
|
|
|
const preferredWidthFromStorage = useSelector<StateType, number>(
|
|
|
|
getPreferredLeftPaneWidth
|
|
|
|
);
|
2022-07-29 00:16:30 +00:00
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
const addStoryData = useSelector(getAddStoryData);
|
2022-07-01 00:52:03 +00:00
|
|
|
const { hiddenStories, myStories, stories } = useSelector(getStories);
|
|
|
|
|
|
|
|
const me = useSelector(getMe);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-09-26 20:28:40 +00:00
|
|
|
const selectedStoryData = useSelector(getSelectedStoryData);
|
|
|
|
|
|
|
|
const isStoriesSettingsVisible = useSelector(
|
|
|
|
(state: StateType) => state.globalModals.isStoriesSettingsVisible
|
|
|
|
);
|
|
|
|
|
2022-10-25 22:18:42 +00:00
|
|
|
const hasViewReceiptSetting = useSelector(getHasStoryViewReceiptSetting);
|
2023-08-14 23:28:47 +00:00
|
|
|
const hasPendingUpdate = useSelector(getHasPendingUpdate);
|
|
|
|
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
|
2023-08-21 20:12:27 +00:00
|
|
|
const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
|
2022-10-14 20:49:46 +00:00
|
|
|
|
2023-02-28 22:17:22 +00:00
|
|
|
const remoteConfig = useSelector(getRemoteConfig);
|
2023-10-30 16:24:28 +00:00
|
|
|
const maxAttachmentSizeInKb = getMaximumOutgoingAttachmentSizeInKb(
|
2023-02-28 22:17:22 +00:00
|
|
|
(name: ConfigKeyType) => {
|
|
|
|
const value = remoteConfig[name]?.value;
|
|
|
|
return value ? String(value) : undefined;
|
|
|
|
}
|
|
|
|
);
|
2023-02-24 23:18:57 +00:00
|
|
|
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
const preferredLeftPaneWidth = useSelector(getPreferredLeftPaneWidth);
|
|
|
|
const navTabsCollapsed = useSelector(getNavTabsCollapsed);
|
|
|
|
const { savePreferredLeftPaneWidth, toggleNavTabsCollapse } =
|
|
|
|
useItemsActions();
|
|
|
|
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
storiesActions.markStoriesTabViewed();
|
|
|
|
return () => {
|
|
|
|
storiesActions.clearStoriesTabState();
|
|
|
|
};
|
|
|
|
}, [storiesActions]);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
return (
|
2023-08-09 00:53:06 +00:00
|
|
|
<StoriesTab
|
2023-08-21 20:12:27 +00:00
|
|
|
otherTabsUnreadStats={otherTabsUnreadStats}
|
2022-11-02 00:36:16 +00:00
|
|
|
addStoryData={addStoryData}
|
2022-07-29 00:16:30 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2023-08-14 23:28:47 +00:00
|
|
|
hasFailedStorySends={hasFailedStorySends}
|
|
|
|
hasPendingUpdate={hasPendingUpdate}
|
2022-03-04 21:14:52 +00:00
|
|
|
hiddenStories={hiddenStories}
|
|
|
|
i18n={i18n}
|
2023-02-28 22:17:22 +00:00
|
|
|
maxAttachmentSizeInKb={maxAttachmentSizeInKb}
|
2022-07-01 00:52:03 +00:00
|
|
|
me={me}
|
|
|
|
myStories={myStories}
|
2023-08-09 00:53:06 +00:00
|
|
|
navTabsCollapsed={navTabsCollapsed}
|
2023-03-20 22:23:53 +00:00
|
|
|
onForwardStory={messageId => {
|
|
|
|
toggleForwardMessagesModal([messageId]);
|
|
|
|
}}
|
2022-07-01 00:52:03 +00:00
|
|
|
onSaveStory={story => {
|
|
|
|
if (story.attachment) {
|
|
|
|
saveAttachment(story.attachment, story.timestamp);
|
|
|
|
}
|
|
|
|
}}
|
2023-08-09 00:53:06 +00:00
|
|
|
onToggleNavTabsCollapse={toggleNavTabsCollapse}
|
2023-02-24 23:18:57 +00:00
|
|
|
onMediaPlaybackStart={pauseVoiceNotePlayer}
|
2023-08-09 00:53:06 +00:00
|
|
|
preferredLeftPaneWidth={preferredLeftPaneWidth}
|
2022-03-04 21:14:52 +00:00
|
|
|
preferredWidthFromStorage={preferredWidthFromStorage}
|
2022-06-17 00:48:57 +00:00
|
|
|
renderStoryCreator={renderStoryCreator}
|
2024-01-29 20:09:54 +00:00
|
|
|
renderToastManager={renderToastManager}
|
2022-12-20 01:04:47 +00:00
|
|
|
retryMessageSend={retryMessageSend}
|
2023-08-09 00:53:06 +00:00
|
|
|
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation={showConversation}
|
2022-07-21 00:07:09 +00:00
|
|
|
showStoriesSettings={showStoriesSettings}
|
2022-08-12 23:44:10 +00:00
|
|
|
showToast={showToast}
|
2022-03-04 21:14:52 +00:00
|
|
|
stories={stories}
|
2023-08-09 00:53:06 +00:00
|
|
|
theme={theme}
|
2022-03-04 21:14:52 +00:00
|
|
|
toggleHideStories={toggleHideStories}
|
2022-09-26 20:28:40 +00:00
|
|
|
isViewingStory={selectedStoryData !== undefined}
|
|
|
|
isStoriesSettingsVisible={isStoriesSettingsVisible}
|
2022-10-25 22:18:42 +00:00
|
|
|
hasViewReceiptSetting={hasViewReceiptSetting}
|
2022-03-04 21:14:52 +00:00
|
|
|
{...storiesActions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|