2018-07-18 05:25:55 +02:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
2019-04-18 05:48:13 +02:00
|
|
|
import { isEmpty } from 'lodash';
|
2020-12-01 00:32:56 +01:00
|
|
|
import { contextMenu } from 'react-contexify';
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2018-09-27 02:23:17 +02:00
|
|
|
import { Avatar } from './Avatar';
|
2018-07-18 05:25:55 +02:00
|
|
|
import { MessageBody } from './conversation/MessageBody';
|
|
|
|
import { Timestamp } from './conversation/Timestamp';
|
|
|
|
import { ContactName } from './conversation/ContactName';
|
2018-11-14 20:10:32 +01:00
|
|
|
import { TypingAnimation } from './conversation/TypingAnimation';
|
|
|
|
|
2020-09-11 07:06:13 +02:00
|
|
|
import { LocalizerType } from '../types/Util';
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2020-09-15 08:38:24 +02:00
|
|
|
import {
|
|
|
|
ConversationAvatar,
|
|
|
|
usingClosedConversationDetails,
|
|
|
|
} from './session/usingClosedConversationDetails';
|
2020-10-22 07:34:41 +02:00
|
|
|
import {
|
|
|
|
ConversationListItemContextMenu,
|
|
|
|
PropsContextConversationItem,
|
|
|
|
} from './session/menu/ConversationListItemContextMenu';
|
2020-12-01 00:32:56 +01:00
|
|
|
import { createPortal } from 'react-dom';
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2019-01-14 22:49:58 +01:00
|
|
|
export type PropsData = {
|
|
|
|
id: string;
|
2018-07-18 05:25:55 +02:00
|
|
|
phoneNumber: string;
|
2019-01-14 22:49:58 +01:00
|
|
|
color?: string;
|
2018-07-18 05:25:55 +02:00
|
|
|
profileName?: string;
|
|
|
|
name?: string;
|
2019-01-14 22:49:58 +01:00
|
|
|
type: 'group' | 'direct';
|
2018-07-18 05:25:55 +02:00
|
|
|
avatarPath?: string;
|
2019-01-31 02:45:58 +01:00
|
|
|
isMe: boolean;
|
2019-09-03 09:38:11 +02:00
|
|
|
isPublic?: boolean;
|
2020-02-05 08:09:53 +01:00
|
|
|
isRss?: boolean;
|
2019-08-23 06:23:21 +02:00
|
|
|
isClosable?: boolean;
|
2020-05-14 07:13:06 +02:00
|
|
|
primaryDevice?: string;
|
2018-07-18 05:25:55 +02:00
|
|
|
|
|
|
|
lastUpdated: number;
|
2018-07-21 01:37:57 +02:00
|
|
|
unreadCount: number;
|
2019-10-02 05:28:10 +02:00
|
|
|
mentionedUs: boolean;
|
2018-07-18 05:25:55 +02:00
|
|
|
isSelected: boolean;
|
|
|
|
|
2018-11-14 20:10:32 +01:00
|
|
|
isTyping: boolean;
|
2018-07-18 05:25:55 +02:00
|
|
|
lastMessage?: {
|
|
|
|
status: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
|
|
|
|
text: string;
|
2019-07-23 08:15:39 +02:00
|
|
|
isRss: boolean;
|
2018-07-18 05:25:55 +02:00
|
|
|
};
|
2019-04-17 08:30:15 +02:00
|
|
|
|
|
|
|
isBlocked?: boolean;
|
|
|
|
isOnline?: boolean;
|
|
|
|
hasNickname?: boolean;
|
2019-10-28 02:03:09 +01:00
|
|
|
isSecondary?: boolean;
|
2019-11-22 06:16:43 +01:00
|
|
|
isGroupInvitation?: boolean;
|
2020-07-24 08:38:03 +02:00
|
|
|
isKickedFromGroup?: boolean;
|
2020-09-15 08:38:24 +02:00
|
|
|
memberAvatars?: Array<ConversationAvatar>; // this is added by usingClosedConversationDetails
|
2019-01-14 22:49:58 +01:00
|
|
|
};
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2019-01-14 22:49:58 +01:00
|
|
|
type PropsHousekeeping = {
|
|
|
|
i18n: LocalizerType;
|
2019-03-09 03:25:28 +01:00
|
|
|
style?: Object;
|
2019-01-14 22:49:58 +01:00
|
|
|
onClick?: (id: string) => void;
|
2019-03-07 02:14:44 +01:00
|
|
|
onDeleteMessages?: () => void;
|
|
|
|
onDeleteContact?: () => void;
|
|
|
|
onBlockContact?: () => void;
|
2019-03-08 06:16:10 +01:00
|
|
|
onCopyPublicKey?: () => void;
|
2019-03-07 02:14:44 +01:00
|
|
|
onUnblockContact?: () => void;
|
2020-07-24 08:38:03 +02:00
|
|
|
onInviteContacts?: () => void;
|
2020-08-10 07:11:32 +02:00
|
|
|
onClearNickname?: () => void;
|
2019-01-14 22:49:58 +01:00
|
|
|
};
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2019-01-14 22:49:58 +01:00
|
|
|
type Props = PropsData & PropsHousekeeping;
|
|
|
|
|
2020-12-01 00:32:56 +01:00
|
|
|
const Portal = ({ children }: { children: any }) => {
|
|
|
|
return createPortal(children, document.querySelector('.inbox.index') as Element);
|
|
|
|
}
|
|
|
|
|
2020-09-14 08:06:24 +02:00
|
|
|
class ConversationListItem extends React.PureComponent<Props> {
|
2020-09-11 07:06:13 +02:00
|
|
|
public constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2018-07-18 05:25:55 +02:00
|
|
|
public renderAvatar() {
|
|
|
|
const {
|
|
|
|
avatarPath,
|
|
|
|
i18n,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
2020-09-15 08:38:24 +02:00
|
|
|
memberAvatars,
|
2018-07-18 05:25:55 +02:00
|
|
|
} = this.props;
|
|
|
|
|
2020-06-15 10:05:14 +02:00
|
|
|
const iconSize = 36;
|
2020-09-15 07:07:22 +02:00
|
|
|
const userName = name || profileName || phoneNumber;
|
2019-02-05 04:18:04 +01:00
|
|
|
|
2018-07-18 05:25:55 +02:00
|
|
|
return (
|
2018-09-27 00:55:13 +02:00
|
|
|
<div className="module-conversation-list-item__avatar-container">
|
2018-09-27 02:23:17 +02:00
|
|
|
<Avatar
|
|
|
|
avatarPath={avatarPath}
|
2020-09-15 07:07:22 +02:00
|
|
|
name={userName}
|
2020-01-02 03:21:37 +01:00
|
|
|
size={iconSize}
|
2020-09-15 08:38:24 +02:00
|
|
|
memberAvatars={memberAvatars}
|
2020-09-15 07:07:22 +02:00
|
|
|
pubkey={phoneNumber}
|
2018-09-27 00:55:13 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2018-07-18 05:25:55 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-25 06:13:32 +02:00
|
|
|
public renderHeader() {
|
|
|
|
const { unreadCount, mentionedUs, i18n, isMe, lastUpdated } = this.props;
|
2018-09-27 00:55:13 +02:00
|
|
|
|
2020-09-25 06:13:32 +02:00
|
|
|
let atSymbol = null;
|
|
|
|
let unreadCountDiv = null;
|
2018-09-27 00:55:13 +02:00
|
|
|
if (unreadCount > 0) {
|
2020-09-25 06:13:32 +02:00
|
|
|
atSymbol = mentionedUs ? <p className="at-symbol">@</p> : null;
|
|
|
|
unreadCountDiv = (
|
|
|
|
<p className="module-conversation-list-item__unread-count">
|
|
|
|
{unreadCount}
|
|
|
|
</p>
|
2018-09-27 00:55:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-18 05:25:55 +02:00
|
|
|
return (
|
|
|
|
<div className="module-conversation-list-item__header">
|
2018-07-27 00:02:39 +02:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__header__name',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__header__name--with-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2020-09-10 07:52:36 +02:00
|
|
|
{this.renderUser()}
|
2018-07-18 05:25:55 +02:00
|
|
|
</div>
|
2020-09-25 06:13:32 +02:00
|
|
|
{unreadCountDiv}
|
|
|
|
{atSymbol}
|
2020-06-16 02:00:37 +02:00
|
|
|
{
|
2019-04-18 05:48:13 +02:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__header__date',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__header__date--has-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2020-06-16 02:00:37 +02:00
|
|
|
{
|
2020-01-03 01:49:42 +01:00
|
|
|
<Timestamp
|
|
|
|
timestamp={lastUpdated}
|
|
|
|
extended={false}
|
|
|
|
module="module-conversation-list-item__header__timestamp"
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
2020-06-16 02:00:37 +02:00
|
|
|
}
|
2019-04-18 05:48:13 +02:00
|
|
|
</div>
|
2020-06-16 02:00:37 +02:00
|
|
|
}
|
2018-07-18 05:25:55 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderMessage() {
|
2020-06-16 02:00:37 +02:00
|
|
|
const { lastMessage, isTyping, unreadCount, i18n } = this.props;
|
2019-04-18 05:48:13 +02:00
|
|
|
|
2018-11-14 20:10:32 +01:00
|
|
|
if (!lastMessage && !isTyping) {
|
2018-07-18 05:25:55 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-07-23 08:15:39 +02:00
|
|
|
let text = lastMessage && lastMessage.text ? lastMessage.text : '';
|
|
|
|
|
|
|
|
// if coming from Rss feed
|
|
|
|
if (lastMessage && lastMessage.isRss) {
|
|
|
|
// strip any HTML
|
|
|
|
text = text.replace(/<[^>]*>?/gm, '');
|
|
|
|
}
|
2018-07-18 05:25:55 +02:00
|
|
|
|
2019-04-18 05:48:13 +02:00
|
|
|
if (isEmpty(text)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-18 05:25:55 +02:00
|
|
|
return (
|
|
|
|
<div className="module-conversation-list-item__message">
|
2018-07-27 03:13:56 +02:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__message__text',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item__message__text--has-unread'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
>
|
2018-11-14 20:10:32 +01:00
|
|
|
{isTyping ? (
|
|
|
|
<TypingAnimation i18n={i18n} />
|
|
|
|
) : (
|
2020-12-01 00:32:56 +01:00
|
|
|
<MessageBody
|
|
|
|
isGroup={true}
|
|
|
|
text={text}
|
|
|
|
disableJumbomoji={true}
|
|
|
|
disableLinks={true}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
)}
|
2018-07-27 03:13:56 +02:00
|
|
|
</div>
|
2018-11-14 20:10:32 +01:00
|
|
|
{lastMessage && lastMessage.status ? (
|
2018-07-18 05:25:55 +02:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item__message__status-icon',
|
2020-05-29 08:25:15 +02:00
|
|
|
`module-conversation-list-item__message__status-icon--${lastMessage.status}`
|
2018-07-18 05:25:55 +02:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2019-01-16 05:44:13 +01:00
|
|
|
const {
|
2019-03-07 02:14:44 +01:00
|
|
|
phoneNumber,
|
2019-01-16 05:44:13 +01:00
|
|
|
unreadCount,
|
|
|
|
onClick,
|
2019-04-17 08:30:15 +02:00
|
|
|
id,
|
2019-01-16 05:44:13 +01:00
|
|
|
isSelected,
|
|
|
|
isBlocked,
|
2019-04-18 03:16:51 +02:00
|
|
|
style,
|
2019-10-02 05:28:10 +02:00
|
|
|
mentionedUs,
|
2019-01-16 05:44:13 +01:00
|
|
|
} = this.props;
|
2020-10-22 07:34:41 +02:00
|
|
|
const triggerId = `conversation-item-${phoneNumber}-ctxmenu`;
|
|
|
|
const key = `conversation-item-${phoneNumber}`;
|
2019-03-07 02:14:44 +01:00
|
|
|
|
2018-07-18 05:25:55 +02:00
|
|
|
return (
|
2020-10-22 07:34:41 +02:00
|
|
|
<div key={key}>
|
2020-12-01 00:32:56 +01:00
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={() => {
|
|
|
|
if (onClick) {
|
|
|
|
onClick(id);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onContextMenu={(e: any) => {
|
|
|
|
contextMenu.show({
|
|
|
|
id: triggerId,
|
|
|
|
event: e,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
style={style}
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-list-item',
|
|
|
|
unreadCount > 0
|
|
|
|
? 'module-conversation-list-item--has-unread'
|
|
|
|
: null,
|
|
|
|
unreadCount > 0 && mentionedUs
|
|
|
|
? 'module-conversation-list-item--mentioned-us'
|
|
|
|
: null,
|
|
|
|
isSelected ? 'module-conversation-list-item--is-selected' : null,
|
|
|
|
isBlocked ? 'module-conversation-list-item--is-blocked' : null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{this.renderAvatar()}
|
|
|
|
<div className="module-conversation-list-item__content">
|
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderMessage()}
|
2019-03-07 02:14:44 +01:00
|
|
|
</div>
|
2020-12-01 00:32:56 +01:00
|
|
|
</div>
|
|
|
|
<Portal>
|
|
|
|
<ConversationListItemContextMenu {...this.getMenuProps(triggerId)} />
|
|
|
|
</Portal>
|
2018-07-18 05:25:55 +02:00
|
|
|
</div>
|
|
|
|
);
|
2020-01-07 03:24:44 +01:00
|
|
|
}
|
2019-12-18 02:03:51 +01:00
|
|
|
|
2020-10-22 07:34:41 +02:00
|
|
|
private getMenuProps(triggerId: string): PropsContextConversationItem {
|
|
|
|
return {
|
|
|
|
triggerId,
|
|
|
|
...this.props,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-18 02:03:51 +01:00
|
|
|
private renderUser() {
|
2020-09-10 07:52:36 +02:00
|
|
|
const { name, phoneNumber, profileName, isMe, i18n } = this.props;
|
2019-12-18 02:03:51 +01:00
|
|
|
|
|
|
|
const shortenedPubkey = window.shortenPubkey(phoneNumber);
|
|
|
|
|
|
|
|
const displayedPubkey = profileName ? shortenedPubkey : phoneNumber;
|
2020-09-10 07:52:36 +02:00
|
|
|
const displayName = isMe ? i18n('noteToSelf') : profileName;
|
2019-12-18 02:03:51 +01:00
|
|
|
|
2020-10-06 06:45:27 +02:00
|
|
|
let shouldShowPubkey = false;
|
|
|
|
if (!name || name.length === 0) {
|
|
|
|
shouldShowPubkey = true;
|
|
|
|
}
|
2019-12-18 02:03:51 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-conversation__user">
|
|
|
|
<ContactName
|
|
|
|
phoneNumber={displayedPubkey}
|
|
|
|
name={name}
|
2020-09-10 07:52:36 +02:00
|
|
|
profileName={displayName}
|
2019-12-18 02:03:51 +01:00
|
|
|
module="module-conversation__user"
|
|
|
|
i18n={window.i18n}
|
|
|
|
boldProfileName={true}
|
2020-10-06 06:45:27 +02:00
|
|
|
shouldShowPubkey={shouldShowPubkey}
|
2019-12-18 02:03:51 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-07-18 05:25:55 +02:00
|
|
|
}
|
2020-09-14 08:06:24 +02:00
|
|
|
|
|
|
|
export const ConversationListItemWithDetails = usingClosedConversationDetails(
|
|
|
|
ConversationListItem
|
|
|
|
);
|