Skip to content

Commit

Permalink
Merge pull request #1364 from nextcloud/combine-contacts-in-room-list
Browse files Browse the repository at this point in the history
Combine contacts in room list
  • Loading branch information
SystemKeeper committed Sep 27, 2023
2 parents 6555df1 + 179978b commit e5ede87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NextcloudTalk/NCContactsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#import "ABContact.h"
#import "NCContact.h"

#import "NextcloudTalk-Swift.h"

@interface NCContactsManager ()

@property (nonatomic, strong) CNContactStore *contactStore;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -190,6 +193,7 @@ - (void)searchForPhoneNumbers:(NSDictionary *)phoneNumbers forAccount:(TalkAccou
[[NSNotificationCenter defaultCenter] postNotificationName:NCContactsManagerContactsUpdatedNotification
object:self
userInfo:nil];
[bgTask stopBackgroundTask];
}];
}
}];
Expand Down
13 changes: 12 additions & 1 deletion NextcloudTalk/RoomsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion NextcloudTalk/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e5ede87

Please sign in to comment.