diff --git a/NextcloudTalk/NCContactsManager.m b/NextcloudTalk/NCContactsManager.m index 50e6a1af4..df260ae75 100644 --- a/NextcloudTalk/NCContactsManager.m +++ b/NextcloudTalk/NCContactsManager.m @@ -30,6 +30,8 @@ #import "ABContact.h" #import "NCContact.h" +#import "NextcloudTalk-Swift.h" + @interface NCContactsManager () @property (nonatomic, strong) CNContactStore *contactStore; @@ -158,6 +160,7 @@ - (void)searchForPhoneNumbers:(NSDictionary *)phoneNumbers forAccount:(TalkAccou { [[NCAPIController sharedInstance] searchContactsForAccount:account withPhoneNumbers:phoneNumbers andCompletionBlock:^(NSDictionary *contacts, NSError *error) { if (!error) { + BGTaskHelper *bgTask = [BGTaskHelper startBackgroundTaskWithName:@"NCUpdateContacts" expirationHandler:nil]; RLMRealm *realm = [RLMRealm defaultRealm]; [realm transactionWithBlock:^{ NSInteger updateTimestamp = [[NSDate date] timeIntervalSince1970]; @@ -190,6 +193,7 @@ - (void)searchForPhoneNumbers:(NSDictionary *)phoneNumbers forAccount:(TalkAccou [[NSNotificationCenter defaultCenter] postNotificationName:NCContactsManagerContactsUpdatedNotification object:self userInfo:nil]; + [bgTask stopBackgroundTask]; }]; } }]; diff --git a/NextcloudTalk/RoomsTableViewController.m b/NextcloudTalk/RoomsTableViewController.m index 6756cb121..fb2899be6 100644 --- a/NextcloudTalk/RoomsTableViewController.m +++ b/NextcloudTalk/RoomsTableViewController.m @@ -236,8 +236,13 @@ - (void)dealloc - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + [self adaptInterfaceForAppState:[NCConnectionController sharedInstance].appState]; [self adaptInterfaceForConnectionState:[NCConnectionController sharedInstance].connectionState]; + + if ([[NCSettingsController sharedInstance] isContactSyncEnabled] && [[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityPhonebookSearch]) { + [[NCContactsManager sharedInstance] searchInServerForAddressBookContacts:NO]; + } } - (void)viewWillAppear:(BOOL)animated @@ -550,7 +555,13 @@ - (void)searchListableRoomsAndMessages _resultTableViewController.users = @[]; [[NCAPIController sharedInstance] getContactsForAccount:account forRoom:nil groupRoom:NO withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) { if (!error) { - self->_resultTableViewController.users = [self usersWithoutOneToOneConversations:contactList]; + NSArray *users = [self usersWithoutOneToOneConversations:contactList]; + if ([[NCSettingsController sharedInstance] isContactSyncEnabled] && [[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityPhonebookSearch]) { + TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount]; + NSArray *addressBookContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:nil]; + users = [NCUser combineUsersArray:addressBookContacts withUsersArray:users]; + } + self->_resultTableViewController.users = users; } }]; // Search for listable rooms diff --git a/NextcloudTalk/SettingsTableViewController.swift b/NextcloudTalk/SettingsTableViewController.swift index 0b4d3debf..070400b80 100644 --- a/NextcloudTalk/SettingsTableViewController.swift +++ b/NextcloudTalk/SettingsTableViewController.swift @@ -283,12 +283,14 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate { @objc func contactsHaveBeenUpdated(notification: NSNotification) { DispatchQueue.main.async { + self.activeAccount = NCDatabaseManager.sharedInstance().activeAccount() self.tableView.reloadData() } } @objc func contactsAccessHasBeenUpdated(notification: NSNotification) { DispatchQueue.main.async { + self.activeAccount = NCDatabaseManager.sharedInstance().activeAccount() self.tableView.reloadData() } } @@ -753,6 +755,17 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate { } } + func didSelectAccountSettingsSectionCell(for indexPath: IndexPath) { + let options = getAccountSettingsSectionOptions() + let option = options[indexPath.row] + switch option { + case AccountSettingsOptions.kAccountSettingsContactsSync.rawValue: + NCContactsManager.sharedInstance().searchInServer(forAddressBookContacts: true) + default: + break + } + } + func didSelectSettingsSectionCell(for indexPath: IndexPath) { let options = getConfigurationSectionOptions() let option = options[indexPath.row] @@ -806,6 +819,9 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate { case SettingsSection.kSettingsSectionUserStatus.rawValue: self.presentUserStatusOptions() + case SettingsSection.kSettingsSectionAccountSettings.rawValue: + self.didSelectAccountSettingsSectionCell(for: indexPath) + case SettingsSection.kSettingsSectionOtherAccounts.rawValue: self.didSelectOtherAccountSectionCell(for: indexPath) @@ -869,7 +885,7 @@ extension SettingsTableViewController { cell = tableView.dequeueReusableCell(withIdentifier: contactsSyncCellIdentifier) ?? UITableViewCell(style: .subtitle, reuseIdentifier: contactsSyncCellIdentifier) cell.textLabel?.text = NSLocalizedString("Phone number integration", comment: "") cell.detailTextLabel?.text = NSLocalizedString("Match system contacts", comment: "") - cell.selectionStyle = .none + cell.selectionStyle = contactSyncSwitch.isOn ? .default : .none cell.imageView?.image = UIImage(systemName: "iphone")?.applyingSymbolConfiguration(iconConfiguration) cell.imageView?.tintColor = .secondaryLabel cell.accessoryView = contactSyncSwitch