From 50f656d1ee16a6b7d87bd8883bbcf413af8e757e Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Fri, 4 Nov 2022 15:22:55 +0100 Subject: [PATCH] =?UTF-8?q?Rework=20of=20non-native=20contacts:=20fix=20bu?= =?UTF-8?q?g=20that=20would=20not=20display=20sip=20adresses=20in=20detail?= =?UTF-8?q?=20view,=20and=20fix=20bug=20that=20would=20lose=20the=20?= =?UTF-8?q?=E2=80=9CcreatedFromLdapOrProvisioning=E2=80=9D=20tag=20of=20no?= =?UTF-8?q?n-native=20contacts=20after=20first=20launch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/Contact.h | 2 ++ Classes/Contact.m | 19 +++++++++++++++++++ Classes/ContactDetailsTableView.m | 16 ++++++++-------- Classes/LinphoneUI/UIContactDetailsCell.m | 22 +++++++++++++--------- Classes/Utils/FastAddressBook.m | 9 +-------- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/Classes/Contact.h b/Classes/Contact.h index 579a6ffa4..2cb44a5e2 100644 --- a/Classes/Contact.h +++ b/Classes/Contact.h @@ -58,4 +58,6 @@ - (BOOL)removeSipAddressAtIndex:(NSInteger)index; - (BOOL)removePhoneNumberAtIndex:(NSInteger)index; - (BOOL)removeEmailAtIndex:(NSInteger)index; + +- (NSMutableArray*)getSipAddressesWithoutDuplicatePhoneNumbers; @end diff --git a/Classes/Contact.m b/Classes/Contact.m index 5f289b1da..2e66a797f 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -488,4 +488,23 @@ _friend = NULL; } +- (NSMutableArray*)getSipAddressesWithoutDuplicatePhoneNumbers { + NSMutableArray* resAdresses = [[NSMutableArray alloc] init]; + + for (NSString *address in _sipAddresses) { + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, [address UTF8String], YES); + bool isFoundInPhones = false; + if (addr) { + for (NSString *phoneNb in _phones) { + if ([phoneNb isEqualToString:[NSString stringWithUTF8String:linphone_address_get_username(addr)]]) { + isFoundInPhones = true; + break; + } + } + } + if (!isFoundInPhones) [resAdresses addObject:address]; + } + + return resAdresses; +} @end diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index 1e3037752..2556fbebc 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -160,15 +160,15 @@ /*first and last name only when editting */ return (self.tableView.isEditing) ? 1 : 0; } else if (section == ContactSections_Sip) { - return _contact.createdFromLdapOrProvisioning ? 0 : _contact.sipAddresses.count; + return [_contact getSipAddressesWithoutDuplicatePhoneNumbers].count; } else if (section == ContactSections_Number) { - return _contact.phones.count; - } else if (section == ContactSections_Email) { - BOOL showEmails = [LinphoneManager.instance - lpConfigBoolForKey:@"show_contacts_emails_preference"]; - return showEmails ? _contact.emails.count : 0; - } - return 0; + return _contact.phones.count; + } else if (section == ContactSections_Email) { + BOOL showEmails = [LinphoneManager.instance + lpConfigBoolForKey:@"show_contacts_emails_preference"]; + return showEmails ? _contact.emails.count : 0; + } + return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index c70dce1cd..b1b5bc697 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -57,22 +57,26 @@ [NSString stringWithFormat:NSLocalizedString(@"Chat with %@", nil), _addressLabel.text]; _callButton.accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Call %@", nil), _addressLabel.text]; // Test presence - Contact *contact; - contact = addr ? [FastAddressBook getContactWithAddress:(addr)] : NULL; - + Contact *contact = addr ? [FastAddressBook getContactWithAddress:(addr)] : NULL; + LinphoneFriend *contactFriend = NULL; + if (contact && contact.friend) { + contactFriend = contact.friend; + } else if (addr) { + contactFriend = linphone_core_find_friend(LC, addr); + } + + ContactDetailsView *contactDetailsView = VIEW(ContactDetailsView); _linphoneImage.hidden = TRUE; - if (contact) { - const LinphonePresenceModel *model = contact.friend ? linphone_friend_get_presence_model_for_uri_or_tel(contact.friend, _addressLabel.text.UTF8String) : NULL; - + if (contactFriend) { + const LinphonePresenceModel *model = contactFriend ? linphone_friend_get_presence_model_for_uri_or_tel(contactFriend, _addressLabel.text.UTF8String) : NULL; + self.linphoneImage.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"hide_linphone_contacts" inSection:@"app"] || !((model && linphone_presence_model_get_basic_status(model) == LinphonePresenceBasicStatusOpen) || (account && !linphone_account_is_phone_number(account, _addressLabel.text.UTF8String) && [FastAddressBook isSipURIValid:_addressLabel.text])); - ContactDetailsView *contactDetailsView = VIEW(ContactDetailsView); - self.inviteButton.hidden = !ENABLE_SMS_INVITE || [[contactDetailsView.contact sipAddresses] count] > 0 || !self.linphoneImage.hidden; + self.inviteButton.hidden = !ENABLE_SMS_INVITE || [[contactDetailsView.contact sipAddresses] count] > 0 || !self.linphoneImage.hidden; [self shouldHideEncryptedChatView:account && linphone_account_params_get_conference_factory_uri(linphone_account_get_params(account)) && model && linphone_presence_model_has_capability(model, LinphoneFriendCapabilityLimeX3dh)]; - _chatButton.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"]; } diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 846daaf28..40917c297 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -192,6 +192,7 @@ // above) if (linphone_friend_get_ref_key(f) == NULL) { Contact *contact = [[Contact alloc] initWithFriend:f]; + contact.createdFromLdapOrProvisioning = true; [self registerAddrsFor:contact]; } friends = friends->next; @@ -210,14 +211,6 @@ [_addressBookMap removeAllObjects]; _addressBookMap = [NSMutableDictionary dictionary]; - LinphoneFriend *testFriend = linphone_core_create_friend(LC); - linphone_friend_set_name(testFriend, "Moi Maisentest"); - linphone_friend_set_native_uri(testFriend, "sip:pouetpouet@sip.linphone.org"); - const MSList *lists = linphone_core_get_friends_lists(LC); - LinphoneFriendList *fl = lists->data; - linphone_friend_list_add_friend(fl, testFriend); - const MSList *friends = linphone_friend_list_get_friends(fl); - if ([LinphoneManager.instance lpConfigBoolForKey:@"enable_native_address_book"]) { CNEntityType entityType = CNEntityTypeContacts; [store requestAccessForEntityType:entityType completionHandler:^(BOOL granted, NSError *_Nullable error) {