@ -399,12 +399,30 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
#pragma mark - Whisper User Management
- ( BOOL ) hasNameInSystemContactsForRecipientId : ( NSString * ) recipientId
{
return [ self cachedDisplayNameForRecipientId : recipientId ] != nil ;
}
- ( NSString * ) unknownContactName
{
return NSLocalizedString ( @ "UNKNOWN_CONTACT_NAME ",
@ "Displayed if for some reason we can ' t determine a contacts phone number * or * name ") ;
}
- ( nullable NSString * ) formattedProfileNameForRecipientId : ( NSString * ) recipientId
{
NSString * _Nullable profileName = [ self . profileManager profileNameForRecipientId : recipientId ] ;
if ( profileName . length == 0 ) {
return nil ;
}
NSString * profileNameFormatString = NSLocalizedString ( @ "PROFILE_NAME_LABEL_FORMAT ",
@ "Prepend a simple marker to differentiate the profile name , embeds the contact ' s { { profile name } } . ") ;
return [ NSString stringWithFormat : profileNameFormatString , profileName ] ;
}
- ( NSString * _Nonnull ) displayNameForPhoneIdentifier : ( NSString * _Nullable ) recipientId
{
if ( !recipientId ) {
@ -414,11 +432,6 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
/ / Prefer a saved name from system contacts , if available
NSString * _Nullable displayName = [ self cachedDisplayNameForRecipientId : recipientId ] ;
/ / Else try to use their profile name
if ( displayName . length < 1 ) {
displayName = [ self . profileManager profileNameForRecipientId : recipientId ] ;
}
/ / Else fall back to just using their recipientId
if ( displayName . length < 1 ) {
displayName = recipientId ;
@ -490,21 +503,13 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
[ formattedName appendAttributedString : [ [ NSAttributedString alloc ] initWithString : cachedLastName
attributes : lastNameAttributes ] ] ;
} else {
/ / If there ' s no name saved in our contacts , try their profile .
/ / TODO we might want to format this specially .
NSString * _Nullable profileName = [ self . profileManager profileNameForRecipientId : recipientId ] ;
if ( profileName . length < 1 ) {
/ / Else , fall back to using just their recipientId
NSString * phoneString = [ PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber : recipientId ] ;
return [ [ NSAttributedString alloc ] initWithString : phoneString
attributes : normalFontAttributes ] ;
}
[ formattedName appendAttributedString : [ [ NSAttributedString alloc ] initWithString : profileName
attributes : lastNameAttributes ] ] ;
NSString * phoneString =
[ PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber : recipientId ] ;
return [ [ NSAttributedString alloc ] initWithString : phoneString attributes : normalFontAttributes ] ;
}
/ / Append unique label for contacts with multiple Signal accounts
SignalAccount * signalAccount = [ self signalAccountForRecipientId : recipientId ] ;
if ( signalAccount && signalAccount . multipleAccountLabelText ) {
OWSAssert ( signalAccount . multipleAccountLabelText . length > 0 ) ;
@ -521,6 +526,30 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
return formattedName ;
}
- ( NSAttributedString * ) attributedStringForMessageFooterWithPhoneIdentifier : ( NSString * ) recipientId
{
/ / Prefer a saved name from system contacts , if available
NSString * _Nullable savedContactName = [ self cachedDisplayNameForRecipientId : recipientId ] ;
if ( savedContactName . length > 0 ) {
return [ [ NSAttributedString alloc ] initWithString : savedContactName ] ;
}
NSString * _Nullable profileName = [ self . profileManager profileNameForRecipientId : recipientId ] ;
if ( profileName . length > 0 ) {
NSString * numberAndProfileNameFormat = NSLocalizedString ( @ "PROFILE_NAME_AND_PHONE_NUMBER_LABEL_FORMAT ",
@ "Label text combining the phone number and profile name separated by a simple demarcation character . "
@ "Phone number should be most prominent . ' %1$@' is replaced with { { phone number } } and ' %2$@' is replaced "
@ "with { { profile name } } ") ;
NSString * numberAndProfileName =
[ NSString stringWithFormat : numberAndProfileNameFormat , recipientId , profileName ] ;
return [ [ NSAttributedString alloc ] initWithString : numberAndProfileName ] ;
}
/ / else fall back to recipient id
return [ [ NSAttributedString alloc ] initWithString : recipientId ] ;
}
- ( nullable SignalAccount * ) signalAccountForRecipientId : ( NSString * ) recipientId
{
OWSAssert ( recipientId . length > 0 ) ;