mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Fix crash that would occur when typing too fast in the chatroom creation search bar (race condition), and fix possible infinite loop when having some specific conditions in the phone contacts
This commit is contained in:
parent
ebbc94fccf
commit
51876c9c06
1 changed files with 69 additions and 63 deletions
|
|
@ -93,68 +93,71 @@
|
|||
_loadingView.hidden = FALSE;
|
||||
}
|
||||
- (void)onChatMagicSearchFinished:(NSNotification *)k {
|
||||
[self buildChatContactTable];
|
||||
_loadingView.hidden = TRUE;
|
||||
@synchronized(self) {
|
||||
[self buildChatContactTable];
|
||||
_loadingView.hidden = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) buildChatContactTable {
|
||||
[_ldapContactAddressBookMap removeAllObjects];
|
||||
bctbx_list_t *results = [MagicSearchSingleton.instance getLastSearchResults];
|
||||
while (results) {
|
||||
|
||||
LinphoneSearchResult *result = results->data;
|
||||
const LinphoneAddress *addr = linphone_search_result_get_address(result);
|
||||
|
||||
const char *phoneNumber = NULL;
|
||||
Contact *contact = nil;
|
||||
char *uri = nil;
|
||||
NSString *address = nil;
|
||||
if (addr) {
|
||||
uri = linphone_address_as_string_uri_only(addr);
|
||||
address = [NSString stringWithUTF8String:uri];
|
||||
contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:address]];
|
||||
}
|
||||
|
||||
const LinphoneFriend* friend = linphone_search_result_get_friend(result);
|
||||
if (!addr || (!contact && friend)) {
|
||||
phoneNumber = linphone_search_result_get_phone_number(result);
|
||||
if (!phoneNumber) {
|
||||
bctbx_list_t *results = [MagicSearchSingleton.instance getLastSearchResults];
|
||||
while (results) {
|
||||
|
||||
LinphoneSearchResult *result = results->data;
|
||||
const LinphoneAddress *addr = linphone_search_result_get_address(result);
|
||||
|
||||
const char *phoneNumber = NULL;
|
||||
Contact *contact = nil;
|
||||
char *uri = nil;
|
||||
NSString *address = nil;
|
||||
if (addr) {
|
||||
uri = linphone_address_as_string_uri_only(addr);
|
||||
address = [NSString stringWithUTF8String:uri];
|
||||
contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:address]];
|
||||
}
|
||||
|
||||
const LinphoneFriend* friend = linphone_search_result_get_friend(result);
|
||||
if (!addr || (!contact && friend)) {
|
||||
phoneNumber = linphone_search_result_get_phone_number(result);
|
||||
if (!phoneNumber) {
|
||||
results = results->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
LinphoneAccount *account = linphone_core_get_default_account(LC);
|
||||
if (account) {
|
||||
const char *normalizedPhoneNumber = linphone_account_normalize_phone_number(account, phoneNumber);
|
||||
if (!normalizedPhoneNumber) {
|
||||
// get invalid phone number, continue
|
||||
results = results->next;
|
||||
continue;
|
||||
}
|
||||
addr = linphone_account_normalize_sip_uri(account, normalizedPhoneNumber);
|
||||
uri = linphone_address_as_string_uri_only(addr);
|
||||
address = [NSString stringWithUTF8String:uri];
|
||||
|
||||
contact = [[Contact alloc] initWithFriend:friend];
|
||||
[contact setCreatedFromLdap:TRUE];
|
||||
[_ldapContactAddressBookMap setObject:contact forKey:address];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!addr) {
|
||||
results = results->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
LinphoneAccount *account = linphone_core_get_default_account(LC);
|
||||
if (account) {
|
||||
const char *normalizedPhoneNumber = linphone_account_normalize_phone_number(account, phoneNumber);
|
||||
if (!normalizedPhoneNumber) {
|
||||
// get invalid phone number, continue
|
||||
continue;
|
||||
}
|
||||
addr = linphone_account_normalize_sip_uri(account, normalizedPhoneNumber);
|
||||
uri = linphone_address_as_string_uri_only(addr);
|
||||
address = [NSString stringWithUTF8String:uri];
|
||||
|
||||
contact = [[Contact alloc] initWithFriend:friend];
|
||||
[contact setCreatedFromLdap:TRUE];
|
||||
[_ldapContactAddressBookMap setObject:contact forKey:address];
|
||||
}
|
||||
ms_free(uri);
|
||||
|
||||
[_addresses addObject:address];
|
||||
[_phoneOrAddr addObject:phoneNumber ? [NSString stringWithUTF8String:phoneNumber] : address];
|
||||
[_addressesCached addObject:[NSString stringWithFormat:@"%d",linphone_search_result_get_capabilities(result)]];
|
||||
|
||||
}
|
||||
|
||||
if (!addr) {
|
||||
results = results->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
ms_free(uri);
|
||||
|
||||
[_addresses addObject:address];
|
||||
[_phoneOrAddr addObject:phoneNumber ? [NSString stringWithUTF8String:phoneNumber] : address];
|
||||
[_addressesCached addObject:[NSString stringWithFormat:@"%d",linphone_search_result_get_capabilities(result)]];
|
||||
|
||||
results = results->next;
|
||||
}
|
||||
_reloadMagicSearch = FALSE;
|
||||
[self.tableView reloadData];
|
||||
_reloadMagicSearch = FALSE;
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void) loadData {
|
||||
|
|
@ -162,16 +165,19 @@
|
|||
}
|
||||
|
||||
- (void)reloadDataWithFilter:(NSString *)filter {
|
||||
[_addresses removeAllObjects];
|
||||
[_phoneOrAddr removeAllObjects];
|
||||
[_addressesCached removeAllObjects];
|
||||
_reloadMagicSearch = _reloadMagicSearch || [filter length]==0 || ![[MagicSearchSingleton.instance currentFilter] isEqualToString:filter];
|
||||
[MagicSearchSingleton.instance setCurrentFilter:filter];
|
||||
|
||||
if (_reloadMagicSearch) {
|
||||
[MagicSearchSingleton.instance searchForContactsWithDomain:_allFilter ? @"" : @"*" sourceFlags:LinphoneMagicSearchSourceAll clearCache:FALSE];
|
||||
} else {
|
||||
[self buildChatContactTable];
|
||||
@synchronized(self) {
|
||||
[_addresses removeAllObjects];
|
||||
[_phoneOrAddr removeAllObjects];
|
||||
[_addressesCached removeAllObjects];
|
||||
[_ldapContactAddressBookMap removeAllObjects];
|
||||
_reloadMagicSearch = _reloadMagicSearch || [filter length]==0 || ![[MagicSearchSingleton.instance currentFilter] isEqualToString:filter];
|
||||
[MagicSearchSingleton.instance setCurrentFilter:filter];
|
||||
|
||||
if (_reloadMagicSearch) {
|
||||
[MagicSearchSingleton.instance searchForContactsWithDomain:_allFilter ? @"" : @"*" sourceFlags:LinphoneMagicSearchSourceAll clearCache:FALSE];
|
||||
} else {
|
||||
[self buildChatContactTable];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue