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; isPublic: 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, isMe, isClosable, isPublic, onDeleteMessages, onDeleteContact, onCopyPublicKey, } = this.props; return ( {this.renderPublicMenuItems()} {i18n('copyPublicKey')} {i18n('deleteMessages')} {!isMe && isClosable ? ( !isPublic ? ( {i18n('deleteContact')} ) : ( {i18n('deletePublicChannel')} ) ) : 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)}
); } private renderPublicMenuItems() { const { i18n, isBlocked, isMe, isGroup, isArchived, isPublic, onResetSession, onSetDisappearingMessages, // onShowAllMedia, onShowGroupMembers, onShowSafetyNumber, onArchive, onMoveToInbox, timerOptions, onBlockUser, onUnblockUser, hasNickname, onClearNickname, onChangeNickname, } = this.props; if (isPublic) { return null; } const disappearingTitle = i18n('disappearingMessages') as any; const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); const blockHandler = isBlocked ? onUnblockUser : onBlockUser; const disappearingMessagesMenuItem = ( {(timerOptions || []).map(item => ( { onSetDisappearingMessages(item.value); }} > {item.name} ))} ); const showMembersMenuItem = isGroup && ( {i18n('showMembers')} ); const showSafetyNumberMenuItem = !isGroup && !isMe && ( {i18n('showSafetyNumber')} ); const resetSessionMenuItem = !isGroup && ( {i18n('resetSession')} ); const blockHandlerMenuItem = !isMe && ( {blockTitle} ); const changeNicknameMenuItem = !isMe && ( {i18n('changeNickname')} ); const clearNicknameMenuItem = !isMe && hasNickname && ( {i18n('clearNickname')} ); const archiveConversationMenuItem = isArchived ? ( {i18n('moveConversationToInbox')} ) : ( {i18n('archiveConversation')} ); return ( {/* {i18n('viewAllMedia')} */} {disappearingMessagesMenuItem} {showMembersMenuItem} {showSafetyNumberMenuItem} {resetSessionMenuItem} {blockHandlerMenuItem} {changeNicknameMenuItem} {clearNicknameMenuItem} {archiveConversationMenuItem} ); } }