diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index a9a61f6ac8..c61e99525c 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -41,6 +41,9 @@ #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 @@ -313,6 +316,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Configure Google Analytics here if the option is enabled [self startGoogleAnalytics]; + // Configure local contacts management + [MXKContactManager sharedManager].enableFullMatrixIdSyncOnLocalContactsDidLoad = NO; + // Add matrix observers, and initialize matrix sessions if the app is not launched in background. [self initMatrixSessions]; @@ -469,9 +475,12 @@ - (void)applicationDidBecomeActive:(UIApplication *)application [account resume]; } - // refresh the contacts list - [MXKContactManager sharedManager].enableFullMatrixIdSyncOnLocalContactsDidLoad = NO; - [[MXKContactManager sharedManager] loadLocalContacts]; + // Check if the application is allowed to access the local contacts + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) + { + // Refresh the local contacts list by reloading it + [[MXKContactManager sharedManager] loadLocalContacts]; + } _isAppForeground = YES; } diff --git a/Vector/ViewController/ContactPickerViewController.m b/Vector/ViewController/ContactPickerViewController.m index 65867c3101..c298b80544 100644 --- a/Vector/ViewController/ContactPickerViewController.m +++ b/Vector/ViewController/ContactPickerViewController.m @@ -108,6 +108,37 @@ - (void)viewWillAppear:(BOOL)animated [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshContactsList) name:kMXKContactManagerDidUpdateMatrixContactsNotification object:nil]; [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 + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) + { + // Try to load the local contacts list + dispatch_async(dispatch_get_main_queue(), ^{ + + [[MXKContactManager sharedManager] loadLocalContacts]; + + }); + } +#endif } - (void)viewWillDisappear:(BOOL)animated diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index c38da87bd1..5596e2e059 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -1684,20 +1684,34 @@ - (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; - } - }]; + 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 + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) + { + // Try to load the local contacts list + dispatch_async(dispatch_get_main_queue(), ^{ + + [[MXKContactManager sharedManager] loadLocalContacts]; + + }); } +#endif return YES; } diff --git a/Vector/ViewController/SettingsViewController.m b/Vector/ViewController/SettingsViewController.m index 6924d2d106..2702498e38 100644 --- a/Vector/ViewController/SettingsViewController.m +++ b/Vector/ViewController/SettingsViewController.m @@ -27,6 +27,8 @@ #import #import +#ifdef MX_USE_CONTACTS_SERVER_SYNC + #define SETTINGS_SECTION_SIGN_OUT_INDEX 0 #define SETTINGS_SECTION_USER_SETTINGS_INDEX 1 #define SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX 2 @@ -37,6 +39,20 @@ #define SETTINGS_SECTION_LABS_INDEX 7 #define SETTINGS_SECTION_COUNT 7 // Not 8 because the LABS section is currently hidden +#else + +#define SETTINGS_SECTION_SIGN_OUT_INDEX 0 +#define SETTINGS_SECTION_USER_SETTINGS_INDEX 1 +#define SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX 2 +#define SETTINGS_SECTION_IGNORED_USERS_INDEX 3 +#define SETTINGS_SECTION_ADVANCED_INDEX 4 +#define SETTINGS_SECTION_OTHER_INDEX 5 +#define SETTINGS_SECTION_CONTACTS_INDEX 6 +#define SETTINGS_SECTION_LABS_INDEX 7 +#define SETTINGS_SECTION_COUNT 6 // Not 8 because the CONTACTS and LABS section is currently hidden + +#endif + #define NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX 0 #define NOTIFICATION_SETTINGS_GLOBAL_SETTINGS_INDEX 1 //#define NOTIFICATION_SETTINGS_CONTAINING_MY_USER_NAME_INDEX 1 diff --git a/Vector/ViewController/StartChatViewController.m b/Vector/ViewController/StartChatViewController.m index d9ae0e4675..3b4ba4cb4e 100644 --- a/Vector/ViewController/StartChatViewController.m +++ b/Vector/ViewController/StartChatViewController.m @@ -801,13 +801,15 @@ - (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) { @@ -817,6 +819,18 @@ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar }]; } } +#else + // If not requested yet, ask user permission to access their local contacts + if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) + { + // Try to load the local contacts list + dispatch_async(dispatch_get_main_queue(), ^{ + + [[MXKContactManager sharedManager] loadLocalContacts]; + + }); + } +#endif return YES; }