2018-07-18 03:25:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2018-09-27 00:23:17 +00:00
|
|
|
import { Avatar } from './Avatar';
|
2018-07-18 03:25:55 +00:00
|
|
|
import { MessageBody } from './conversation/MessageBody';
|
|
|
|
import { Timestamp } from './conversation/Timestamp';
|
|
|
|
import { ContactName } from './conversation/ContactName';
|
2018-11-14 19:10:32 +00:00
|
|
|
import { TypingAnimation } from './conversation/TypingAnimation';
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { LocalizerType } from '../types/Util';
|
2018-07-18 03:25:55 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export type PropsData = {
|
|
|
|
id: string;
|
2018-07-18 03:25:55 +00:00
|
|
|
phoneNumber: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
color?: string;
|
2018-07-18 03:25:55 +00:00
|
|
|
profileName?: string;
|
|
|
|
name?: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'group' | 'direct';
|
2018-07-18 03:25:55 +00:00
|
|
|
avatarPath?: string;
|
2019-01-31 01:45:58 +00:00
|
|
|
isMe: boolean;
|
2018-07-18 03:25:55 +00:00
|
|
|
|
|
|
|
lastUpdated: number;
|
2018-07-20 23:37:57 +00:00
|
|
|
unreadCount: number;
|
2018-07-18 03:25:55 +00:00
|
|
|
isSelected: boolean;
|
|
|
|
|
2018-11-14 19:10:32 +00:00
|
|
|
isTyping: boolean;
|
2018-07-18 03:25:55 +00:00
|
|
|
lastMessage?: {
|
|
|
|
status: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
|
|
|
|
text: string;
|
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2018-07-18 03:25:55 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
type PropsHousekeeping = {
|
|
|
|
i18n: LocalizerType;
|
2019-03-09 02:25:28 +00:00
|
|
|
style?: Object;
|
2019-01-14 21:49:58 +00:00
|
|
|
onClick?: (id: string) => void;
|
|
|
|
};
|
2018-07-18 03:25:55 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
type Props = PropsData & PropsHousekeeping;
|
|
|
|
|
|
|
|
export class ConversationListItem extends React.PureComponent<Props> {
|
2018-07-18 03:25:55 +00:00
|
|
|
public renderAvatar() {
|
|
|
|
const {
|
|
|
|
avatarPath,
|
|
|
|
color,
|
2019-01-14 21:49:58 +00:00
|
|
|
type,
|
2018-07-18 03:25:55 +00:00
|
|
|
i18n,
|
2019-01-31 01:45:58 +00:00
|
|
|
isMe,
|
2018-07-18 03:25:55 +00:00
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
2018-09-26 22:55:13 +00:00
|
|
|
<div className="module-conversation-list-item__avatar-container">
|
2018-09-27 00:23:17 +00:00
|
|
|
<Avatar
|
|
|
|
avatarPath={avatarPath}
|
|
|
|
color={color}
|
2019-01-31 01:45:58 +00:00
|
|
|
noteToSelf={isMe}
|
2019-01-14 21:49:58 +00:00
|
|
|
conversationType={type}
|
2018-09-27 00:23:17 +00:00
|
|
|
i18n={i18n}
|
|
|
|
name={name}
|
|
|
|
phoneNumber={phoneNumber}
|
|
|
|
profileName={profileName}
|
|
|
|
size={48}
|
2018-09-26 22:55:13 +00:00
|
|
|
/>
|
|
|
|
{this.renderUnread()}
|
|
|
|
</div>
|
2018-07-18 03:25:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-26 22:55:13 +00:00
|
|
|
public renderUnread() {
|
|
|
|
const { unreadCount } = this.props;
|
|
|
|
|
|
|
|
if (unreadCount > 0) {
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-list-item__unread-count">
|
|
|
|
{unreadCount}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-18 03:25:55 +00:00
|
|
|
public renderHeader() {
|
2018-07-20 23:37:57 +00:00
|
|
|
const {
|
|
|
|
unreadCount,
|
|
|
|
i18n,
|
2019-01-31 01:45:58 +00:00
|
|
|
isMe,
|
2018-07-20 23:37:57 +00:00
|
|
|
lastUpdated,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
} = this.props;
|
2018-07-18 03:25:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-list-item__header">
|
2018-07-26 22:02:39 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__header__name',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__header__name--with-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2019-01-31 01:45:58 +00:00
|
|
|
{isMe ? (
|
|
|
|
i18n('noteToSelf')
|
|
|
|
) : (
|
|
|
|
<ContactName
|
|
|
|
phoneNumber={phoneNumber}
|
|
|
|
name={name}
|
|
|
|
profileName={profileName}
|
|
|
|
/>
|
|
|
|
)}
|
2018-07-18 03:25:55 +00:00
|
|
|
</div>
|
2018-07-20 23:37:57 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__header__date',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__header__date--has-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2018-07-18 03:25:55 +00:00
|
|
|
<Timestamp
|
|
|
|
timestamp={lastUpdated}
|
|
|
|
extended={false}
|
|
|
|
module="module-conversation-list-item__header__timestamp"
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderMessage() {
|
2018-11-14 19:10:32 +00:00
|
|
|
const { lastMessage, isTyping, unreadCount, i18n } = this.props;
|
|
|
|
if (!lastMessage && !isTyping) {
|
2018-07-18 03:25:55 +00:00
|
|
|
return null;
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
const text = lastMessage && lastMessage.text ? lastMessage.text : '';
|
2018-07-18 03:25:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-conversation-list-item__message">
|
2018-07-27 01:13:56 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__message__text',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__message__text--has-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2018-11-14 19:10:32 +00:00
|
|
|
{isTyping ? (
|
|
|
|
<TypingAnimation i18n={i18n} />
|
|
|
|
) : (
|
|
|
|
<MessageBody
|
2019-01-14 21:49:58 +00:00
|
|
|
text={text}
|
2018-11-14 19:10:32 +00:00
|
|
|
disableJumbomoji={true}
|
|
|
|
disableLinks={true}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
)}
|
2018-07-27 01:13:56 +00:00
|
|
|
</div>
|
2018-11-14 19:10:32 +00:00
|
|
|
{lastMessage && lastMessage.status ? (
|
2018-07-18 03:25:55 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__message__status-icon',
|
|
|
|
`module-conversation-list-item__message__status-icon--${
|
|
|
|
lastMessage.status
|
|
|
|
}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2019-03-09 02:25:28 +00:00
|
|
|
const { unreadCount, onClick, id, isSelected, style } = this.props;
|
2018-07-18 03:25:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="button"
|
2019-01-14 21:49:58 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (onClick) {
|
|
|
|
onClick(id);
|
|
|
|
}
|
|
|
|
}}
|
2019-03-09 02:25:28 +00:00
|
|
|
style={style}
|
2018-07-18 03:25:55 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item',
|
2018-07-20 23:37:57 +00:00
|
|
|
unreadCount > 0 ? 'module-conversation-list-item--has-unread' : null,
|
2018-07-18 03:25:55 +00:00
|
|
|
isSelected ? 'module-conversation-list-item--is-selected' : null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.renderAvatar()}
|
|
|
|
<div className="module-conversation-list-item__content">
|
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderMessage()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|