signal-desktop/ts/components/ContactListItem.tsx

121 lines
2.9 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import classNames from 'classnames';
2021-01-26 01:01:19 +00:00
import { About } from './conversation/About';
import { Avatar } from './Avatar';
import { Emojify } from './conversation/Emojify';
2020-07-24 01:35:32 +00:00
import { InContactsIcon } from './InContactsIcon';
import { LocalizerType } from '../types/Util';
import { ConversationType } from '../state/ducks/conversations';
import { isInSystemContacts } from '../util/isInSystemContacts';
type Props = {
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
2020-09-09 02:25:05 +00:00
isAdmin?: boolean;
onClick?: () => void;
} & Pick<
ConversationType,
| 'about'
| 'acceptedMessageRequest'
| 'avatarPath'
| 'color'
| 'isMe'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
| 'type'
| 'unblurredAvatarPath'
>;
export class ContactListItem extends React.Component<Props> {
2020-09-12 00:46:52 +00:00
public renderAvatar(): JSX.Element {
const {
acceptedMessageRequest,
avatarPath,
color,
i18n,
2021-05-07 22:21:10 +00:00
isMe,
name,
phoneNumber,
profileName,
sharedGroupNames,
2020-07-24 01:35:32 +00:00
title,
type,
unblurredAvatarPath,
} = this.props;
return (
<Avatar
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
color={color}
conversationType={type}
i18n={i18n}
2021-05-07 22:21:10 +00:00
isMe={isMe}
name={name}
phoneNumber={phoneNumber}
profileName={profileName}
2020-07-24 01:35:32 +00:00
title={title}
sharedGroupNames={sharedGroupNames}
2019-10-04 18:06:17 +00:00
size={52}
unblurredAvatarPath={unblurredAvatarPath}
/>
);
}
2020-09-12 00:46:52 +00:00
public render(): JSX.Element {
const {
about,
i18n,
isAdmin,
isMe,
name,
onClick,
title,
type,
} = this.props;
const displayName = isMe ? i18n('you') : title;
return (
2019-11-07 21:36:16 +00:00
<button
onClick={onClick}
className={classNames(
'module-contact-list-item',
onClick ? 'module-contact-list-item--with-click-handler' : null
)}
2020-09-12 00:46:52 +00:00
type="button"
>
{this.renderAvatar()}
<div className="module-contact-list-item__text">
2020-09-09 02:25:05 +00:00
<div className="module-contact-list-item__left">
<div className="module-contact-list-item__text__name">
<Emojify text={displayName} />
{isInSystemContacts({ name, type }) ? (
2020-09-09 02:25:05 +00:00
<span>
{' '}
<InContactsIcon i18n={i18n} />
</span>
) : null}
</div>
<div className="module-contact-list-item__text__additional-data">
2021-01-26 01:01:19 +00:00
<About text={about} />
2020-09-09 02:25:05 +00:00
</div>
</div>
2020-09-09 02:25:05 +00:00
{isAdmin ? (
<div className="module-contact-list-item__admin">
{i18n('GroupV2--admin')}
</div>
) : null}
</div>
2019-11-07 21:36:16 +00:00
</button>
);
}
}