// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactNode } from 'react'; import React, { useState } from 'react'; import { Avatar } from '../../Avatar'; import { AvatarLightbox } from '../../AvatarLightbox'; import type { ConversationType } from '../../../state/ducks/conversations'; import { Emojify } from '../Emojify'; import { GroupDescription } from '../GroupDescription'; import type { GroupV2Membership } from './ConversationDetailsMembershipList'; import type { LocalizerType } from '../../../types/Util'; import { bemGenerator } from './util'; export type Props = { canEdit: boolean; conversation: ConversationType; i18n: LocalizerType; isGroup: boolean; isMe: boolean; memberships: Array; startEditing: (isGroupTitle: boolean) => void; }; const bem = bemGenerator('ConversationDetails-header'); export const ConversationDetailsHeader: React.ComponentType = ({ canEdit, conversation, i18n, isGroup, isMe, memberships, startEditing, }) => { const [showingAvatar, setShowingAvatar] = useState(false); let subtitle: ReactNode; if (isGroup) { if (conversation.groupDescription) { subtitle = ( ); } else if (canEdit) { subtitle = i18n('ConversationDetailsHeader--add-group-description'); } else { subtitle = i18n('ConversationDetailsHeader--members', [ memberships.length.toString(), ]); } } else if (!isMe) { subtitle = conversation.phoneNumber; } const avatar = ( setShowingAvatar(true)} sharedGroupNames={[]} /> ); const contents = (
); const avatarLightbox = showingAvatar && !isMe ? ( setShowingAvatar(false)} /> ) : null; if (canEdit) { return (
{avatarLightbox} {avatar}
); } return (
{avatarLightbox} {avatar} {contents}
{subtitle}
); };