2018-07-09 21:29:13 +00:00
|
|
|
import React from 'react';
|
2019-07-31 16:16:29 +00:00
|
|
|
import classNames from 'classnames';
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
import { Emojify } from './Emojify';
|
2018-09-27 00:23:17 +00:00
|
|
|
import { Avatar } from '../Avatar';
|
2020-03-26 21:47:35 +00:00
|
|
|
import { ColorType, LocalizerType } from '../../types/Util';
|
2018-07-09 21:29:13 +00:00
|
|
|
import {
|
|
|
|
ContextMenu,
|
|
|
|
ContextMenuTrigger,
|
|
|
|
MenuItem,
|
|
|
|
SubMenu,
|
|
|
|
} from 'react-contextmenu';
|
|
|
|
|
|
|
|
interface TimerOption {
|
|
|
|
name: string;
|
|
|
|
value: number;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:47:35 +00:00
|
|
|
export interface PropsData {
|
2018-07-09 21:29:13 +00:00
|
|
|
id: string;
|
2019-03-12 00:20:16 +00:00
|
|
|
name?: string;
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
phoneNumber: string;
|
|
|
|
profileName?: string;
|
2020-03-26 21:47:35 +00:00
|
|
|
color?: ColorType;
|
2018-07-09 21:29:13 +00:00
|
|
|
avatarPath?: string;
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2020-05-27 21:37:06 +00:00
|
|
|
isAccepted?: boolean;
|
2020-03-26 21:47:35 +00:00
|
|
|
isVerified?: boolean;
|
|
|
|
isMe?: boolean;
|
|
|
|
isGroup?: boolean;
|
|
|
|
isArchived?: boolean;
|
|
|
|
leftGroup?: boolean;
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
expirationSettingName?: string;
|
2020-03-26 21:47:35 +00:00
|
|
|
showBackButton?: boolean;
|
|
|
|
timerOptions?: Array<TimerOption>;
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
|
2020-03-26 21:47:35 +00:00
|
|
|
export interface PropsActions {
|
2018-07-09 21:29:13 +00:00
|
|
|
onSetDisappearingMessages: (seconds: number) => void;
|
|
|
|
onDeleteMessages: () => void;
|
|
|
|
onResetSession: () => void;
|
2019-08-09 23:12:29 +00:00
|
|
|
onSearchInConversation: () => void;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
onShowSafetyNumber: () => void;
|
|
|
|
onShowAllMedia: () => void;
|
|
|
|
onShowGroupMembers: () => void;
|
|
|
|
onGoBack: () => void;
|
2019-03-12 00:20:16 +00:00
|
|
|
|
|
|
|
onArchive: () => void;
|
|
|
|
onMoveToInbox: () => void;
|
2020-03-26 21:47:35 +00:00
|
|
|
}
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2020-03-26 21:47:35 +00:00
|
|
|
export interface PropsHousekeeping {
|
2019-03-12 00:20:16 +00:00
|
|
|
i18n: LocalizerType;
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 21:47:35 +00:00
|
|
|
export type Props = PropsData & PropsActions & PropsHousekeeping;
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
export class ConversationHeader extends React.Component<Props> {
|
2019-07-25 16:24:03 +00:00
|
|
|
public showMenuBound: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
2019-01-14 21:49:58 +00:00
|
|
|
public menuTriggerRef: React.RefObject<any>;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
this.menuTriggerRef = React.createRef();
|
2018-07-09 21:29:13 +00:00
|
|
|
this.showMenuBound = this.showMenu.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:24:03 +00:00
|
|
|
public showMenu(event: React.MouseEvent<HTMLButtonElement>) {
|
2019-01-14 21:49:58 +00:00
|
|
|
if (this.menuTriggerRef.current) {
|
|
|
|
this.menuTriggerRef.current.handleContextClick(event);
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderBackButton() {
|
|
|
|
const { onGoBack, showBackButton } = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-07-25 16:24:03 +00:00
|
|
|
<button
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={onGoBack}
|
2019-07-31 16:16:29 +00:00
|
|
|
className={classNames(
|
2019-07-25 16:24:03 +00:00
|
|
|
'module-conversation-header__back-icon',
|
|
|
|
showBackButton ? 'module-conversation-header__back-icon--show' : null
|
|
|
|
)}
|
|
|
|
disabled={!showBackButton}
|
2018-07-09 21:29:13 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderTitle() {
|
2019-01-31 01:45:58 +00:00
|
|
|
const {
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
i18n,
|
|
|
|
isMe,
|
|
|
|
profileName,
|
|
|
|
isVerified,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (isMe) {
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-header__title">
|
|
|
|
{i18n('noteToSelf')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-header__title">
|
2019-06-27 20:35:21 +00:00
|
|
|
{name ? <Emojify text={name} /> : null}
|
2018-07-09 21:29:13 +00:00
|
|
|
{name && phoneNumber ? ' · ' : null}
|
|
|
|
{phoneNumber ? phoneNumber : null}{' '}
|
|
|
|
{profileName && !name ? (
|
|
|
|
<span className="module-conversation-header__title__profile-name">
|
2019-06-27 20:35:21 +00:00
|
|
|
~<Emojify text={profileName} />
|
2018-07-09 21:29:13 +00:00
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
{isVerified ? ' · ' : null}
|
|
|
|
{isVerified ? (
|
|
|
|
<span>
|
|
|
|
<span className="module-conversation-header__title__verified-icon" />
|
|
|
|
{i18n('verified')}
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAvatar() {
|
|
|
|
const {
|
|
|
|
avatarPath,
|
|
|
|
color,
|
|
|
|
i18n,
|
2018-09-27 00:23:17 +00:00
|
|
|
isGroup,
|
2019-01-31 01:45:58 +00:00
|
|
|
isMe,
|
2018-07-09 21:29:13 +00:00
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
} = this.props;
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
const conversationType = isGroup ? 'group' : 'direct';
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
return (
|
2018-09-27 00:23:17 +00:00
|
|
|
<span className="module-conversation-header__avatar">
|
|
|
|
<Avatar
|
|
|
|
avatarPath={avatarPath}
|
|
|
|
color={color}
|
2019-01-14 21:49:58 +00:00
|
|
|
conversationType={conversationType}
|
2018-09-27 00:23:17 +00:00
|
|
|
i18n={i18n}
|
2019-01-31 01:45:58 +00:00
|
|
|
noteToSelf={isMe}
|
2018-09-27 00:23:17 +00:00
|
|
|
name={name}
|
|
|
|
phoneNumber={phoneNumber}
|
|
|
|
profileName={profileName}
|
|
|
|
size={28}
|
|
|
|
/>
|
|
|
|
</span>
|
2018-07-09 21:29:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderExpirationLength() {
|
2019-08-09 23:12:29 +00:00
|
|
|
const { expirationSettingName, showBackButton } = this.props;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
if (!expirationSettingName) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-08-09 23:12:29 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-header__expiration',
|
|
|
|
showBackButton
|
|
|
|
? 'module-conversation-header__expiration--hidden'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2018-07-09 21:29:13 +00:00
|
|
|
<div className="module-conversation-header__expiration__clock-icon" />
|
|
|
|
<div className="module-conversation-header__expiration__setting">
|
|
|
|
{expirationSettingName}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:12:29 +00:00
|
|
|
public renderMoreButton(triggerId: string) {
|
2018-07-09 21:29:13 +00:00
|
|
|
const { showBackButton } = this.props;
|
|
|
|
|
|
|
|
return (
|
2019-01-14 21:49:58 +00:00
|
|
|
<ContextMenuTrigger id={triggerId} ref={this.menuTriggerRef}>
|
2019-07-25 16:24:03 +00:00
|
|
|
<button
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={this.showMenuBound}
|
2019-07-31 16:16:29 +00:00
|
|
|
className={classNames(
|
2019-08-09 23:12:29 +00:00
|
|
|
'module-conversation-header__more-button',
|
2019-07-25 16:24:03 +00:00
|
|
|
showBackButton
|
|
|
|
? null
|
2019-08-09 23:12:29 +00:00
|
|
|
: 'module-conversation-header__more-button--show'
|
2019-07-25 16:24:03 +00:00
|
|
|
)}
|
|
|
|
disabled={showBackButton}
|
2018-07-09 21:29:13 +00:00
|
|
|
/>
|
|
|
|
</ContextMenuTrigger>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:12:29 +00:00
|
|
|
public renderSearchButton() {
|
|
|
|
const { onSearchInConversation, showBackButton } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
onClick={onSearchInConversation}
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-header__search-button',
|
|
|
|
showBackButton
|
|
|
|
? null
|
|
|
|
: 'module-conversation-header__search-button--show'
|
|
|
|
)}
|
|
|
|
disabled={showBackButton}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
public renderMenu(triggerId: string) {
|
|
|
|
const {
|
|
|
|
i18n,
|
2020-05-27 21:37:06 +00:00
|
|
|
isAccepted,
|
2018-07-09 21:29:13 +00:00
|
|
|
isMe,
|
|
|
|
isGroup,
|
2019-03-12 00:20:16 +00:00
|
|
|
isArchived,
|
2020-03-26 21:47:35 +00:00
|
|
|
leftGroup,
|
2018-07-09 21:29:13 +00:00
|
|
|
onDeleteMessages,
|
|
|
|
onResetSession,
|
|
|
|
onSetDisappearingMessages,
|
|
|
|
onShowAllMedia,
|
|
|
|
onShowGroupMembers,
|
|
|
|
onShowSafetyNumber,
|
2019-03-12 00:20:16 +00:00
|
|
|
onArchive,
|
|
|
|
onMoveToInbox,
|
2018-07-09 21:29:13 +00:00
|
|
|
timerOptions,
|
|
|
|
} = this.props;
|
|
|
|
|
2018-08-01 18:59:49 +00:00
|
|
|
const disappearingTitle = i18n('disappearingMessages') as any;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ContextMenu id={triggerId}>
|
2020-05-27 21:37:06 +00:00
|
|
|
{!leftGroup && isAccepted ? (
|
2020-03-26 21:47:35 +00:00
|
|
|
<SubMenu title={disappearingTitle}>
|
|
|
|
{(timerOptions || []).map(item => (
|
|
|
|
<MenuItem
|
|
|
|
key={item.value}
|
|
|
|
onClick={() => {
|
|
|
|
onSetDisappearingMessages(item.value);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{item.name}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</SubMenu>
|
2020-05-27 21:37:06 +00:00
|
|
|
) : null}
|
2020-06-09 19:54:09 +00:00
|
|
|
<MenuItem onClick={onShowAllMedia}>{i18n('viewRecentMedia')}</MenuItem>
|
2018-07-09 21:29:13 +00:00
|
|
|
{isGroup ? (
|
|
|
|
<MenuItem onClick={onShowGroupMembers}>
|
|
|
|
{i18n('showMembers')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
|
|
|
{!isGroup && !isMe ? (
|
|
|
|
<MenuItem onClick={onShowSafetyNumber}>
|
|
|
|
{i18n('showSafetyNumber')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
2020-05-27 21:37:06 +00:00
|
|
|
{!isGroup && isAccepted ? (
|
2018-07-09 21:29:13 +00:00
|
|
|
<MenuItem onClick={onResetSession}>{i18n('resetSession')}</MenuItem>
|
|
|
|
) : null}
|
2019-03-12 00:20:16 +00:00
|
|
|
{isArchived ? (
|
|
|
|
<MenuItem onClick={onMoveToInbox}>
|
|
|
|
{i18n('moveConversationToInbox')}
|
|
|
|
</MenuItem>
|
|
|
|
) : (
|
|
|
|
<MenuItem onClick={onArchive}>{i18n('archiveConversation')}</MenuItem>
|
|
|
|
)}
|
2018-07-09 21:29:13 +00:00
|
|
|
<MenuItem onClick={onDeleteMessages}>{i18n('deleteMessages')}</MenuItem>
|
|
|
|
</ContextMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const { id } = this.props;
|
2019-01-14 21:49:58 +00:00
|
|
|
const triggerId = `conversation-${id}`;
|
2018-07-09 21:29:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-header">
|
|
|
|
{this.renderBackButton()}
|
2018-07-26 22:02:39 +00:00
|
|
|
<div className="module-conversation-header__title-container">
|
|
|
|
<div className="module-conversation-header__title-flex">
|
|
|
|
{this.renderAvatar()}
|
|
|
|
{this.renderTitle()}
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-07-09 21:29:13 +00:00
|
|
|
{this.renderExpirationLength()}
|
2019-08-09 23:12:29 +00:00
|
|
|
{this.renderSearchButton()}
|
|
|
|
{this.renderMoreButton(triggerId)}
|
2019-01-14 21:49:58 +00:00
|
|
|
{this.renderMenu(triggerId)}
|
2018-07-09 21:29:13 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|