Init Nicknames & Notes

This commit is contained in:
Jamie Kyle 2024-03-26 12:48:33 -07:00 committed by GitHub
parent ebecf2403f
commit e26916702c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 1050 additions and 23 deletions

View file

@ -9,10 +9,16 @@ import { combineNames } from './combineNames';
import { getRegionCodeForNumber } from './libphonenumberUtil';
import { isDirectConversation } from './whatTypeOfConversation';
import { getE164 } from './getE164';
import { areNicknamesEnabled } from './nicknames';
type TitleOptions = {
isShort?: boolean;
ignoreNickname?: boolean;
};
export function getTitle(
attributes: ConversationRenderInfoType,
options?: { isShort?: boolean }
options?: TitleOptions
): string {
const title = getTitleNoDefault(attributes, options);
if (title) {
@ -27,7 +33,7 @@ export function getTitle(
export function getTitleNoDefault(
attributes: ConversationRenderInfoType,
{ isShort = false }: { isShort?: boolean } = {}
{ isShort = false, ignoreNickname = false }: TitleOptions = {}
): string | undefined {
if (!isDirectConversation(attributes)) {
return attributes.name;
@ -35,7 +41,15 @@ export function getTitleNoDefault(
const { username } = attributes;
let nicknameValue: string | undefined;
if (areNicknamesEnabled() && !ignoreNickname) {
nicknameValue =
(isShort ? attributes.nicknameGivenName : undefined) ||
getNicknameName(attributes);
}
return (
nicknameValue ||
(isShort ? attributes.systemGivenName : undefined) ||
getSystemName(attributes) ||
(isShort ? attributes.profileName : undefined) ||
@ -59,6 +73,8 @@ export function canHaveUsername(
| 'systemGivenName'
| 'systemFamilyName'
| 'systemNickname'
| 'nicknameGivenName'
| 'nicknameFamilyName'
| 'type'
>,
ourConversationId: string | undefined
@ -72,6 +88,7 @@ export function canHaveUsername(
}
return (
!getNicknameName(attributes) &&
!getSystemName(attributes) &&
!getProfileName(attributes) &&
!getNumber(attributes)
@ -91,6 +108,25 @@ export function getProfileName(
return undefined;
}
export function getNicknameName(
attributes: Pick<
ConversationAttributesType,
'nicknameGivenName' | 'nicknameFamilyName' | 'type'
>
): string | undefined {
if (!areNicknamesEnabled()) {
return undefined;
}
if (isDirectConversation(attributes)) {
return combineNames(
attributes.nicknameGivenName ?? undefined,
attributes.nicknameFamilyName ?? undefined
);
}
return undefined;
}
export function getSystemName(
attributes: Pick<
ConversationAttributesType,
@ -151,6 +187,7 @@ export function hasNumberTitle(
>
): boolean {
return (
!getNicknameName(attributes) &&
!getSystemName(attributes) &&
!getProfileName(attributes) &&
Boolean(getNumber(attributes))
@ -164,6 +201,7 @@ export function hasUsernameTitle(
>
): boolean {
return (
!getNicknameName(attributes) &&
!getSystemName(attributes) &&
!getProfileName(attributes) &&
!getNumber(attributes) &&