Local contacts: Consider the local contacts when the access is authorized even if the server sync option is disabled.

This commit is contained in:
giomfo 2016-09-15 09:44:22 +02:00
parent 86aafbe292
commit 56a01f1be2
5 changed files with 96 additions and 12 deletions

View file

@ -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;
[[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;
}

View file

@ -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

View file

@ -1685,19 +1685,33 @@
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;
}

View file

@ -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

View file

@ -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;
}