From 61a9d393c16ca73769813d103781273e65f24a6b Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 13 Nov 2015 09:59:02 +0100 Subject: [PATCH] Contact: use composite name if available --- Classes/ContactsListTableView.m | 21 ++------------------- Classes/Utils/FastAddressBook.m | 12 ++++++------ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index e97555eb0..b75715ebb 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -82,25 +82,8 @@ static int ms_strcmpfuz(const char *fuzzy_word, const char *sentence) { } - (NSString *)displayNameForContact:(ABRecordRef)person { - NSString *lFirstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty)); - NSString *lLocalizedFirstName = [FastAddressBook localizedLabel:lFirstName]; - NSString *lLastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty)); - NSString *lLocalizedLastName = [FastAddressBook localizedLabel:lLastName]; - NSString *lOrganization = CFBridgingRelease(ABRecordCopyValue(person, kABPersonOrganizationProperty)); - NSString *lLocalizedlOrganization = [FastAddressBook localizedLabel:lOrganization]; - - NSString *name = nil; - if (lLocalizedFirstName.length && lLocalizedLastName.length) { - name = [NSString stringWithFormat:@"%@ %@", lLocalizedFirstName, lLocalizedLastName]; - } else if (lLocalizedLastName.length) { - name = [NSString stringWithFormat:@"%@", lLocalizedLastName]; - } else if (lLocalizedFirstName.length) { - name = [NSString stringWithFormat:@"%@", lLocalizedFirstName]; - } else if (lLocalizedlOrganization.length) { - name = [NSString stringWithFormat:@"%@", lLocalizedlOrganization]; - } - - if (name != nil && [name length] > 0) { + NSString *name = [FastAddressBook displayNameForContact:person]; + if (name != nil && [name length] > 0 && ![name isEqualToString:NSLocalizedString(@"Unkonwn", nil)]) { // Add the contact only if it fuzzy match filter too (if any) if ([ContactSelection getNameOrEmailFilter] == nil || (ms_strcmpfuz([[[ContactSelection getNameOrEmailFilter] lowercaseString] UTF8String], diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 988f1d2ee..251ba6fe1 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -305,9 +305,7 @@ void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info, void if (contact != nil) { NSString *lFirstName = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonFirstNameProperty)); NSString *lLocalizedFirstName = [FastAddressBook localizedLabel:lFirstName]; - - // TODO: we may use the following so that first name / last name is properly displayed? - // retString = CFBridgingRelease(ABRecordCopyCompositeName(contact)); + NSString *compositeName = CFBridgingRelease(ABRecordCopyCompositeName(contact)); NSString *lLastName = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonLastNameProperty)); NSString *lLocalizedLastName = [FastAddressBook localizedLabel:lLastName]; @@ -315,10 +313,12 @@ void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info, void NSString *lOrganization = CFBridgingRelease(ABRecordCopyValue(contact, kABPersonOrganizationProperty)); NSString *lLocalizedOrganization = [FastAddressBook localizedLabel:lOrganization]; - if (lLocalizedFirstName == nil && lLocalizedLastName == nil) { - ret = (NSString *)lLocalizedOrganization; - } else { + if (compositeName) { + ret = compositeName; + } else if (lLocalizedFirstName || lLocalizedLastName) { ret = [NSString stringWithFormat:@"%@ %@", lLocalizedFirstName, lLocalizedLastName]; + } else { + ret = (NSString *)lLocalizedOrganization; } } return ret;