mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Local contacts: Consider the local contacts when the access is authorized even if the server sync option is disabled.
This commit is contained in:
parent
86aafbe292
commit
56a01f1be2
5 changed files with 96 additions and 12 deletions
|
@ -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 <MatrixOpenWebRTCWrapper/MatrixOpenWebRTCWrapper.h>
|
||||
|
@ -313,6 +316,9 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
// 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 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
[account resume];
|
||||
}
|
||||
|
||||
// refresh the contacts list
|
||||
[MXKContactManager sharedManager].enableFullMatrixIdSyncOnLocalContactsDidLoad = NO;
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -108,6 +108,37 @@
|
|||
[[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
|
||||
|
|
|
@ -1685,6 +1685,8 @@
|
|||
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)
|
||||
{
|
||||
|
@ -1698,6 +1700,18 @@
|
|||
}
|
||||
}];
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#import <Photos/Photos.h>
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -801,6 +801,8 @@
|
|||
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
|
||||
|
@ -817,6 +819,18 @@
|
|||
}];
|
||||
}
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue