2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-10-05 16:47:06 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
2022-12-15 01:10:09 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-12-14 18:41:04 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2023-06-15 22:26:53 +00:00
|
|
|
import { ConversationPanel } from './ConversationPanel';
|
2022-12-14 18:41:04 +00:00
|
|
|
import { ConversationView } from '../../components/conversation/ConversationView';
|
|
|
|
import { SmartCompositionArea } from './CompositionArea';
|
|
|
|
import { SmartConversationHeader } from './ConversationHeader';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { SmartTimeline } from './Timeline';
|
2023-01-02 21:34:41 +00:00
|
|
|
import {
|
2023-07-26 22:23:32 +00:00
|
|
|
getActivePanel,
|
|
|
|
getIsPanelAnimating,
|
2023-01-02 21:34:41 +00:00
|
|
|
getSelectedConversationId,
|
2023-03-20 22:23:53 +00:00
|
|
|
getSelectedMessageIds,
|
2023-01-02 21:34:41 +00:00
|
|
|
} from '../selectors/conversations';
|
2022-12-15 01:10:09 +00:00
|
|
|
import { useComposerActions } from '../ducks/composer';
|
2022-12-21 03:25:10 +00:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
2021-10-05 16:47:06 +00:00
|
|
|
|
2023-01-02 21:34:41 +00:00
|
|
|
export function SmartConversationView(): JSX.Element {
|
|
|
|
const conversationId = useSelector(getSelectedConversationId);
|
|
|
|
|
|
|
|
if (!conversationId) {
|
|
|
|
throw new Error('SmartConversationView: No selected conversation');
|
|
|
|
}
|
2021-10-05 16:47:06 +00:00
|
|
|
|
2023-06-15 22:26:53 +00:00
|
|
|
const { toggleSelectMode } = useConversationsActions();
|
2023-03-20 22:23:53 +00:00
|
|
|
const selectedMessageIds = useSelector(getSelectedMessageIds);
|
|
|
|
const isSelectMode = selectedMessageIds != null;
|
2022-12-15 01:10:09 +00:00
|
|
|
|
|
|
|
const { processAttachments } = useComposerActions();
|
|
|
|
|
2023-03-24 21:16:48 +00:00
|
|
|
const hasOpenModal = useSelector((state: StateType) => {
|
|
|
|
return (
|
|
|
|
state.globalModals.forwardMessagesProps != null ||
|
2023-04-10 21:38:34 +00:00
|
|
|
state.globalModals.deleteMessagesProps != null ||
|
2023-03-24 21:16:48 +00:00
|
|
|
state.globalModals.hasConfirmationModal
|
|
|
|
);
|
2023-03-20 22:23:53 +00:00
|
|
|
});
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const shouldHideConversationView = useSelector((state: StateType) => {
|
|
|
|
const activePanel = getActivePanel(state);
|
|
|
|
const isAnimating = getIsPanelAnimating(state);
|
|
|
|
return activePanel && !isAnimating;
|
|
|
|
});
|
|
|
|
|
2022-12-15 01:10:09 +00:00
|
|
|
return (
|
|
|
|
<ConversationView
|
|
|
|
conversationId={conversationId}
|
2023-03-24 21:16:48 +00:00
|
|
|
hasOpenModal={hasOpenModal}
|
|
|
|
isSelectMode={isSelectMode}
|
|
|
|
onExitSelectMode={() => {
|
|
|
|
toggleSelectMode(false);
|
|
|
|
}}
|
2022-12-15 01:10:09 +00:00
|
|
|
processAttachments={processAttachments}
|
2022-12-21 03:25:10 +00:00
|
|
|
renderCompositionArea={() => <SmartCompositionArea id={conversationId} />}
|
2022-12-15 01:10:09 +00:00
|
|
|
renderConversationHeader={() => (
|
2022-12-21 03:25:10 +00:00
|
|
|
<SmartConversationHeader id={conversationId} />
|
2022-12-15 01:10:09 +00:00
|
|
|
)}
|
2023-01-18 03:27:34 +00:00
|
|
|
renderTimeline={() => (
|
|
|
|
<SmartTimeline key={conversationId} id={conversationId} />
|
|
|
|
)}
|
2023-06-15 22:26:53 +00:00
|
|
|
renderPanel={() => <ConversationPanel conversationId={conversationId} />}
|
2023-07-26 22:23:32 +00:00
|
|
|
shouldHideConversationView={shouldHideConversationView}
|
2022-12-15 01:10:09 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|