Process username changes in storage service

This commit is contained in:
Fedor Indutny 2023-02-02 10:03:51 -08:00 committed by GitHub
parent 71c97e9580
commit 1381e8df5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 252 additions and 53 deletions

View file

@ -36,7 +36,7 @@ export function getTitleNoDefault(
return (
(isShort ? attributes.systemGivenName : undefined) ||
attributes.name ||
getSystemName(attributes) ||
(isShort ? attributes.profileName : undefined) ||
getProfileName(attributes) ||
getNumber(attributes) ||
@ -44,6 +44,30 @@ export function getTitleNoDefault(
);
}
// Note that the used attributes field should match the ones we listen for
// change on in ConversationModel (see `ConversationModel#maybeClearUsername`)
export function canHaveUsername(
attributes: Pick<
ConversationAttributesType,
'id' | 'type' | 'name' | 'profileName' | 'profileFamilyName' | 'e164'
>,
ourConversationId: string | undefined
): boolean {
if (!isDirectConversation(attributes)) {
return false;
}
if (ourConversationId === attributes.id) {
return true;
}
return (
!getSystemName(attributes) &&
!getProfileName(attributes) &&
!getNumber(attributes)
);
}
export function getProfileName(
attributes: Pick<
ConversationAttributesType,
@ -57,6 +81,22 @@ export function getProfileName(
return undefined;
}
export function getSystemName(
attributes: Pick<
ConversationAttributesType,
'systemGivenName' | 'systemFamilyName' | 'type'
>
): string | undefined {
if (isDirectConversation(attributes)) {
return combineNames(
attributes.systemGivenName,
attributes.systemFamilyName
);
}
return undefined;
}
export function getNumber(
attributes: Pick<ConversationAttributesType, 'e164' | 'type'>
): string {