import React from 'react'; import classNames from 'classnames'; import { Emojify } from './Emojify'; 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; name?: string; id: string; phoneNumber: string; profileName?: string; color: string; avatarPath?: string; isMe: boolean; isGroup: boolean; expirationSettingName?: string; showBackButton: boolean; timerOptions: Array; onSetDisappearingMessages: (seconds: number) => void; onDeleteMessages: () => void; onResetSession: () => void; onShowSafetyNumber: () => void; onShowAllMedia: () => void; onShowGroupMembers: () => void; onGoBack: () => void; } function getInitial(name: string): string { return name.trim()[0] || '#'; } 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 { name, phoneNumber, i18n, profileName, isVerified } = this.props; return (
{name ? : null} {name && phoneNumber ? ' · ' : null} {phoneNumber ? phoneNumber : null}{' '} {profileName && !name ? ( ) : null} {isVerified ? ' · ' : null} {isVerified ? ( {i18n('verified')} ) : null}
); } public renderAvatar() { const { avatarPath, color, i18n, name, phoneNumber, profileName, } = this.props; if (!avatarPath) { const initial = getInitial(name || ''); return (
{initial}
); } const title = `${name || phoneNumber}${ !name && profileName ? ` ~${profileName}` : '' }`; return ( {i18n('contactAvatarAlt', ); } 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, isMe, isGroup, onDeleteMessages, onResetSession, onSetDisappearingMessages, onShowAllMedia, onShowGroupMembers, onShowSafetyNumber, timerOptions, } = this.props; const title = i18n('disappearingMessages') as any; return ( {(timerOptions || []).map(item => ( { onSetDisappearingMessages(item.value); }} > {item.name} ))} {i18n('viewAllMedia')} {isGroup ? ( {i18n('showMembers')} ) : null} {!isGroup && !isMe ? ( {i18n('showSafetyNumber')} ) : null} {!isGroup ? ( {i18n('resetSession')} ) : null} {i18n('deleteMessages')} ); } /* tslint:enable */ public render() { const { id } = this.props; return (
{this.renderBackButton()} {this.renderAvatar()} {this.renderTitle()} {this.renderExpirationLength()} {this.renderGear(id)} {this.renderMenu(id)}
); } }