2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-18 23:57:26 +00:00
|
|
|
import React from 'react';
|
2021-05-28 16:15:17 +00:00
|
|
|
import classNames from 'classnames';
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2020-07-29 23:20:05 +00:00
|
|
|
import { Emojify } from './Emojify';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ContactNameColorType } from '../../types/Colors';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { getClassNamesFor } from '../../util/getClassNamesFor';
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type PropsType = {
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor?: ContactNameColorType;
|
2021-03-03 20:09:58 +00:00
|
|
|
firstName?: string;
|
2022-11-09 02:38:19 +00:00
|
|
|
isSignalConversation?: boolean;
|
2023-03-02 06:57:35 +00:00
|
|
|
isMe?: boolean;
|
2020-07-29 23:20:05 +00:00
|
|
|
module?: string;
|
2021-03-03 20:09:58 +00:00
|
|
|
preferFirstName?: boolean;
|
|
|
|
title: string;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function ContactName({
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor,
|
2021-03-03 20:09:58 +00:00
|
|
|
firstName,
|
2022-11-09 02:38:19 +00:00
|
|
|
isSignalConversation,
|
2023-03-02 06:57:35 +00:00
|
|
|
isMe,
|
2021-03-03 20:09:58 +00:00
|
|
|
module,
|
|
|
|
preferFirstName,
|
|
|
|
title,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-05-28 16:15:17 +00:00
|
|
|
const getClassName = getClassNamesFor('module-contact-name', module);
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
let text: string;
|
|
|
|
if (preferFirstName) {
|
|
|
|
text = firstName || title || '';
|
|
|
|
} else {
|
|
|
|
text = title || '';
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
return (
|
2021-05-28 16:15:17 +00:00
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
getClassName(''),
|
|
|
|
contactNameColor ? getClassName(`--${contactNameColor}`) : null
|
|
|
|
)}
|
|
|
|
dir="auto"
|
|
|
|
>
|
2021-03-03 20:09:58 +00:00
|
|
|
<Emojify text={text} />
|
2023-03-02 06:57:35 +00:00
|
|
|
{(isSignalConversation || isMe) && (
|
|
|
|
<span className="ContactModal__official-badge" />
|
2022-11-09 02:38:19 +00:00
|
|
|
)}
|
2020-09-14 19:51:27 +00:00
|
|
|
</span>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|