import React from 'react'; import { ContactName } from './ContactName'; import { Avatar } from '../Avatar'; import { Colors, LocalizerType } from '../../types/Util'; import { ContextMenu, ContextMenuTrigger, MenuItem, SubMenu, } from 'react-contextmenu'; interface TimerOption { name: string; value: number; } interface Props { id: string; name?: string; phoneNumber: string; profileName?: string; color: string; avatarPath?: string; isVerified: boolean; isMe: boolean; isClosable?: boolean; isGroup: boolean; isArchived: boolean; expirationSettingName?: string; showBackButton: boolean; timerOptions: Array; hasNickname?: boolean; isBlocked: boolean; isKeysPending: boolean; isOnline?: boolean; onSetDisappearingMessages: (seconds: number) => void; onDeleteMessages: () => void; onDeleteContact: () => void; onResetSession: () => void; onArchive: () => void; onMoveToInbox: () => void; onShowSafetyNumber: () => void; onShowAllMedia: () => void; onShowGroupMembers: () => void; onGoBack: () => void; onBlockUser: () => void; onUnblockUser: () => void; onClearNickname: () => void; onChangeNickname: () => void; onCopyPublicKey: () => void; i18n: LocalizerType; } export class ConversationHeader extends React.Component { public showMenuBound: (event: React.MouseEvent) => void; public menuTriggerRef: React.RefObject; public constructor(props: Props) { super(props); this.menuTriggerRef = React.createRef(); this.showMenuBound = this.showMenu.bind(this); } public showMenu(event: React.MouseEvent) { if (this.menuTriggerRef.current) { this.menuTriggerRef.current.handleContextClick(event); } } public renderBackButton() { const { onGoBack, showBackButton } = this.props; if (!showBackButton) { return null; } return (
); } public renderTitle() { const { phoneNumber, i18n, profileName, isKeysPending, isMe, name, } = this.props; if (isMe) { return (
{i18n('noteToSelf')}
); } return (
{isKeysPending ? '(pending)' : null}
); } public renderAvatar() { const { avatarPath, color, i18n, isGroup, isMe, name, phoneNumber, profileName, isOnline, } = this.props; const borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE_LIGHT; const conversationType = isGroup ? 'group' : 'direct'; return ( ); } public renderExpirationLength() { const { expirationSettingName } = this.props; if (!expirationSettingName) { return null; } return (
{expirationSettingName}
); } public renderGear(triggerId: string) { const { showBackButton } = this.props; if (showBackButton) { return null; } return (
); } public renderMenu(triggerId: string) { const { i18n, isBlocked, isMe, isClosable, isGroup, isArchived, onDeleteMessages, onDeleteContact, onResetSession, onSetDisappearingMessages, // onShowAllMedia, onShowGroupMembers, onShowSafetyNumber, onArchive, onMoveToInbox, timerOptions, onBlockUser, onUnblockUser, hasNickname, onClearNickname, onChangeNickname, onCopyPublicKey, } = this.props; const disappearingTitle = i18n('disappearingMessages') as any; const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); const blockHandler = isBlocked ? onUnblockUser : onBlockUser; return ( {(timerOptions || []).map(item => ( { onSetDisappearingMessages(item.value); }} > {item.name} ))} {/* {i18n('viewAllMedia')} */} {isGroup ? ( {i18n('showMembers')} ) : null} {!isGroup && !isMe ? ( {i18n('showSafetyNumber')} ) : null} {!isGroup ? ( {i18n('resetSession')} ) : null} {/* Only show the block on other conversations */} {!isMe ? ( {blockTitle} ) : null} {!isMe ? ( {i18n('changeNickname')} ) : null} {!isMe && hasNickname ? ( {i18n('clearNickname')} ) : null} {i18n('copyPublicKey')} {isArchived ? ( {i18n('moveConversationToInbox')} ) : ( {i18n('archiveConversation')} )} {i18n('deleteMessages')} {!isMe && isClosable ? ( {i18n('deleteContact')} ) : null} ); } public render() { const { id } = this.props; const triggerId = `conversation-${id}`; return (
{this.renderBackButton()}
{this.renderAvatar()} {this.renderTitle()}
{this.renderExpirationLength()} {this.renderGear(triggerId)} {this.renderMenu(triggerId)}
); } }