From ef10b65b12e9b20704f8f214e1a409b0d7e98bb5 Mon Sep 17 00:00:00 2001 From: Brieuc Viel Date: Thu, 9 Nov 2017 16:43:53 +0100 Subject: [PATCH] [CNContact] CNContact fix ChatConversationTableView crash on click new --- Classes/Utils/FastAddressBook.m | 18 ----------- Classes/Utils/Utils.m | 57 +++++++++++++++++---------------- 2 files changed, 29 insertions(+), 46 deletions(-) diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 7df7be63e..ba59c388d 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -156,27 +156,11 @@ return self; } -/*- (void)saveAddressBook { - if (addressBook != nil) { - if (!ABAddressBookSave(addressBook, nil)) { - LOGW(@"Couldn't save Address Book"); - } - } -} -*/ - -(void) updateAddressBook:(NSNotification*) notif { LOGD(@"address book has changed"); self.needToUpdate = TRUE; - //[self reloadAllContacts]; } -/*- (void)reload { - [self getAllContacts]; - LOGE(@"Create AddressBook failed"); - -} -*/ - (BOOL)reloadAllContacts { BOOL success = FALSE; if ([CNContactStore class]) { @@ -209,8 +193,6 @@ } else { Contact *newContact = [[Contact alloc] initWithCNContact:contact]; - [_addressBookMap setObject:newContact - forKey:contact]; [self registerAddrsFor:newContact]; } }]; diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index f2c47a610..5aaa54dcc 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -454,35 +454,36 @@ } + (LinphoneAddress *)normalizeSipOrPhoneAddress:(NSString *)value { - if (!value) { - return NULL; - } - LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC); - const char * normvalue; - if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { - normvalue = linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String); - } else { - normvalue = value.UTF8String; - } - LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri(cfg, normvalue); - // first try to find a friend with the given address - Contact *c = [FastAddressBook getContactWithAddress:addr]; + if (!value || [value isEqualToString:@""]) { + return NULL; + } + LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(LC); + const char *normvalue; + if (linphone_proxy_config_is_phone_number(cfg, value.UTF8String)) { + normvalue = + linphone_proxy_config_normalize_phone_number(cfg, value.UTF8String); + } else { + normvalue = value.UTF8String; + } + LinphoneAddress *addr = + linphone_proxy_config_normalize_sip_uri(cfg, normvalue); + // first try to find a friend with the given address + Contact *c = [FastAddressBook getContactWithAddress:addr]; - if (c && c.friend) { - LinphoneFriend *f = c.friend; - const LinphonePresenceModel *m = - f ? linphone_friend_get_presence_model_for_uri_or_tel( - f, value.UTF8String) - : NULL; - const char *contact = - m ? linphone_presence_model_get_contact(m) : NULL; - if (contact) { - LinphoneAddress *contact_addr = linphone_address_new(contact); - if (contact_addr) { - linphone_address_destroy(addr); - return contact_addr; - } - } + if (c && c.friend) { + LinphoneFriend *f = c.friend; + const LinphonePresenceModel *m = + f ? linphone_friend_get_presence_model_for_uri_or_tel(f, + value.UTF8String) + : NULL; + const char *contact = m ? linphone_presence_model_get_contact(m) : NULL; + if (contact) { + LinphoneAddress *contact_addr = linphone_address_new(contact); + if (contact_addr) { + linphone_address_destroy(addr); + return contact_addr; + } + } } // since user wants to escape plus, we assume it expects to have phone