mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-16 12:49:59 +02:00
Merge pull request #4619 from vector-im/doug/4616_access_contacts_when_needed
Delay access to local contacts until they're needed for display
This commit is contained in:
@@ -9,6 +9,7 @@ Changes to be released in next version
|
||||
* Rooms Tab: Remove the directory section (#4521).
|
||||
* Notifications: Show decrypted content is enabled by default (#4519).
|
||||
* People Tab: Remove the local contacts section (#4523).
|
||||
* Contacts: Delay access to local contacts until they're needed for display (#4616).
|
||||
|
||||
🐛 Bugfix
|
||||
* Room: Fixed mentioning users from room info member details (#4583)
|
||||
|
||||
@@ -1854,16 +1854,6 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
||||
[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];
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
[self.delegate legacyAppDelegate:self didAddAccount:account];
|
||||
}];
|
||||
|
||||
@@ -1976,14 +1966,6 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
||||
// during this blocking task.
|
||||
dispatch_after(dispatch_walltime(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||
[[MXKContactManager sharedManager] addMatrixSession:mxSession];
|
||||
|
||||
// Load the local contacts on first account
|
||||
if ([MXKAccountManager sharedManager].accounts.count == 1)
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self refreshLocalContacts];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Register the session to the widgets manager
|
||||
@@ -2939,54 +2921,6 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)refreshLocalContacts
|
||||
{
|
||||
if (!BuildSettings.allowLocalContactsAccess)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not scan local contacts in background if the user has not decided yet about using
|
||||
// an identity server
|
||||
BOOL doRefreshLocalContacts = NO;
|
||||
for (MXSession *session in mxSessionArray)
|
||||
{
|
||||
if (session.hasAccountDataIdentityServerValue)
|
||||
{
|
||||
doRefreshLocalContacts = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the application is allowed to access the local contacts.
|
||||
if (doRefreshLocalContacts
|
||||
&& [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized)
|
||||
{
|
||||
// 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;
|
||||
|
||||
[MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:self.presentedViewController completionHandler:^(BOOL granted) {
|
||||
|
||||
if (granted)
|
||||
{
|
||||
// Allow local contacts sync in order to discover matrix users.
|
||||
[MXKAppSettings standardAppSettings].syncLocalContacts = YES;
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh the local contacts list.
|
||||
[[MXKContactManager sharedManager] refreshLocalContacts];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Matrix Groups handling
|
||||
|
||||
- (void)showGroup:(MXGroup*)group withMatrixSession:(MXSession*)mxSession
|
||||
|
||||
@@ -174,6 +174,15 @@
|
||||
[self refreshContactsTable];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
[super viewDidAppear:animated];
|
||||
|
||||
// Load the local contacts for display.
|
||||
// In viewDidAppear as it may trigger a request for contacts access.
|
||||
[self refreshLocalContacts];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
@@ -212,6 +221,54 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)refreshLocalContacts
|
||||
{
|
||||
if (!BuildSettings.allowLocalContactsAccess)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not scan local contacts in background if the user has not decided yet about using
|
||||
// an identity server
|
||||
BOOL doRefreshLocalContacts = NO;
|
||||
for (MXSession *session in self.mxSessions)
|
||||
{
|
||||
if (session.hasAccountDataIdentityServerValue)
|
||||
{
|
||||
doRefreshLocalContacts = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the application is allowed to access the local contacts.
|
||||
if (doRefreshLocalContacts
|
||||
&& [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized)
|
||||
{
|
||||
// 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;
|
||||
|
||||
[MXKContactManager requestUserConfirmationForLocalContactsSyncInViewController:self completionHandler:^(BOOL granted) {
|
||||
|
||||
if (granted)
|
||||
{
|
||||
// Allow local contacts sync in order to discover matrix users.
|
||||
[MXKAppSettings standardAppSettings].syncLocalContacts = YES;
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh the local contacts list.
|
||||
[[MXKContactManager sharedManager] refreshLocalContacts];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)refreshContactsTable
|
||||
{
|
||||
[self.contactsTableView reloadData];
|
||||
|
||||
Reference in New Issue
Block a user