diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 6d704500c..70da309b1 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -473,13 +473,18 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onEditClick:(id)event { if (_tableController.isEditing) { - [self setEditing:FALSE]; - [self saveData]; - _isAdding = FALSE; - self.tmpContact = NULL; - _avatarImage.hidden = FALSE; - _deleteButton.hidden = FALSE; - _editButton.hidden = FALSE; + if(![self hasDuplicateContactOf:_contact]){ + [self setEditing:FALSE]; + [self saveData]; + _isAdding = FALSE; + self.tmpContact = NULL; + _avatarImage.hidden = FALSE; + _deleteButton.hidden = FALSE; + _editButton.hidden = FALSE; + }else{ + LOGE(@"====>>>> Duplicated Contacts detected !!!"); + [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Contact error", nil) message:NSLocalizedString(@"Contact duplicate", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil] show]; + } } else { [self modifyTmpContact:_contact]; [self setEditing:TRUE]; @@ -517,6 +522,30 @@ static UICompositeViewDescription *compositeDescription = nil; } } +- (BOOL) hasDuplicateContactOf:(Contact*) contactToCheck{ + CNContactStore *store = [[CNContactStore alloc] init]; + NSArray *keysToFetch = @[ + CNContactEmailAddressesKey, CNContactPhoneNumbersKey, + CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey, + CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey, + CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey + ]; + CNMutableContact *mCNContact = + [[store unifiedContactWithIdentifier:contactToCheck.identifier keysToFetch:keysToFetch error:nil] mutableCopy]; + if(mCNContact == NULL){ + for(NSString *address in contactToCheck.sipAddresses){ + NSString *name = [FastAddressBook normalizeSipURI:address]; + if([LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:name]){ + return TRUE; + } + } + return FALSE; + }else{ + return FALSE; + } +} + + #pragma mark - Image picker delegate - (void)imagePickerDelegateImage:(UIImage *)image info:(NSDictionary *)info { diff --git a/Classes/ContactsListView.m b/Classes/ContactsListView.m index ea3c5b52b..76f541dcf 100644 --- a/Classes/ContactsListView.m +++ b/Classes/ContactsListView.m @@ -219,8 +219,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onEditionChangeClick:(id)sender { - allButton.hidden = linphoneButton.hidden = _selectedButtonImage.hidden = addButton.hidden = - self.tableController.isEditing; + allButton.hidden = linphoneButton.hidden = _selectedButtonImage.hidden = addButton.hidden = self.tableController.isEditing; } - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 23a47cb51..0a97e6af7 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -293,9 +293,6 @@ return ret; } -- (BOOL)deleteContact:(Contact *)contact { - return [self deleteCNContact:contact.person]; -} - (CNContact *)getCNContactFromContact:(Contact *)acontact { NSArray *keysToFetch = @[ @@ -312,20 +309,47 @@ } - (BOOL)deleteCNContact:(CNContact *)contact { + return TRUE;//[self deleteContact:] ; +} + +- (BOOL)deleteContact:(Contact *)contact { CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init]; - [saveRequest deleteContact:[contact mutableCopy]]; - @try { - BOOL success = [store executeSaveRequest:saveRequest error:nil]; - NSLog(@"Success %d", success); - if(success) - [self fetchContactsInBackGroundThread]; - } @catch (NSException *exception) { - NSLog(@"description = %@", [exception description]); - return FALSE; + NSArray *keysToFetch = @[ + CNContactEmailAddressesKey, CNContactPhoneNumbersKey, + CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey, + CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey, + CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey + ]; + CNMutableContact *mCNContact = + [[store unifiedContactWithIdentifier:contact.identifier + keysToFetch:keysToFetch + error:nil] mutableCopy]; + if(mCNContact != nil){ + [saveRequest deleteContact:mCNContact]; + @try { + BOOL success = [store executeSaveRequest:saveRequest error:nil]; + NSLog(@"Success %d", success); + [self removeFriend:contact ]; + [LinphoneManager.instance setContactsUpdated:TRUE]; + if([contact.sipAddresses count] > 0){ + for (NSString *sip in contact.sipAddresses) { + [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:sip] ?: sip)]; + } + } + if([contact.phones count] > 0){ + for (NSString *phone in contact.phones) { + [_addressBookMap removeObjectForKey:([FastAddressBook normalizeSipURI:phone] ?: phone)]; + } + } + } @catch (NSException *exception) { + NSLog(@"description = %@", [exception description]); + return FALSE; + } } return TRUE; } + - (BOOL)deleteAllContacts { NSArray *keys = @[ CNContactPhoneNumbersKey ]; NSString *containerId = store.defaultContainerIdentifier; @@ -416,4 +440,16 @@ lists = lists->next; } } + +-(void)removeFriend:(Contact*) contact{ + BOOL enabled = [LinphoneManager.instance lpConfigBoolForKey:@"use_rls_presence"]; + const MSList *lists = linphone_core_get_friends_lists(LC); + while (lists) { + linphone_friend_list_remove_friend(lists->data, contact.friend); + linphone_friend_list_enable_subscriptions(lists->data, FALSE); + linphone_friend_list_enable_subscriptions(lists->data, enabled); + linphone_friend_list_update_subscriptions(lists->data); + lists = lists->next; + } +} @end diff --git a/Resources/ar.lproj/Localizable.strings b/Resources/ar.lproj/Localizable.strings index 51afad6ca..2ffe410e6 100644 Binary files a/Resources/ar.lproj/Localizable.strings and b/Resources/ar.lproj/Localizable.strings differ diff --git a/Resources/de.lproj/Localizable.strings b/Resources/de.lproj/Localizable.strings index 6e4776deb..c80a3c330 100644 Binary files a/Resources/de.lproj/Localizable.strings and b/Resources/de.lproj/Localizable.strings differ diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings index bf88909cf..bc8499f08 100644 Binary files a/Resources/en.lproj/Localizable.strings and b/Resources/en.lproj/Localizable.strings differ diff --git a/Resources/fr.lproj/Localizable.strings b/Resources/fr.lproj/Localizable.strings index 1745d8bbd..15486845e 100644 Binary files a/Resources/fr.lproj/Localizable.strings and b/Resources/fr.lproj/Localizable.strings differ diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings index 579badcd6..5e589d0b5 100644 Binary files a/Resources/ja.lproj/Localizable.strings and b/Resources/ja.lproj/Localizable.strings differ diff --git a/Resources/nl.lproj/Localizable.strings b/Resources/nl.lproj/Localizable.strings index ffeb605ee..7b40c3461 100644 Binary files a/Resources/nl.lproj/Localizable.strings and b/Resources/nl.lproj/Localizable.strings differ diff --git a/Resources/ru.lproj/Localizable.strings b/Resources/ru.lproj/Localizable.strings index 3a7d21011..d12a7ff87 100644 Binary files a/Resources/ru.lproj/Localizable.strings and b/Resources/ru.lproj/Localizable.strings differ diff --git a/Resources/zh_TW.lproj/Localizable.strings b/Resources/zh_TW.lproj/Localizable.strings index f0e67aa58..5b7ed5d28 100644 Binary files a/Resources/zh_TW.lproj/Localizable.strings and b/Resources/zh_TW.lproj/Localizable.strings differ diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index c0ef95cd5..ccbe50984 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 244523B01E8266CC0037A187 /* chat_error.png in Resources */ = {isa = PBXBuildFile; fileRef = 244523AD1E8266CC0037A187 /* chat_error.png */; }; 244523B11E8266CC0037A187 /* chat_read.png in Resources */ = {isa = PBXBuildFile; fileRef = 244523AE1E8266CC0037A187 /* chat_read.png */; }; 244523BE1E8D3A6C0037A187 /* chat_unsecure.png in Resources */ = {isa = PBXBuildFile; fileRef = 244523BC1E8D3A6C0037A187 /* chat_unsecure.png */; }; + 249660951FD6A35F001D55AA /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 249660941FD6A359001D55AA /* Photos.framework */; }; 24A3459E1D95797700881A5C /* UIShopTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24A3459D1D95797700881A5C /* UIShopTableCell.xib */; }; 24A345A61D95798A00881A5C /* UIShopTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 24A345A51D95798A00881A5C /* UIShopTableCell.m */; }; 24E1C7C01F9A235600D3F981 /* Contacts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24E1C7B91F9A235500D3F981 /* Contacts.framework */; }; @@ -945,6 +946,7 @@ 244523AD1E8266CC0037A187 /* chat_error.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chat_error.png; sourceTree = ""; }; 244523AE1E8266CC0037A187 /* chat_read.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chat_read.png; sourceTree = ""; }; 244523BC1E8D3A6C0037A187 /* chat_unsecure.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chat_unsecure.png; sourceTree = ""; }; + 249660941FD6A359001D55AA /* Photos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Photos.framework; path = System/Library/Frameworks/Photos.framework; sourceTree = SDKROOT; }; 24A3459D1D95797700881A5C /* UIShopTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = UIShopTableCell.xib; sourceTree = ""; }; 24A345A51D95798A00881A5C /* UIShopTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIShopTableCell.m; sourceTree = ""; }; 24A345A71D95799900881A5C /* UIShopTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIShopTableCell.h; sourceTree = ""; }; @@ -1849,6 +1851,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 249660951FD6A35F001D55AA /* Photos.framework in Frameworks */, 24E1C7C01F9A235600D3F981 /* Contacts.framework in Frameworks */, 8C5BCED61EB3859300A9AAEF /* mediastreamer_voip.framework in Frameworks */, 8C2595DF1DEDCC8E007A6424 /* CallKit.framework in Frameworks */, @@ -2210,6 +2213,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 249660941FD6A359001D55AA /* Photos.framework */, 24E1C7B91F9A235500D3F981 /* Contacts.framework */, 8C3EAA191EB8D9C300B732B6 /* linphonetester.framework */, 8C5BCEC61EB3859200A9AAEF /* bctoolbox-tester.framework */,