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
|
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
import { isEmpty, pick } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import React from 'react';
|
2019-03-20 17:42:28 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-08-06 21:43:18 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2019-03-20 17:42:28 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2024-02-06 02:13:13 +00:00
|
|
|
import type { WarningType as TimelineWarningType } from '../../components/conversation/Timeline';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { Timeline } from '../../components/conversation/Timeline';
|
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { ConversationType } from '../ducks/conversations';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2021-11-20 15:41:21 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
2019-05-31 22:42:01 +00:00
|
|
|
import {
|
2022-12-23 00:32:03 +00:00
|
|
|
getMessages,
|
2023-08-16 20:54:39 +00:00
|
|
|
getConversationByServiceIdSelector,
|
2019-05-31 22:42:01 +00:00
|
|
|
getConversationMessagesSelector,
|
|
|
|
getConversationSelector,
|
2021-03-03 20:09:58 +00:00
|
|
|
getInvitedContactsForNewlyCreatedGroup,
|
2024-02-06 02:13:13 +00:00
|
|
|
getSafeConversationWithSameTitle,
|
2023-03-20 22:23:53 +00:00
|
|
|
getTargetedMessage,
|
2019-05-31 22:42:01 +00:00
|
|
|
} from '../selectors/conversations';
|
2023-03-20 18:03:21 +00:00
|
|
|
import { selectAudioPlayerActive } from '../selectors/audioPlayer';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2024-02-27 16:01:25 +00:00
|
|
|
import { SmartTimelineItem, type SmartTimelineItemProps } from './TimelineItem';
|
2024-02-06 02:13:13 +00:00
|
|
|
import { SmartCollidingAvatars } from './CollidingAvatars';
|
|
|
|
import type { PropsType as SmartCollidingAvatarsPropsType } from './CollidingAvatars';
|
2022-03-24 21:46:17 +00:00
|
|
|
import { SmartContactSpoofingReviewDialog } from './ContactSpoofingReviewDialog';
|
|
|
|
import type { PropsType as SmartContactSpoofingReviewDialogPropsType } from './ContactSpoofingReviewDialog';
|
2019-05-31 22:42:01 +00:00
|
|
|
import { SmartTypingBubble } from './TypingBubble';
|
2020-05-27 21:37:06 +00:00
|
|
|
import { SmartHeroRow } from './HeroRow';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
|
|
|
import {
|
|
|
|
dehydrateCollisionsWithConversations,
|
|
|
|
getCollisionsFromMemberships,
|
|
|
|
} from '../../util/groupMemberNameCollisions';
|
|
|
|
import { ContactSpoofingType } from '../../util/contactSpoofing';
|
2021-11-20 15:41:21 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2023-03-20 18:03:21 +00:00
|
|
|
import { SmartMiniPlayer } from './MiniPlayer';
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
|
2021-09-10 23:59:41 +00:00
|
|
|
function renderItem({
|
|
|
|
containerElementRef,
|
2021-10-12 23:59:08 +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,
|
2024-02-27 16:01:25 +00:00
|
|
|
}: SmartTimelineItemProps): JSX.Element {
|
2019-11-07 21:36:16 +00:00
|
|
|
return (
|
2021-08-11 16:23:21 +00:00
|
|
|
<SmartTimelineItem
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef={containerElementRef}
|
2021-10-12 23:59:08 +00:00
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
2019-11-07 21:36:16 +00:00
|
|
|
conversationId={conversationId}
|
2022-01-26 23:05:26 +00:00
|
|
|
isOldestTimelineItem={isOldestTimelineItem}
|
2021-09-10 23:59:41 +00:00
|
|
|
messageId={messageId}
|
|
|
|
previousMessageId={previousMessageId}
|
|
|
|
nextMessageId={nextMessageId}
|
2022-03-08 14:32:42 +00:00
|
|
|
unreadIndicatorPlacement={unreadIndicatorPlacement}
|
2020-05-05 19:49:34 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-03-10 20:36:58 +00:00
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
function renderCollidingAvatars(
|
|
|
|
props: SmartCollidingAvatarsPropsType
|
|
|
|
): JSX.Element {
|
|
|
|
return <SmartCollidingAvatars {...props} />;
|
|
|
|
}
|
|
|
|
|
2022-03-24 21:46:17 +00:00
|
|
|
function renderContactSpoofingReviewDialog(
|
|
|
|
props: SmartContactSpoofingReviewDialogPropsType
|
|
|
|
): JSX.Element {
|
|
|
|
return <SmartContactSpoofingReviewDialog {...props} />;
|
|
|
|
}
|
|
|
|
|
2022-12-21 03:25:10 +00:00
|
|
|
function renderHeroRow(id: string): JSX.Element {
|
|
|
|
return <SmartHeroRow id={id} />;
|
2020-05-27 21:37:06 +00:00
|
|
|
}
|
2023-03-20 18:03:21 +00:00
|
|
|
function renderMiniPlayer(options: { shouldFlow: boolean }): JSX.Element {
|
|
|
|
return <SmartMiniPlayer {...options} />;
|
|
|
|
}
|
2023-09-18 21:17:26 +00:00
|
|
|
function renderTypingBubble(conversationId: string): JSX.Element {
|
|
|
|
return <SmartTypingBubble conversationId={conversationId} />;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
const getWarning = (
|
2023-01-13 20:07:26 +00:00
|
|
|
conversation: ReadonlyDeep<ConversationType>,
|
2021-04-21 16:31:12 +00:00
|
|
|
state: Readonly<StateType>
|
|
|
|
): undefined | TimelineWarningType => {
|
2021-06-01 23:30:25 +00:00
|
|
|
switch (conversation.type) {
|
|
|
|
case 'direct':
|
|
|
|
if (!conversation.acceptedMessageRequest && !conversation.isBlocked) {
|
2024-02-06 02:13:13 +00:00
|
|
|
const safeConversation = getSafeConversationWithSameTitle(state, {
|
|
|
|
possiblyUnsafeConversation: conversation,
|
|
|
|
});
|
2021-06-01 23:30:25 +00:00
|
|
|
|
|
|
|
if (safeConversation) {
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle,
|
2024-02-06 02:13:13 +00:00
|
|
|
safeConversationId: safeConversation.id,
|
2021-06-01 23:30:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
case 'group': {
|
|
|
|
if (conversation.left || conversation.groupVersion !== 2) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const getConversationByServiceId =
|
|
|
|
getConversationByServiceIdSelector(state);
|
2021-06-01 23:30:25 +00:00
|
|
|
|
|
|
|
const { memberships } = getGroupMemberships(
|
|
|
|
conversation,
|
2023-08-16 20:54:39 +00:00
|
|
|
getConversationByServiceId
|
2021-06-01 23:30:25 +00:00
|
|
|
);
|
|
|
|
const groupNameCollisions = getCollisionsFromMemberships(memberships);
|
|
|
|
const hasGroupMembersWithSameName = !isEmpty(groupNameCollisions);
|
|
|
|
if (hasGroupMembersWithSameName) {
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle,
|
|
|
|
acknowledgedGroupNameCollisions:
|
2022-11-19 08:31:18 +00:00
|
|
|
conversation.acknowledgedGroupNameCollisions,
|
2021-11-11 22:43:05 +00:00
|
|
|
groupNameCollisions:
|
|
|
|
dehydrateCollisionsWithConversations(groupNameCollisions),
|
2021-06-01 23:30:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
default:
|
2022-11-19 08:31:18 +00:00
|
|
|
throw missingCaseError(conversation);
|
2021-06-01 23:30:25 +00:00
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
};
|
|
|
|
|
2022-12-21 03:25:10 +00:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
|
|
|
const { id } = props;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
const conversation = getConversationSelector(state)(id);
|
2021-09-13 02:36:41 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
const conversationMessages = getConversationMessagesSelector(state)(id);
|
2023-03-20 22:23:53 +00:00
|
|
|
const targetedMessage = getTargetedMessage(state);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2022-02-07 18:54:15 +00:00
|
|
|
const getTimestampForMessage = (messageId: string): undefined | number =>
|
2022-12-23 00:32:03 +00:00
|
|
|
getMessages(state)[messageId]?.timestamp;
|
2022-01-26 23:05:26 +00:00
|
|
|
|
2023-03-20 18:03:21 +00:00
|
|
|
const shouldShowMiniPlayer = Boolean(selectAudioPlayerActive(state));
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
return {
|
2019-05-31 22:42:01 +00:00
|
|
|
id,
|
2023-05-23 21:59:07 +00:00
|
|
|
...pick(conversation, [
|
|
|
|
'unreadCount',
|
|
|
|
'unreadMentionsCount',
|
|
|
|
'isGroupV1AndDisabled',
|
2023-09-27 21:23:52 +00:00
|
|
|
'typingContactIdTimestamps',
|
2023-05-23 21:59:07 +00:00
|
|
|
]),
|
2022-03-03 20:23:10 +00:00
|
|
|
isConversationSelected: state.conversations.selectedConversationId === id,
|
2023-12-08 18:18:51 +00:00
|
|
|
isIncomingMessageRequest: Boolean(
|
|
|
|
!conversation.acceptedMessageRequest &&
|
|
|
|
conversation.removalStage !== 'justNotification'
|
|
|
|
),
|
2023-09-27 21:23:52 +00:00
|
|
|
isSomeoneTyping: Boolean(
|
|
|
|
Object.keys(conversation.typingContactIdTimestamps ?? {}).length > 0
|
|
|
|
),
|
2019-05-31 22:42:01 +00:00
|
|
|
...conversationMessages,
|
2023-03-20 18:03:21 +00:00
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
invitedContactsForNewlyCreatedGroup:
|
|
|
|
getInvitedContactsForNewlyCreatedGroup(state),
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageId: targetedMessage ? targetedMessage.id : undefined,
|
2023-03-20 18:03:21 +00:00
|
|
|
shouldShowMiniPlayer,
|
2021-04-21 16:31:12 +00:00
|
|
|
|
|
|
|
warning: getWarning(conversation, state),
|
2024-02-06 02:13:13 +00:00
|
|
|
hasContactSpoofingReview: state.conversations.hasContactSpoofingReview,
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2022-01-26 23:05:26 +00:00
|
|
|
getTimestampForMessage,
|
2021-11-20 15:41:21 +00:00
|
|
|
getPreferredBadge: getPreferredBadgeSelector(state),
|
2019-03-20 17:42:28 +00:00
|
|
|
i18n: getIntl(state),
|
2021-11-20 15:41:21 +00:00
|
|
|
theme: getTheme(state),
|
2023-03-20 18:03:21 +00:00
|
|
|
|
2024-02-06 02:13:13 +00:00
|
|
|
renderCollidingAvatars,
|
2022-03-24 21:46:17 +00:00
|
|
|
renderContactSpoofingReviewDialog,
|
2020-05-27 21:37:06 +00:00
|
|
|
renderHeroRow,
|
2023-03-20 18:03:21 +00:00
|
|
|
renderItem,
|
|
|
|
renderMiniPlayer,
|
2019-05-31 22:42:01 +00:00
|
|
|
renderTypingBubble,
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
2021-09-13 02:36:41 +00:00
|
|
|
export const SmartTimeline = smart(Timeline);
|