mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 00:02:47 +00:00
Merge pull request #908 from vector-im/local_contact_sync
The contact book is used to search for users by email or phone number…
This commit is contained in:
commit
05c166b679
6 changed files with 50 additions and 93 deletions
|
@ -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 <MatrixOpenWebRTCWrapper/MatrixOpenWebRTCWrapper.h>
|
||||
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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.";
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue