signal-desktop/ts/state/smart/ContactName.tsx

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
2020-09-09 02:25:05 +00:00
import { useSelector } from 'react-redux';
import { ContactName } from '../../components/conversation/ContactName';
import { getIntl } from '../selectors/user';
import {
getConversationSelector,
getSelectedConversationId,
} from '../selectors/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
2020-09-09 02:25:05 +00:00
type ExternalProps = {
contactId: string;
2020-09-09 02:25:05 +00:00
};
export const SmartContactName = memo(function SmartContactName(
props: ExternalProps
) {
const { contactId } = props;
const i18n = useSelector(getIntl);
const getConversation = useSelector(getConversationSelector);
2020-09-09 02:25:05 +00:00
const contact = getConversation(contactId) || {
2023-03-30 00:03:25 +00:00
title: i18n('icu:unknownContact'),
};
const currentConversationId = useSelector(getSelectedConversationId);
const currentConversation = getConversation(currentConversationId);
const { showContactModal } = useGlobalModalActions();
2020-09-09 02:25:05 +00:00
2021-05-28 16:15:17 +00:00
return (
<ContactName
firstName={contact.firstName}
title={contact.title}
onClick={() => showContactModal(contact.id, currentConversation.id)}
2021-05-28 16:15:17 +00:00
/>
);
});