2022-01-26 23:05:26 +00:00
|
|
|
// Copyright 2019-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
import { isEmpty, mapValues, pick } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { RefObject } from 'react';
|
|
|
|
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
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-08-11 16:23:21 +00:00
|
|
|
PropsActionsType as TimelineActionsType,
|
2021-06-01 23:30:25 +00:00
|
|
|
ContactSpoofingReviewPropType,
|
2021-04-21 16:31:12 +00:00
|
|
|
WarningType as TimelineWarningType,
|
2021-10-05 16:47:06 +00:00
|
|
|
PropsType as ComponentPropsType,
|
2021-04-21 16:31:12 +00:00
|
|
|
} 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 {
|
2021-10-26 22:59:08 +00:00
|
|
|
getConversationByUuidSelector,
|
2019-05-31 22:42:01 +00:00
|
|
|
getConversationMessagesSelector,
|
|
|
|
getConversationSelector,
|
2021-04-21 16:31:12 +00:00
|
|
|
getConversationsByTitleSelector,
|
2021-03-03 20:09:58 +00:00
|
|
|
getInvitedContactsForNewlyCreatedGroup,
|
2022-01-26 23:05:26 +00:00
|
|
|
getMessageSelector,
|
2019-11-07 21:36:16 +00:00
|
|
|
getSelectedMessage,
|
2019-05-31 22:42:01 +00:00
|
|
|
} from '../selectors/conversations';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
import { SmartTimelineItem } from './TimelineItem';
|
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';
|
2021-03-24 22:06:12 +00:00
|
|
|
import { renderAudioAttachment } from './renderAudioAttachment';
|
|
|
|
import { renderEmojiPicker } from './renderEmojiPicker';
|
2021-09-10 18:00:31 +00:00
|
|
|
import { renderReactionPicker } from './renderReactionPicker';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2022-09-15 19:17:15 +00:00
|
|
|
import { assertDev } from '../../util/assert';
|
2021-06-01 23:30:25 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
|
|
|
import {
|
|
|
|
dehydrateCollisionsWithConversations,
|
|
|
|
getCollisionsFromMemberships,
|
|
|
|
invertIdsByTitle,
|
|
|
|
} from '../../util/groupMemberNameCollisions';
|
|
|
|
import { ContactSpoofingType } from '../../util/contactSpoofing';
|
2022-03-08 14:32:42 +00:00
|
|
|
import type { UnreadIndicatorPlacement } from '../../util/timelineUtil';
|
2021-10-12 23:59:08 +00:00
|
|
|
import type { WidthBreakpoint } from '../../components/_util';
|
2021-11-20 15:41:21 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
type ExternalProps = {
|
|
|
|
id: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
// Note: most action creators are not wired into redux; for now they
|
|
|
|
// are provided by ConversationView in setupTimeline().
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
|
2021-10-05 16:47:06 +00:00
|
|
|
export type TimelinePropsType = ExternalProps &
|
|
|
|
Pick<
|
|
|
|
ComponentPropsType,
|
|
|
|
| 'acknowledgeGroupMemberNameCollisions'
|
|
|
|
| 'contactSupport'
|
2022-03-16 00:11:28 +00:00
|
|
|
| 'blockGroupLinkRequests'
|
2021-10-05 16:47:06 +00:00
|
|
|
| 'deleteMessage'
|
|
|
|
| 'deleteMessageForEveryone'
|
|
|
|
| 'displayTapToViewMessage'
|
|
|
|
| 'downloadAttachment'
|
|
|
|
| 'downloadNewVersion'
|
|
|
|
| 'kickOffAttachmentDownload'
|
|
|
|
| 'learnMoreAboutDeliveryIssue'
|
|
|
|
| 'loadNewerMessages'
|
|
|
|
| 'loadNewestMessages'
|
|
|
|
| 'loadOlderMessages'
|
|
|
|
| 'markAttachmentAsCorrupted'
|
|
|
|
| 'markMessageRead'
|
|
|
|
| 'markViewed'
|
|
|
|
| 'onBlock'
|
|
|
|
| 'onBlockAndReportSpam'
|
|
|
|
| 'onDelete'
|
|
|
|
| 'onUnblock'
|
|
|
|
| 'openConversation'
|
2022-05-11 20:59:58 +00:00
|
|
|
| 'openGiftBadge'
|
2021-10-05 16:47:06 +00:00
|
|
|
| 'openLink'
|
|
|
|
| 'reactToMessage'
|
|
|
|
| 'removeMember'
|
|
|
|
| 'replyToMessage'
|
2022-03-04 19:22:31 +00:00
|
|
|
| 'retryDeleteForEveryone'
|
2021-10-05 16:47:06 +00:00
|
|
|
| 'retrySend'
|
|
|
|
| 'scrollToQuotedMessage'
|
|
|
|
| 'showContactDetail'
|
|
|
|
| 'showContactModal'
|
|
|
|
| 'showExpiredIncomingTapToViewToast'
|
|
|
|
| 'showExpiredOutgoingTapToViewToast'
|
|
|
|
| 'showForwardMessageModal'
|
|
|
|
| 'showIdentity'
|
|
|
|
| 'showMessageDetail'
|
|
|
|
| 'showVisualAttachment'
|
2022-04-12 00:26:09 +00:00
|
|
|
| 'startConversation'
|
2021-10-05 16:47:06 +00:00
|
|
|
| 'unblurAvatar'
|
|
|
|
| 'updateSharedGroups'
|
|
|
|
>;
|
|
|
|
|
2021-09-10 23:59:41 +00:00
|
|
|
function renderItem({
|
|
|
|
actionProps,
|
|
|
|
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,
|
2021-09-10 23:59:41 +00:00
|
|
|
}: {
|
|
|
|
actionProps: TimelineActionsType;
|
|
|
|
containerElementRef: RefObject<HTMLElement>;
|
2021-10-12 23:59:08 +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;
|
2021-09-10 23:59:41 +00:00
|
|
|
}): JSX.Element {
|
2019-11-07 21:36:16 +00:00
|
|
|
return (
|
2021-08-11 16:23:21 +00:00
|
|
|
<SmartTimelineItem
|
2019-11-07 21:36:16 +00:00
|
|
|
{...actionProps}
|
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}
|
2020-05-05 19:49:34 +00:00
|
|
|
renderEmojiPicker={renderEmojiPicker}
|
2021-09-10 18:00:31 +00:00
|
|
|
renderReactionPicker={renderReactionPicker}
|
2021-03-10 20:36:58 +00:00
|
|
|
renderAudioAttachment={renderAudioAttachment}
|
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
|
|
|
|
2022-03-24 21:46:17 +00:00
|
|
|
function renderContactSpoofingReviewDialog(
|
|
|
|
props: SmartContactSpoofingReviewDialogPropsType
|
|
|
|
): JSX.Element {
|
|
|
|
return <SmartContactSpoofingReviewDialog {...props} />;
|
|
|
|
}
|
|
|
|
|
2020-08-07 00:50:54 +00:00
|
|
|
function renderHeroRow(
|
|
|
|
id: string,
|
2021-04-30 19:40:25 +00:00
|
|
|
unblurAvatar: () => void,
|
2020-08-07 00:50:54 +00:00
|
|
|
updateSharedGroups: () => unknown
|
|
|
|
): JSX.Element {
|
|
|
|
return (
|
2021-05-06 19:15:04 +00:00
|
|
|
<SmartHeroRow
|
2020-08-07 00:50:54 +00:00
|
|
|
id={id}
|
2021-04-30 19:40:25 +00:00
|
|
|
unblurAvatar={unblurAvatar}
|
2020-08-07 00:50:54 +00:00
|
|
|
updateSharedGroups={updateSharedGroups}
|
|
|
|
/>
|
|
|
|
);
|
2020-05-27 21:37:06 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function renderTypingBubble(id: string): JSX.Element {
|
2021-08-11 16:23:21 +00:00
|
|
|
return <SmartTypingBubble id={id} />;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
const getWarning = (
|
|
|
|
conversation: Readonly<ConversationType>,
|
|
|
|
state: Readonly<StateType>
|
|
|
|
): undefined | TimelineWarningType => {
|
2021-06-01 23:30:25 +00:00
|
|
|
switch (conversation.type) {
|
|
|
|
case 'direct':
|
|
|
|
if (!conversation.acceptedMessageRequest && !conversation.isBlocked) {
|
2021-11-11 22:43:05 +00:00
|
|
|
const getConversationsWithTitle =
|
|
|
|
getConversationsByTitleSelector(state);
|
2021-06-01 23:30:25 +00:00
|
|
|
const conversationsWithSameTitle = getConversationsWithTitle(
|
|
|
|
conversation.title
|
|
|
|
);
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-06-01 23:30:25 +00:00
|
|
|
conversationsWithSameTitle.length,
|
|
|
|
'Expected at least 1 conversation with the same title (this one)'
|
|
|
|
);
|
|
|
|
|
|
|
|
const safeConversation = conversationsWithSameTitle.find(
|
|
|
|
otherConversation =>
|
|
|
|
otherConversation.acceptedMessageRequest &&
|
|
|
|
otherConversation.type === 'direct' &&
|
|
|
|
otherConversation.id !== conversation.id
|
|
|
|
);
|
|
|
|
|
|
|
|
if (safeConversation) {
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle,
|
|
|
|
safeConversation,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
case 'group': {
|
|
|
|
if (conversation.left || conversation.groupVersion !== 2) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2021-10-26 22:59:08 +00:00
|
|
|
const getConversationByUuid = getConversationByUuidSelector(state);
|
2021-06-01 23:30:25 +00:00
|
|
|
|
|
|
|
const { memberships } = getGroupMemberships(
|
|
|
|
conversation,
|
2021-10-26 22:59:08 +00:00
|
|
|
getConversationByUuid
|
2021-06-01 23:30:25 +00:00
|
|
|
);
|
|
|
|
const groupNameCollisions = getCollisionsFromMemberships(memberships);
|
|
|
|
const hasGroupMembersWithSameName = !isEmpty(groupNameCollisions);
|
|
|
|
if (hasGroupMembersWithSameName) {
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle,
|
|
|
|
acknowledgedGroupNameCollisions:
|
|
|
|
conversation.acknowledgedGroupNameCollisions || {},
|
2021-11-11 22:43:05 +00:00
|
|
|
groupNameCollisions:
|
|
|
|
dehydrateCollisionsWithConversations(groupNameCollisions),
|
2021-06-01 23:30:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw missingCaseError(conversation.type);
|
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getContactSpoofingReview = (
|
|
|
|
selectedConversationId: string,
|
|
|
|
state: Readonly<StateType>
|
2021-06-01 23:30:25 +00:00
|
|
|
): undefined | ContactSpoofingReviewPropType => {
|
2021-04-21 16:31:12 +00:00
|
|
|
const { contactSpoofingReview } = state.conversations;
|
|
|
|
if (!contactSpoofingReview) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversationSelector = getConversationSelector(state);
|
2021-10-26 22:59:08 +00:00
|
|
|
const getConversationByUuid = getConversationByUuidSelector(state);
|
2021-06-01 23:30:25 +00:00
|
|
|
|
|
|
|
const currentConversation = conversationSelector(selectedConversationId);
|
|
|
|
|
|
|
|
switch (contactSpoofingReview.type) {
|
|
|
|
case ContactSpoofingType.DirectConversationWithSameTitle:
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle,
|
|
|
|
possiblyUnsafeConversation: currentConversation,
|
|
|
|
safeConversation: conversationSelector(
|
|
|
|
contactSpoofingReview.safeConversationId
|
|
|
|
),
|
|
|
|
};
|
|
|
|
case ContactSpoofingType.MultipleGroupMembersWithSameTitle: {
|
|
|
|
const { memberships } = getGroupMemberships(
|
|
|
|
currentConversation,
|
2021-10-26 22:59:08 +00:00
|
|
|
getConversationByUuid
|
2021-06-01 23:30:25 +00:00
|
|
|
);
|
|
|
|
const groupNameCollisions = getCollisionsFromMemberships(memberships);
|
|
|
|
|
|
|
|
const previouslyAcknowledgedTitlesById = invertIdsByTitle(
|
|
|
|
currentConversation.acknowledgedGroupNameCollisions || {}
|
|
|
|
);
|
|
|
|
|
|
|
|
const collisionInfoByTitle = mapValues(
|
|
|
|
groupNameCollisions,
|
|
|
|
conversations =>
|
|
|
|
conversations.map(conversation => ({
|
|
|
|
conversation,
|
|
|
|
oldName: getOwn(previouslyAcknowledgedTitlesById, conversation.id),
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle,
|
|
|
|
collisionInfoByTitle,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw missingCaseError(contactSpoofingReview);
|
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
};
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { id, ...actions } = 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);
|
2019-11-07 21:36:16 +00:00
|
|
|
const selectedMessage = getSelectedMessage(state);
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2022-01-26 23:05:26 +00:00
|
|
|
const messageSelector = getMessageSelector(state);
|
2022-02-07 18:54:15 +00:00
|
|
|
const getTimestampForMessage = (messageId: string): undefined | number =>
|
|
|
|
messageSelector(messageId)?.timestamp;
|
2022-01-26 23:05:26 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
return {
|
2019-05-31 22:42:01 +00:00
|
|
|
id,
|
2022-03-15 01:32:07 +00:00
|
|
|
...pick(conversation, ['unreadCount', 'isGroupV1AndDisabled']),
|
2022-03-03 20:23:10 +00:00
|
|
|
isConversationSelected: state.conversations.selectedConversationId === id,
|
2021-04-30 22:59:37 +00:00
|
|
|
isIncomingMessageRequest: Boolean(
|
|
|
|
conversation.messageRequestsEnabled &&
|
|
|
|
!conversation.acceptedMessageRequest
|
|
|
|
),
|
2022-03-09 19:15:15 +00:00
|
|
|
isSomeoneTyping: Boolean(conversation.typingContactId),
|
2019-05-31 22:42:01 +00:00
|
|
|
...conversationMessages,
|
2021-11-11 22:43:05 +00:00
|
|
|
invitedContactsForNewlyCreatedGroup:
|
|
|
|
getInvitedContactsForNewlyCreatedGroup(state),
|
2019-11-07 21:36:16 +00:00
|
|
|
selectedMessageId: selectedMessage ? selectedMessage.id : undefined,
|
2021-04-21 16:31:12 +00:00
|
|
|
|
|
|
|
warning: getWarning(conversation, state),
|
|
|
|
contactSpoofingReview: getContactSpoofingReview(id, state),
|
|
|
|
|
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),
|
2019-05-31 22:42:01 +00:00
|
|
|
renderItem,
|
2022-03-24 21:46:17 +00:00
|
|
|
renderContactSpoofingReviewDialog,
|
2020-05-27 21:37:06 +00:00
|
|
|
renderHeroRow,
|
2019-05-31 22:42:01 +00:00
|
|
|
renderTypingBubble,
|
|
|
|
...actions,
|
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);
|