// Copyright 2020-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useEffect, useState } from 'react'; import type { Props as AvatarProps } from '../Avatar'; import { Avatar, AvatarBlur } from '../Avatar'; import { ContactName } from './ContactName'; import { About } from './About'; import { GroupDescription } from './GroupDescription'; import { SharedGroupNames } from '../SharedGroupNames'; import type { LocalizerType, ThemeType } from '../../types/Util'; import type { HasStories } from '../../types/Stories'; import type { ViewUserStoriesActionCreatorType } from '../../state/ducks/stories'; import { StoryViewModeType } from '../../types/Stories'; import { ConfirmationDialog } from '../ConfirmationDialog'; import { Button, ButtonSize, ButtonVariant } from '../Button'; import { shouldBlurAvatar } from '../../util/shouldBlurAvatar'; import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser'; export type Props = { about?: string; acceptedMessageRequest?: boolean; groupDescription?: string; hasStories?: HasStories; id: string; i18n: LocalizerType; isMe: boolean; isSignalConversation?: boolean; membersCount?: number; name?: string; phoneNumber?: string; sharedGroupNames?: Array; unblurAvatar: () => void; unblurredAvatarPath?: string; updateSharedGroups: () => unknown; theme: ThemeType; viewUserStories: ViewUserStoriesActionCreatorType; } & Omit; const renderMembershipRow = ({ acceptedMessageRequest, conversationType, i18n, isMe, onClickMessageRequestWarning, phoneNumber, sharedGroupNames, }: Pick< Props, | 'acceptedMessageRequest' | 'conversationType' | 'i18n' | 'isMe' | 'phoneNumber' > & Required> & { onClickMessageRequestWarning: () => void; }) => { const className = 'module-conversation-hero__membership'; if (conversationType !== 'direct') { return null; } if (isMe) { return
{i18n('noteToSelfHero')}
; } if (sharedGroupNames.length > 0) { return (
); } if (acceptedMessageRequest) { if (phoneNumber) { return null; } return
{i18n('no-groups-in-common')}
; } return (
{i18n('no-groups-in-common-warning')}
); }; export const ConversationHero = ({ i18n, about, acceptedMessageRequest, avatarPath, badge, color, conversationType, groupDescription, hasStories, id, isMe, isSignalConversation, membersCount, sharedGroupNames = [], name, phoneNumber, profileName, theme, title, unblurAvatar, unblurredAvatarPath, updateSharedGroups, viewUserStories, }: Props): JSX.Element => { const [isShowingMessageRequestWarning, setIsShowingMessageRequestWarning] = useState(false); const closeMessageRequestWarning = () => { setIsShowingMessageRequestWarning(false); }; useEffect(() => { // Kick off the expensive hydration of the current sharedGroupNames updateSharedGroups(); }, [updateSharedGroups]); let avatarBlur: AvatarBlur = AvatarBlur.NoBlur; let avatarOnClick: undefined | (() => void); if ( shouldBlurAvatar({ acceptedMessageRequest, avatarPath, isMe, sharedGroupNames, unblurredAvatarPath, }) ) { avatarBlur = AvatarBlur.BlurPictureWithClickToView; avatarOnClick = unblurAvatar; } else if (hasStories) { avatarOnClick = () => { viewUserStories({ conversationId: id, storyViewMode: StoryViewModeType.User, }); }; } const phoneNumberOnly = Boolean( !name && !profileName && conversationType === 'direct' ); /* eslint-disable no-nested-ternary */ return ( <>

{isMe ? ( i18n('noteToSelf') ) : ( )}

{about && !isMe && (
)} {!isMe ? (
{groupDescription ? ( ) : membersCount != null ? ( i18n('icu:ConversationHero--members', { count: membersCount }) ) : phoneNumberOnly ? null : ( phoneNumber )}
) : null} {!isSignalConversation && renderMembershipRow({ acceptedMessageRequest, conversationType, i18n, isMe, onClickMessageRequestWarning() { setIsShowingMessageRequestWarning(true); }, phoneNumber, sharedGroupNames, })} {!isSignalConversation && (
{i18n('messageHistoryUnsynced')}
)}
{isShowingMessageRequestWarning && ( { openLinkInWebBrowser( 'https://support.signal.org/hc/articles/360007459591' ); closeMessageRequestWarning(); }, }, ]} > {i18n('MessageRequestWarning__dialog__details')} )} ); /* eslint-enable no-nested-ternary */ };