2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { RefObject } from 'react';
|
|
|
|
import React from 'react';
|
2023-01-19 19:56:02 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2019-08-09 00:46:49 +00:00
|
|
|
import { TimelineItem } from '../../components/conversation/TimelineItem';
|
2023-01-19 19:56:02 +00:00
|
|
|
import type { WidthBreakpoint } from '../../components/_util';
|
|
|
|
import { useProxySelector } from '../../hooks/useProxySelector';
|
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useComposerActions } from '../ducks/composer';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useAccountsActions } from '../ducks/accounts';
|
|
|
|
import { useLightboxActions } from '../ducks/lightbox';
|
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
|
|
|
import { useCallingActions } from '../ducks/calling';
|
2021-11-17 21:11:46 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2023-04-03 20:16:27 +00:00
|
|
|
import {
|
|
|
|
getIntl,
|
|
|
|
getInteractionMode,
|
|
|
|
getTheme,
|
|
|
|
getPlatform,
|
|
|
|
} from '../selectors/user';
|
2023-03-20 22:23:53 +00:00
|
|
|
import { getTargetedMessage } from '../selectors/conversations';
|
2022-12-23 00:32:03 +00:00
|
|
|
import { getTimelineItem } from '../selectors/timeline';
|
2022-03-28 22:55:12 +00:00
|
|
|
import {
|
|
|
|
areMessagesInSameGroup,
|
|
|
|
shouldCurrentMessageHideMetadata,
|
|
|
|
UnreadIndicatorPlacement,
|
|
|
|
} from '../../util/timelineUtil';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2020-09-09 02:25:05 +00:00
|
|
|
import { SmartContactName } from './ContactName';
|
2021-06-01 20:45:43 +00:00
|
|
|
import { SmartUniversalTimerNotification } from './UniversalTimerNotification';
|
2022-03-28 22:55:12 +00:00
|
|
|
import { isSameDay } from '../../util/timestamp';
|
2023-01-19 19:56:02 +00:00
|
|
|
import { renderAudioAttachment } from './renderAudioAttachment';
|
|
|
|
import { renderEmojiPicker } from './renderEmojiPicker';
|
|
|
|
import { renderReactionPicker } from './renderReactionPicker';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
type ExternalProps = {
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef: RefObject<HTMLElement>;
|
2023-01-19 19:56:02 +00:00
|
|
|
containerWidthBreakpoint: WidthBreakpoint;
|
2021-09-10 23:59:41 +00:00
|
|
|
conversationId: string;
|
2022-01-26 23:05:26 +00:00
|
|
|
isOldestTimelineItem: boolean;
|
2021-09-10 23:59:41 +00:00
|
|
|
messageId: string;
|
|
|
|
nextMessageId: undefined | string;
|
|
|
|
previousMessageId: undefined | string;
|
2022-03-08 14:32:42 +00:00
|
|
|
unreadIndicatorPlacement: undefined | UnreadIndicatorPlacement;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
|
2024-02-08 14:36:08 +00:00
|
|
|
function renderContact(contactId: string): JSX.Element {
|
|
|
|
return <SmartContactName contactId={contactId} />;
|
2020-09-09 02:25:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 20:45:43 +00:00
|
|
|
function renderUniversalTimerNotification(): JSX.Element {
|
|
|
|
return <SmartUniversalTimerNotification />;
|
|
|
|
}
|
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export function SmartTimelineItem(props: ExternalProps): JSX.Element {
|
2021-09-10 23:59:41 +00:00
|
|
|
const {
|
|
|
|
containerElementRef,
|
2023-01-19 19:56:02 +00:00
|
|
|
containerWidthBreakpoint,
|
2021-09-10 23:59:41 +00:00
|
|
|
conversationId,
|
2022-01-26 23:05:26 +00:00
|
|
|
isOldestTimelineItem,
|
2021-09-10 23:59:41 +00:00
|
|
|
messageId,
|
|
|
|
nextMessageId,
|
|
|
|
previousMessageId,
|
2022-03-08 14:32:42 +00:00
|
|
|
unreadIndicatorPlacement,
|
2021-09-10 23:59:41 +00:00
|
|
|
} = props;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
|
|
|
const interactionMode = useSelector(getInteractionMode);
|
|
|
|
const theme = useSelector(getTheme);
|
2023-04-03 20:16:27 +00:00
|
|
|
const platform = useSelector(getPlatform);
|
2023-01-19 19:56:02 +00:00
|
|
|
const item = useProxySelector(getTimelineItem, messageId);
|
|
|
|
const previousItem = useProxySelector(getTimelineItem, previousMessageId);
|
|
|
|
const nextItem = useProxySelector(getTimelineItem, nextMessageId);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const targetedMessage = useSelector(getTargetedMessage);
|
|
|
|
const isTargeted = Boolean(
|
|
|
|
targetedMessage && messageId === targetedMessage.id
|
2021-09-10 23:59:41 +00:00
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2022-03-28 22:55:12 +00:00
|
|
|
const isNextItemCallingNotification = nextItem?.type === 'callHistory';
|
|
|
|
|
|
|
|
const shouldCollapseAbove = areMessagesInSameGroup(
|
|
|
|
previousItem,
|
|
|
|
unreadIndicatorPlacement === UnreadIndicatorPlacement.JustAbove,
|
|
|
|
item
|
|
|
|
);
|
|
|
|
const shouldCollapseBelow = areMessagesInSameGroup(
|
|
|
|
item,
|
|
|
|
unreadIndicatorPlacement === UnreadIndicatorPlacement.JustBelow,
|
|
|
|
nextItem
|
|
|
|
);
|
|
|
|
const shouldHideMetadata = shouldCurrentMessageHideMetadata(
|
|
|
|
shouldCollapseBelow,
|
|
|
|
item,
|
|
|
|
nextItem
|
|
|
|
);
|
|
|
|
const shouldRenderDateHeader =
|
|
|
|
isOldestTimelineItem ||
|
|
|
|
Boolean(
|
|
|
|
item &&
|
|
|
|
previousItem &&
|
|
|
|
// This comparison avoids strange header behavior for out-of-order messages.
|
|
|
|
item.timestamp > previousItem.timestamp &&
|
|
|
|
!isSameDay(previousItem.timestamp, item.timestamp)
|
|
|
|
);
|
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const {
|
|
|
|
blockGroupLinkRequests,
|
2023-03-20 22:23:53 +00:00
|
|
|
clearTargetedMessage: clearSelectedMessage,
|
2023-01-19 19:56:02 +00:00
|
|
|
doubleCheckMissingQuoteReference,
|
|
|
|
kickOffAttachmentDownload,
|
|
|
|
markAttachmentAsCorrupted,
|
|
|
|
messageExpanded,
|
|
|
|
openGiftBadge,
|
|
|
|
pushPanelForConversation,
|
2023-04-22 01:52:25 +00:00
|
|
|
copyMessageText,
|
2023-01-19 19:56:02 +00:00
|
|
|
retryDeleteForEveryone,
|
|
|
|
retryMessageSend,
|
|
|
|
saveAttachment,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetMessage,
|
|
|
|
toggleSelectMessage,
|
2023-04-20 16:31:59 +00:00
|
|
|
setMessageToEdit,
|
2023-01-19 19:56:02 +00:00
|
|
|
showConversation,
|
|
|
|
showExpiredIncomingTapToViewToast,
|
|
|
|
showExpiredOutgoingTapToViewToast,
|
2023-04-10 16:31:45 +00:00
|
|
|
showSpoiler,
|
2023-01-19 19:56:02 +00:00
|
|
|
startConversation,
|
|
|
|
} = useConversationsActions();
|
|
|
|
|
|
|
|
const { reactToMessage, scrollToQuotedMessage, setQuoteByMessageId } =
|
|
|
|
useComposerActions();
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const {
|
|
|
|
showContactModal,
|
2023-03-27 23:48:57 +00:00
|
|
|
showEditHistoryModal,
|
2023-04-10 21:38:34 +00:00
|
|
|
toggleDeleteMessagesModal,
|
2023-03-20 22:23:53 +00:00
|
|
|
toggleForwardMessagesModal,
|
2023-01-19 19:56:02 +00:00
|
|
|
toggleSafetyNumberModal,
|
|
|
|
} = useGlobalModalActions();
|
|
|
|
|
|
|
|
const { checkForAccount } = useAccountsActions();
|
|
|
|
|
|
|
|
const { showLightbox, showLightboxForViewOnceMedia } = useLightboxActions();
|
|
|
|
|
|
|
|
const { viewStory } = useStoriesActions();
|
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
const {
|
|
|
|
onOutgoingAudioCallInConversation,
|
|
|
|
onOutgoingVideoCallInConversation,
|
|
|
|
returnToActiveCall,
|
|
|
|
} = useCallingActions();
|
2023-01-19 19:56:02 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TimelineItem
|
|
|
|
item={item}
|
|
|
|
id={messageId}
|
|
|
|
containerElementRef={containerElementRef}
|
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
|
|
|
conversationId={conversationId}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
isNextItemCallingNotification={isNextItemCallingNotification}
|
2023-03-20 22:23:53 +00:00
|
|
|
isTargeted={isTargeted}
|
2023-01-19 19:56:02 +00:00
|
|
|
renderAudioAttachment={renderAudioAttachment}
|
|
|
|
renderContact={renderContact}
|
|
|
|
renderEmojiPicker={renderEmojiPicker}
|
|
|
|
renderReactionPicker={renderReactionPicker}
|
|
|
|
renderUniversalTimerNotification={renderUniversalTimerNotification}
|
|
|
|
shouldCollapseAbove={shouldCollapseAbove}
|
|
|
|
shouldCollapseBelow={shouldCollapseBelow}
|
|
|
|
shouldHideMetadata={shouldHideMetadata}
|
|
|
|
shouldRenderDateHeader={shouldRenderDateHeader}
|
2023-03-27 23:48:57 +00:00
|
|
|
showEditHistoryModal={showEditHistoryModal}
|
2023-01-19 19:56:02 +00:00
|
|
|
i18n={i18n}
|
|
|
|
interactionMode={interactionMode}
|
|
|
|
theme={theme}
|
2023-04-03 20:16:27 +00:00
|
|
|
platform={platform}
|
2023-01-19 19:56:02 +00:00
|
|
|
blockGroupLinkRequests={blockGroupLinkRequests}
|
|
|
|
checkForAccount={checkForAccount}
|
2023-03-20 22:23:53 +00:00
|
|
|
clearTargetedMessage={clearSelectedMessage}
|
2023-01-19 19:56:02 +00:00
|
|
|
doubleCheckMissingQuoteReference={doubleCheckMissingQuoteReference}
|
|
|
|
kickOffAttachmentDownload={kickOffAttachmentDownload}
|
|
|
|
markAttachmentAsCorrupted={markAttachmentAsCorrupted}
|
|
|
|
messageExpanded={messageExpanded}
|
|
|
|
openGiftBadge={openGiftBadge}
|
|
|
|
pushPanelForConversation={pushPanelForConversation}
|
|
|
|
reactToMessage={reactToMessage}
|
2023-04-22 01:52:25 +00:00
|
|
|
copyMessageText={copyMessageText}
|
2023-09-06 00:34:51 +00:00
|
|
|
onOutgoingAudioCallInConversation={onOutgoingAudioCallInConversation}
|
|
|
|
onOutgoingVideoCallInConversation={onOutgoingVideoCallInConversation}
|
2023-01-19 19:56:02 +00:00
|
|
|
retryDeleteForEveryone={retryDeleteForEveryone}
|
|
|
|
retryMessageSend={retryMessageSend}
|
|
|
|
returnToActiveCall={returnToActiveCall}
|
|
|
|
saveAttachment={saveAttachment}
|
|
|
|
scrollToQuotedMessage={scrollToQuotedMessage}
|
2023-03-20 22:23:53 +00:00
|
|
|
targetMessage={targetMessage}
|
2023-01-19 19:56:02 +00:00
|
|
|
setQuoteByMessageId={setQuoteByMessageId}
|
2023-04-20 16:31:59 +00:00
|
|
|
setMessageToEdit={setMessageToEdit}
|
2023-01-19 19:56:02 +00:00
|
|
|
showContactModal={showContactModal}
|
|
|
|
showConversation={showConversation}
|
|
|
|
showExpiredIncomingTapToViewToast={showExpiredIncomingTapToViewToast}
|
|
|
|
showExpiredOutgoingTapToViewToast={showExpiredOutgoingTapToViewToast}
|
|
|
|
showLightbox={showLightbox}
|
|
|
|
showLightboxForViewOnceMedia={showLightboxForViewOnceMedia}
|
2023-04-10 16:31:45 +00:00
|
|
|
showSpoiler={showSpoiler}
|
2023-01-19 19:56:02 +00:00
|
|
|
startConversation={startConversation}
|
2023-04-10 21:38:34 +00:00
|
|
|
toggleDeleteMessagesModal={toggleDeleteMessagesModal}
|
2023-03-20 22:23:53 +00:00
|
|
|
toggleForwardMessagesModal={toggleForwardMessagesModal}
|
2023-01-19 19:56:02 +00:00
|
|
|
toggleSafetyNumberModal={toggleSafetyNumberModal}
|
|
|
|
viewStory={viewStory}
|
2023-03-20 22:23:53 +00:00
|
|
|
toggleSelectMessage={toggleSelectMessage}
|
2023-01-19 19:56:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|