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
|
2024-03-19 17:12:32 +00:00
|
|
|
import React, { memo, useCallback, useMemo } 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';
|
2024-02-08 14:36:08 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getSelectedConversationId,
|
|
|
|
} from '../selectors/conversations';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
|
|
|
type ExternalProps = {
|
2024-02-08 14:36:08 +00:00
|
|
|
contactId: string;
|
2020-09-09 02:25:05 +00:00
|
|
|
};
|
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
export const SmartContactName = memo(function SmartContactName({
|
|
|
|
contactId,
|
|
|
|
}: ExternalProps) {
|
2024-03-13 20:44:13 +00:00
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const getConversation = useSelector(getConversationSelector);
|
2024-02-08 14:36:08 +00:00
|
|
|
const currentConversationId = useSelector(getSelectedConversationId);
|
|
|
|
|
|
|
|
const { showContactModal } = useGlobalModalActions();
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2024-03-19 17:12:32 +00:00
|
|
|
const contact = useMemo(() => {
|
|
|
|
return getConversation(contactId);
|
|
|
|
}, [getConversation, contactId]);
|
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
|
|
|
showContactModal(contactId, currentConversationId);
|
|
|
|
}, [showContactModal, contactId, currentConversationId]);
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
return (
|
|
|
|
<ContactName
|
2024-02-08 14:36:08 +00:00
|
|
|
firstName={contact.firstName}
|
2024-03-19 17:12:32 +00:00
|
|
|
title={contact.title ?? i18n('icu:unknownContact')}
|
|
|
|
onClick={handleClick}
|
2021-05-28 16:15:17 +00:00
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|