Skip to content

Commit

Permalink
Local contacts: Consider the local contacts when the access is author…
Browse files Browse the repository at this point in the history
…ized even if the server sync option is disabled.
  • Loading branch information
giomfo committed Sep 15, 2016
1 parent 86aafbe commit 56a01f1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 12 deletions.
15 changes: 12 additions & 3 deletions Vector/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
}
Expand Down
31 changes: 31 additions & 0 deletions Vector/ViewController/ContactPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions Vector/ViewController/RoomParticipantsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions Vector/ViewController/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion Vector/ViewController/StartChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 56a01f1

Please sign in to comment.