Build avatar from contact initials even if they don't have a phone

number

The invite contact picker was rendering the "#" avatar for contacts who
had a name, but no phone number.

In some ways this approach is dumber. But since we have "surprising"
logic to set the contacts firstName to a phone number or maybe a company
name when contacts are built from ABContacts, this approach is more on
the level with the existing assumptions of what could be in that field
(which is to say, pretty much anything).

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 8211d4584f
commit 103f0450a1

@ -57,8 +57,10 @@ NS_ASSUME_NONNULL_BEGIN
}
NSMutableString *initials = [NSMutableString string];
BOOL contactHasName = [self.contactsManager nameExistsForPhoneIdentifier:self.signalId];
if (contactHasName) {
NSRange rangeOfLetters = [self.contactName rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
if (rangeOfLetters.location != NSNotFound) {
// Contact name contains letters, so it's probably not just a phone number.
// Make an image from the contact's initials
NSArray *words =
[self.contactName componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
@ -71,7 +73,9 @@ NS_ASSUME_NONNULL_BEGIN
NSRange stringRange = { 0, MIN([initials length], (NSUInteger)3) }; // Rendering max 3 letters.
initials = [[initials substringWithRange:stringRange] mutableCopy];
} else {
}
if (initials.length == 0) {
// We don't have a name for this contact, so we can't make an "initials" image
[initials appendString:@"#"];
}

@ -30,7 +30,6 @@
- (void)doAfterEnvironmentInitSetup;
- (NSString * _Nonnull)displayNameForPhoneIdentifier:(NSString * _Nullable)identifier;
- (BOOL)nameExistsForPhoneIdentifier:(NSString * _Nullable)identifier;
- (UIImage * _Nullable)imageForPhoneIdentifier:(NSString * _Nullable)identifier;
+ (NSComparator _Nonnull)contactComparator;

@ -411,21 +411,6 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
return displayName;
}
- (BOOL)nameExistsForPhoneIdentifier:(NSString * _Nullable)identifier {
Contact *contact = [self contactForPhoneIdentifier:identifier];
NSString *name = contact.fullName;
if (name.length <= 0) return NO;
// OWSContactsManager::contactForRecord will use the first phone number as a name
// in absense of a name or business name during import. Make sure that's not happening here.
if ((contact.userTextPhoneNumbers.count > 0) && ([contact.userTextPhoneNumbers[0] isEqualToString:name])) {
return NO;
}
return YES;
}
- (Contact * _Nullable)contactForPhoneIdentifier:(NSString * _Nullable)identifier {
if (!identifier) {
return nil;

Loading…
Cancel
Save