diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 78bc07182..7dcf2d18e 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -16,7 +16,6 @@ @property(nonatomic, strong) NSMutableDictionary *contacts; @property(nonatomic, strong) NSDictionary *allContacts; -@property(nonatomic, strong) NSMutableArray *contactsAddresses; @property(nonatomic, strong) NSArray *sortedAddresses; @end @@ -40,8 +39,7 @@ } return; } - self.contacts = [[NSMutableDictionary alloc] initWithCapacity:_allContacts.count]; - self.contactsAddresses = [NSMutableArray array]; + _contacts = [[NSMutableDictionary alloc] initWithCapacity:_allContacts.count]; _contactsGroup = [[NSMutableArray alloc] init]; _allFilter = TRUE; @@ -83,47 +81,9 @@ } - (void)reloadDataWithFilter:(NSString *)filter { - _allContacts = [[NSDictionary alloc] initWithDictionary:LinphoneManager.instance.fastAddressBook.addressBookMap]; + [_contacts removeAllObjects]; - if (_allFilter) { - [_contacts removeAllObjects]; - [_contactsAddresses removeAllObjects]; - for (NSString* key in _sortedAddresses){ - NSString *address = (NSString *)key; - NSString *name = [FastAddressBook displayNameForContact:[_allContacts objectForKey:key]]; - if ((filter.length == 0) || ([name.lowercaseString containsSubstring:filter.lowercaseString]) || - ([address.lowercaseString containsSubstring:filter.lowercaseString])) { - [_contacts setObject:name forKey:address] ; - [_contactsAddresses insertObject:address atIndex:[_contactsAddresses count]]; - } - } else { - NSMutableArray *keys = [[NSMutableArray alloc] init]; - [_allContacts enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { - NSString *address = (NSString *)key; - Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:address]; - Boolean linphoneContact = [FastAddressBook contactHasValidSipDomain:contact] - || (contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(contact.friend)) == LinphonePresenceBasicStatusOpen); - - if (linphoneContact) - [keys addObject:key]; - }]; - self.sortedAddresses = [keys sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { - Contact* first = [_allContacts objectForKey:a]; - Contact* second = [_allContacts objectForKey:b]; - - if([[first.firstName lowercaseString] compare:[second.firstName lowercaseString]] == NSOrderedSame) - return [[first.lastName lowercaseString] compare:[second.lastName lowercaseString]]; - else - return [[first.firstName lowercaseString] compare:[second.firstName lowercaseString]]; - }]; - } - - if (_contacts) - [_contacts removeAllObjects]; - else - _contacts = [[NSMutableDictionary alloc] initWithCapacity:_allContacts.count]; - - for (NSString* key in _sortedAddresses){ + for (NSString* key in _sortedAddresses) { Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:key]; NSString *name = [FastAddressBook displayNameForContact:contact]; Boolean linphoneContact = [FastAddressBook contactHasValidSipDomain:contact] @@ -148,8 +108,7 @@ } if (nsuri.length > 0 && [_contacts valueForKey:nsuri] == nil) { - [_contacts setObject:filter forKey:nsuri] ; - [_contactsAddresses insertObject:nsuri atIndex:[_contactsAddresses count]]; + [_contacts setObject:filter forKey:nsuri]; } [self.tableView reloadData]; @@ -162,7 +121,7 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [self.contactsAddresses count]; + return _contacts.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -176,11 +135,9 @@ Boolean linphoneContact = [FastAddressBook contactHasValidSipDomain:contact] || (contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(contact.friend)) == LinphonePresenceBasicStatusOpen); cell.linphoneImage.hidden = !linphoneContact; - LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:[_sortedAddresses objectAtIndex:indexPath.row]]; - cell.displayNameLabel.text = [_contacts objectForKey:[_sortedAddresses objectAtIndex:indexPath.row]]; - cell.addressLabel.text = addr - ? [NSString stringWithUTF8String:linphone_address_as_string(addr)] - : key; + LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:key]; + cell.displayNameLabel.text = [FastAddressBook displayNameForAddress:addr]; + cell.addressLabel.text = [NSString stringWithUTF8String:linphone_address_as_string(addr)]; cell.selectedImage.hidden = ![_contactsGroup containsObject:cell.addressLabel.text]; return cell;