Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the local contacts on first account creation, #942

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 51 additions & 34 deletions Vector/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -486,38 +486,8 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
[account resume];
}

// 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];
}
// Refresh local contact from the contact book.
[self refreshLocalContacts];

_isAppForeground = YES;
}
Expand Down Expand Up @@ -1467,6 +1437,16 @@ - (void)initMatrixSessions
// Observe inApp notifications toggle change
[account addObserver:self forKeyPath:@"enableInAppNotifications" options:0 context:nil];
}

// Load the local contacts on first account creation.
if ([MXKAccountManager sharedManager].accounts.count == 1)
{
dispatch_async(dispatch_get_main_queue(), ^{

[self refreshLocalContacts];

});
}
}];

// Add observer to handle removed accounts
Expand Down Expand Up @@ -1631,8 +1611,7 @@ - (void)logout
// Return to authentication screen
[_homeViewController showAuthenticationScreen];

// Reset App settings
[[MXKAppSettings standardAppSettings] reset];
// Note: Keep App settings

// Reset the contact manager
[[MXKContactManager sharedManager] reset];
Expand Down Expand Up @@ -1995,6 +1974,44 @@ - (void)startDirectChatWithUserId:(NSString*)userId completion:(void (^)(void))c
}];
}

#pragma mark - Contacts handling

- (void)refreshLocalContacts
{
// 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];
}
}

#pragma mark - MXKCallViewControllerDelegate

- (void)dismissCallViewController:(MXKCallViewController *)callViewController completion:(void (^)())completion
Expand Down