From e98469ec9c25919ad83ca5ff64ee6c622f723ce2 Mon Sep 17 00:00:00 2001 From: Paul Cartier Date: Thu, 23 Apr 2020 14:12:22 +0200 Subject: [PATCH] Fix address book UserDefaults --- Classes/Utils/FastAddressBook.m | 20 +++++++++++++++++-- .../NotificationService.swift | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index cb54275ca..cde589599 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -510,7 +510,7 @@ LinphoneAddress *addr = linphone_address_new(name.UTF8String); if (linphone_proxy_config_is_phone_number(cfg, linphone_address_get_username(addr))) { - if (oldDisplayNames[name] != nil && oldDisplayNames[name] != [contact displayName]) { + if (oldDisplayNames[name] != nil && [FastAddressBook isSipURI:oldDisplayNames[name]]) { NSString *addrForTel = [NSString stringWithString:oldDisplayNames[name]]; /* we keep the link between tel number and sip addr to have the information quickly. If we don't do that, between the startup and presence callback we don't have the dispay name for this address */ @@ -533,6 +533,23 @@ NSMutableDictionary *displayNames = [[NSMutableDictionary alloc] initWithDictionary:[defaults dictionaryForKey:@"addressBook"]]; if (displayNames == nil) return; + LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(LC); + for (NSString *phone in contact.phones) { + char *normalizedPhone = cfg? linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), phone.UTF8String) : nil; + NSString *name = [FastAddressBook normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone]; + if (phone != NULL) { + if ([FastAddressBook isSipURI:displayNames[name]]) { + LOGD(@"removed %s from userdefaults addressBook", ((NSString *)displayNames[name]).UTF8String); + [displayNames removeObjectForKey:displayNames[name]]; + } + [displayNames removeObjectForKey:name]; + LOGD(@"removed %s from userdefaults addressBook", ((NSString *)name).UTF8String); + } + + if (normalizedPhone) + ms_free(normalizedPhone); + } + NSMutableArray *addresses = contact.sipAddresses; for (id addr in addresses) { [displayNames removeObjectForKey:addr]; @@ -543,7 +560,6 @@ } - (void)onPresenceChanged:(NSNotification *)k { - LinphoneFriend *f = [[k.userInfo valueForKey:@"friend"] pointerValue]; NSString *uri = [NSString stringWithUTF8String:[[k.userInfo valueForKey:@"uri"] pointerValue]]; if (![FastAddressBook isSipURI:uri]) { LOGD(@"presence changed for tel [%s]", uri.UTF8String); diff --git a/msgNotificationService/NotificationService.swift b/msgNotificationService/NotificationService.swift index 207e24793..11c747088 100644 --- a/msgNotificationService/NotificationService.swift +++ b/msgNotificationService/NotificationService.swift @@ -216,7 +216,7 @@ class NotificationService: UNNotificationServiceExtension { let addressBook = defaults?.dictionary(forKey: "addressBook") if (addressBook == nil) { - NotificationService.log.message(msg: "address book not found in user defaults") + NotificationService.log.message(msg: "address book not found in userDefaults") return nil } @@ -224,7 +224,7 @@ class NotificationService: UNNotificationServiceExtension { NotificationService.log.message(msg: "display name for \(sipAddr): \(displayName)") return displayName } else { - NotificationService.log.message(msg: "address book not found in user defaults") + NotificationService.log.message(msg: "display name for \(sipAddr) not found in userDefaults") return nil } }