import React from 'react'; import { ContactName } from './ContactName'; import { Avatar } from '../Avatar'; import { Localizer } from '../../types/Util'; import { ContextMenu, ContextMenuTrigger, MenuItem, SubMenu, } from 'react-contextmenu'; interface TimerOption { name: string; value: number; } interface Trigger { handleContextClick: (event: React.MouseEvent) => void; } interface Props { i18n: Localizer; isVerified: boolean; isKeysPending: boolean; name?: string; id: string; phoneNumber: string; profileName?: string; color: string; avatarPath?: string; isBlocked: boolean; isMe: boolean; isGroup: boolean; expirationSettingName?: string; showBackButton: boolean; timerOptions: Array; hasNickname?: boolean; onSetDisappearingMessages: (seconds: number) => void; onDeleteMessages: () => void; onResetSession: () => void; onShowSafetyNumber: () => void; onShowAllMedia: () => void; onShowGroupMembers: () => void; onGoBack: () => void; onBlockUser: () => void; onUnblockUser: () => void; onClearNickname: () => void; onChangeNickname: () => void; onCopyPublicKey: () => void; } export class ConversationHeader extends React.Component { public captureMenuTriggerBound: (trigger: any) => void; public showMenuBound: (event: React.MouseEvent) => void; public menuTriggerRef: Trigger | null; public constructor(props: Props) { super(props); this.captureMenuTriggerBound = this.captureMenuTrigger.bind(this); this.showMenuBound = this.showMenu.bind(this); this.menuTriggerRef = null; } public captureMenuTrigger(triggerRef: Trigger) { this.menuTriggerRef = triggerRef; } public showMenu(event: React.MouseEvent) { if (this.menuTriggerRef) { this.menuTriggerRef.handleContextClick(event); } } public renderBackButton() { const { onGoBack, showBackButton } = this.props; if (!showBackButton) { return null; } return (
); } public renderTitle() { const { phoneNumber, i18n, profileName, isKeysPending, } = this.props; return (
{isKeysPending ? '(pending)' : null}
); } public renderAvatar() { const { avatarPath, color, i18n, isGroup, name, phoneNumber, profileName, } = this.props; 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 (
); } /* tslint:disable:jsx-no-lambda react-this-binding-issue */ public renderMenu(triggerId: string) { const { i18n, isBlocked, isMe, isGroup, onDeleteMessages, onResetSession, onSetDisappearingMessages, onShowAllMedia, onShowGroupMembers, onShowSafetyNumber, 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')} {i18n('deleteMessages')} ); } /* tslint:enable */ public render() { const { id } = this.props; const triggerId = `${id}-${Date.now()}`; return (
{this.renderBackButton()}
{this.renderAvatar()} {this.renderTitle()}
{this.renderExpirationLength()} {this.renderGear(triggerId)} {this.renderMenu(triggerId)}
); } }