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
|
|
|
|
|
2020-09-09 02:25:05 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
|
|
|
import { ContactName } from '../../components/conversation/ContactName';
|
|
|
|
|
|
|
|
import { getIntl } from '../selectors/user';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { GetConversationByIdType } from '../selectors/conversations';
|
2024-02-08 14:36:08 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getSelectedConversationId,
|
|
|
|
} from '../selectors/conversations';
|
2020-09-09 02:25:05 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2024-02-08 14:36:08 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function SmartContactName(props: ExternalProps): JSX.Element {
|
2024-02-08 14:36:08 +00:00
|
|
|
const { contactId } = props;
|
2020-09-09 02:25:05 +00:00
|
|
|
const i18n = useSelector<StateType, LocalizerType>(getIntl);
|
|
|
|
const getConversation = useSelector<StateType, GetConversationByIdType>(
|
|
|
|
getConversationSelector
|
|
|
|
);
|
|
|
|
|
2024-02-08 14:36:08 +00:00
|
|
|
const contact = getConversation(contactId) || {
|
2023-03-30 00:03:25 +00:00
|
|
|
title: i18n('icu:unknownContact'),
|
2020-09-16 14:22:46 +00:00
|
|
|
};
|
2024-02-08 14:36:08 +00:00
|
|
|
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
|
2024-02-08 14:36:08 +00:00
|
|
|
firstName={contact.firstName}
|
|
|
|
title={contact.title}
|
|
|
|
onClick={() => showContactModal(contact.id, currentConversation.id)}
|
2021-05-28 16:15:17 +00:00
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|