// 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 { About } from '../About'; import type { GroupV2Membership } from './ConversationDetailsMembershipList'; import type { LocalizerType, ThemeType } from '../../../types/Util'; import { bemGenerator } from './util'; import { BadgeDialog } from '../../BadgeDialog'; import type { BadgeType } from '../../../badges/types'; export type Props = { badges?: ReadonlyArray; canEdit: boolean; conversation: ConversationType; i18n: LocalizerType; isGroup: boolean; isMe: boolean; memberships: Array; startEditing: (isGroupTitle: boolean) => void; theme: ThemeType; }; enum ConversationDetailsHeaderActiveModal { ShowingAvatar, ShowingBadges, } const bem = bemGenerator('ConversationDetails-header'); export const ConversationDetailsHeader: React.ComponentType = ({ badges, canEdit, conversation, i18n, isGroup, isMe, memberships, startEditing, theme, }) => { const [activeModal, setActiveModal] = useState< undefined | ConversationDetailsHeaderActiveModal >(); let preferredBadge: undefined | BadgeType; 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}
); preferredBadge = badges?.[0]; } const avatar = ( { setActiveModal(ConversationDetailsHeaderActiveModal.ShowingAvatar); }} onClickBadge={() => { setActiveModal(ConversationDetailsHeaderActiveModal.ShowingBadges); }} sharedGroupNames={[]} theme={theme} /> ); const contents = (
); let modal: ReactNode; switch (activeModal) { case ConversationDetailsHeaderActiveModal.ShowingAvatar: modal = ( { setActiveModal(undefined); }} /> ); break; case ConversationDetailsHeaderActiveModal.ShowingBadges: modal = ( { setActiveModal(undefined); }} title={conversation.title} /> ); break; default: modal = null; break; } if (canEdit) { return (
{modal} {avatar}
); } return (
{modal} {avatar} {contents}
{subtitle}
); };