From f9db15888cb535a3548613894d157cb85bc75448 Mon Sep 17 00:00:00 2001 From: giomfo Date: Thu, 5 Jan 2017 15:44:00 +0100 Subject: [PATCH] The contact book is used to search for users by email or phone number on Riot. - Update `NSContactsUsageDescription` to turn on by default the matrix user discovering when the user allows the access to the local contacts. - Ask to the existing users the permission to upload emails when the contact access is already granted. - Update matrix ids for all the local contacts in only one request when device contacts are loaded and an identity server is available. --- Vector/AppDelegate.m | 33 +++++++++++++--- Vector/Assets/InfoPlist.strings | 2 +- .../ContactPickerViewController.m | 32 +++------------- .../RoomParticipantsViewController.m | 35 ++++------------- .../ViewController/SettingsViewController.m | 3 -- .../ViewController/StartChatViewController.m | 38 ++++--------------- 6 files changed, 50 insertions(+), 93 deletions(-) diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index 163257061..0b813b4aa 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -41,9 +41,6 @@ #import "CallViewController.h" -// Uncomment the following line to use local contacts to discover matrix users. -//#define MX_USE_CONTACTS_SERVER_SYNC - //#define MX_CALL_STACK_OPENWEBRTC #ifdef MX_CALL_STACK_OPENWEBRTC #import @@ -322,7 +319,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN [self startGoogleAnalytics]; // Configure local contacts management - [MXKContactManager sharedManager].enableFullMatrixIdSyncOnLocalContactsDidLoad = NO; + [MXKContactManager sharedManager].enableFullMatrixIdSyncOnLocalContactsDidLoad = YES; // Add matrix observers, and initialize matrix sessions if the app is not launched in background. [self initMatrixSessions]; @@ -489,9 +486,35 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN [account resume]; } - // Check if the application is allowed to access the local contacts + // Check whether the application is allowed to access the local contacts. if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { + // Check the user permission for syncing local contacts. This permission was handled independently on previous application version. + if (![MXKAppSettings standardAppSettings].syncLocalContacts) + { + // Check whether it was not requested yet. + if (![MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested) + { + [MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested = YES; + + UIViewController *viewController = self.window.rootViewController.presentedViewController; + if (!viewController) + { + viewController = self.window.rootViewController; + } + + [MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:viewController completionHandler:^(BOOL granted) { + + if (granted) + { + // Allow local contacts sync in order to discover matrix users. + [MXKAppSettings standardAppSettings].syncLocalContacts = YES; + } + + }]; + } + } + // Refresh the local contacts list by reloading it [[MXKContactManager sharedManager] loadLocalContacts]; } diff --git a/Vector/Assets/InfoPlist.strings b/Vector/Assets/InfoPlist.strings index a3954f654..9e2639cea 100644 --- a/Vector/Assets/InfoPlist.strings +++ b/Vector/Assets/InfoPlist.strings @@ -18,5 +18,5 @@ "NSCameraUsageDescription" = "The camera is used to take photos and videos, make video calls."; "NSPhotoLibraryUsageDescription" = "The photo library is used to send photos and videos."; "NSMicrophoneUsageDescription" = "The microphone is used to take videos, make calls."; -"NSContactsUsageDescription" = "The contact book is used to send room invitation to your contacts with their emails."; +"NSContactsUsageDescription" = "The contact book is used to search for users by email or phone number on Riot."; diff --git a/Vector/ViewController/ContactPickerViewController.m b/Vector/ViewController/ContactPickerViewController.m index 806fb2af1..987ca922b 100644 --- a/Vector/ViewController/ContactPickerViewController.m +++ b/Vector/ViewController/ContactPickerViewController.m @@ -114,36 +114,14 @@ [self refreshContactsList]; - // Handle here local contacts -#ifdef MX_USE_CONTACTS_SERVER_SYNC - if (![MXKAppSettings standardAppSettings].syncLocalContacts) - { - // If not requested yet, ask user permission to sync their local contacts - if (![MXKAppSettings standardAppSettings].syncLocalContacts && ![MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested) - { - [MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested = YES; - - [MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:self completionHandler:^(BOOL granted) { - if (granted) - { - // Allow local contacts sync in order to add address book emails in search result - [MXKAppSettings standardAppSettings].syncLocalContacts = YES; - } - }]; - } - } -#else - // If not requested yet, ask user permission to access their local contacts + // Check whether the access to the local contacts has not been already asked. if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { - // Try to load the local contacts list - dispatch_async(dispatch_get_main_queue(), ^{ - - [[MXKContactManager sharedManager] loadLocalContacts]; - - }); + // Allow by default the local contacts sync in order to discover matrix users. + // This setting change will trigger the loading of the local contacts, which will automatically + // ask user permission to access their local contacts. + [MXKAppSettings standardAppSettings].syncLocalContacts = YES; } -#endif } - (void)viewWillDisappear:(BOOL)animated diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index 807a7011d..438e452fe 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -1773,36 +1773,17 @@ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { - self.isAddParticipantSearchBarEditing = YES; - searchBar.showsCancelButton = YES; - - // Handle here local contacts -#ifdef MX_USE_CONTACTS_SERVER_SYNC - // If not requested yet, ask user permission to sync their local contacts - if (![MXKAppSettings standardAppSettings].syncLocalContacts && ![MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested) - { - [MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested = YES; - - [MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:self completionHandler:^(BOOL granted) { - if (granted) - { - // Allow local contacts sync in order to add address book emails in search result - [MXKAppSettings standardAppSettings].syncLocalContacts = YES; - } - }]; - } -#else - // If not requested yet, ask user permission to access their local contacts + // Check whether the access to the local contacts has been already asked. if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { - // Try to load the local contacts list - dispatch_async(dispatch_get_main_queue(), ^{ - - [[MXKContactManager sharedManager] loadLocalContacts]; - - }); + // Allow by default the local contacts sync in order to discover matrix users. + // This setting change will trigger the loading of the local contacts, which will automatically + // ask user permission to access their local contacts. + [MXKAppSettings standardAppSettings].syncLocalContacts = YES; } -#endif + + self.isAddParticipantSearchBarEditing = YES; + searchBar.showsCancelButton = YES; return YES; } diff --git a/Vector/ViewController/SettingsViewController.m b/Vector/ViewController/SettingsViewController.m index 47f6b64fd..e966f7f88 100644 --- a/Vector/ViewController/SettingsViewController.m +++ b/Vector/ViewController/SettingsViewController.m @@ -37,9 +37,6 @@ enum { SETTINGS_SECTION_CONTACTS_INDEX, SETTINGS_SECTION_ADVANCED_INDEX, SETTINGS_SECTION_OTHER_INDEX, -#ifdef MX_USE_CONTACTS_SERVER_SYNC - SETTINGS_SECTION_CONTACTS_INDEX, -#endif SETTINGS_SECTION_LABS_INDEX, SETTINGS_SECTION_CRYPTOGRAPHY_INDEX, SETTINGS_SECTION_DEVICES_INDEX, diff --git a/Vector/ViewController/StartChatViewController.m b/Vector/ViewController/StartChatViewController.m index 6378ad1d4..da4fc3711 100644 --- a/Vector/ViewController/StartChatViewController.m +++ b/Vector/ViewController/StartChatViewController.m @@ -860,39 +860,17 @@ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { - self.isAddParticipantSearchBarEditing = YES; - searchBar.showsCancelButton = NO; - - // Handle here local contacts -#ifdef MX_USE_CONTACTS_SERVER_SYNC - if (![MXKAppSettings standardAppSettings].syncLocalContacts) - { - // If not requested yet, ask user permission to sync their local contacts - if (![MXKAppSettings standardAppSettings].syncLocalContacts && ![MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested) - { - [MXKAppSettings standardAppSettings].syncLocalContactsPermissionRequested = YES; - - [MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:self completionHandler:^(BOOL granted) { - if (granted) - { - // Allow local contacts sync in order to add address book emails in search result - [MXKAppSettings standardAppSettings].syncLocalContacts = YES; - } - }]; - } - } -#else - // If not requested yet, ask user permission to access their local contacts + // Check whether the access to the local contacts has not been already asked. if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { - // Try to load the local contacts list - dispatch_async(dispatch_get_main_queue(), ^{ - - [[MXKContactManager sharedManager] loadLocalContacts]; - - }); + // Allow by default the local contacts sync in order to discover matrix users. + // This setting change will trigger the loading of the local contacts, which will automatically + // ask user permission to access their local contacts. + [MXKAppSettings standardAppSettings].syncLocalContacts = YES; } -#endif + + self.isAddParticipantSearchBarEditing = YES; + searchBar.showsCancelButton = NO; return YES; }