signal-desktop/ts/components/conversationList/ContactListItem.tsx

104 lines
2.4 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { FunctionComponent } from 'react';
import React from 'react';
2021-10-14 15:48:48 +00:00
import {
BaseConversationListItem,
HEADER_CONTACT_NAME_CLASS_NAME,
} from './BaseConversationListItem';
import type { ConversationType } from '../../state/ducks/conversations';
2021-11-17 21:11:21 +00:00
import type { BadgeType } from '../../badges/types';
import type { LocalizerType, ThemeType } from '../../types/Util';
import { ContactName } from '../conversation/ContactName';
import { About } from '../conversation/About';
2021-11-17 21:11:21 +00:00
export type ContactListItemConversationType = Pick<
ConversationType,
| 'about'
| 'acceptedMessageRequest'
| 'avatarPath'
2021-11-17 21:11:21 +00:00
| 'badges'
| 'color'
| 'id'
| 'isMe'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
| 'type'
| 'unblurredAvatarPath'
| 'e164'
>;
2021-11-17 21:11:21 +00:00
type PropsDataType = ContactListItemConversationType & {
badge: undefined | BadgeType;
};
type PropsHousekeepingType = {
i18n: LocalizerType;
2021-03-03 20:09:58 +00:00
onClick?: (id: string) => void;
2021-11-17 21:11:21 +00:00
theme: ThemeType;
};
type PropsType = PropsDataType & PropsHousekeepingType;
export const ContactListItem: FunctionComponent<PropsType> = React.memo(
2021-08-11 19:29:07 +00:00
function ContactListItem({
about,
acceptedMessageRequest,
avatarPath,
2021-11-17 21:11:21 +00:00
badge,
color,
i18n,
id,
isMe,
name,
onClick,
phoneNumber,
profileName,
sharedGroupNames,
2021-11-17 21:11:21 +00:00
theme,
title,
type,
unblurredAvatarPath,
2021-08-11 19:29:07 +00:00
}) {
const headerName = isMe ? (
2021-10-14 15:48:48 +00:00
<span className={HEADER_CONTACT_NAME_CLASS_NAME}>
{i18n('noteToSelf')}
</span>
) : (
2021-10-14 15:48:48 +00:00
<ContactName module={HEADER_CONTACT_NAME_CLASS_NAME} title={title} />
);
const messageText =
about && !isMe ? <About className="" text={about} /> : null;
return (
<BaseConversationListItem
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
2021-11-17 21:11:21 +00:00
badge={badge}
color={color}
conversationType={type}
headerName={headerName}
i18n={i18n}
id={id}
isMe={isMe}
isSelected={false}
messageText={messageText}
name={name}
2021-03-03 20:09:58 +00:00
onClick={onClick ? () => onClick(id) : undefined}
phoneNumber={phoneNumber}
profileName={profileName}
sharedGroupNames={sharedGroupNames}
2021-11-17 21:11:21 +00:00
theme={theme}
title={title}
unblurredAvatarPath={unblurredAvatarPath}
/>
);
}
);