Skip to content

Commit

Permalink
Merge pull request #942 from vector-im/keep_app_settings_on_logout
Browse files Browse the repository at this point in the history
Load the local contacts on first account creation,
  • Loading branch information
giomfo committed Jan 18, 2017
2 parents fc5a319 + d44b2ca commit bdcedd3
Showing 1 changed file with 51 additions and 34 deletions.
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

0 comments on commit bdcedd3

Please sign in to comment.