From 321b3550be72bad4a84b3ed8f0a1543827367c9e Mon Sep 17 00:00:00 2001 From: Brieuc Viel Date: Wed, 17 Jan 2018 15:59:38 +0100 Subject: [PATCH] [Contact] fix fetch Contact -> SIP service only ++ --- Classes/Contact.m | 27 +++++++++++++++------------ Classes/ContactDetailsTableView.m | 21 +++++++++++++++++---- Classes/LinphoneManager.m | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Classes/Contact.m b/Classes/Contact.m index d7a5ad375..4974e1339 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -40,11 +40,14 @@ if (_person.instantMessageAddresses != NULL) { for (CNLabeledValue *sipAddr in _person.instantMessageAddresses) { NSString *username = sipAddr.value.username; - if (username) - [_sipAddresses addObject:username]; + NSString *service = sipAddr.value.service; + if (username && ([service isEqualToString:LinphoneManager.instance.contactSipField] || ([service isEqualToString:@"INSTANT_MESSAGING_NAME"] && [FastAddressBook isSipURI:username]))){ + [_sipAddresses addObject:username]; + } } } } + for (CNLabeledValue *email in _person.emailAddresses) { [_emails addObject:email.value]; } @@ -225,11 +228,11 @@ CNInstantMessageAddress *cNSipMsgAddr; if ([normSip containsString:@"@"]) cNSipMsgAddr = [[CNInstantMessageAddress alloc] - initWithUsername:normSip service:[normSip componentsSeparatedByString:@"@"][1]]; + initWithUsername:normSip service:@"SIP"];//service:[normSip componentsSeparatedByString:@"@"][1]]; else cNSipMsgAddr = [[CNInstantMessageAddress alloc] initWithUsername:normSip - service:normSip]; + service:@"SIP"]; CNLabeledValue *sipAddress = [CNLabeledValue labeledValueWithLabel:NULL value:cNSipMsgAddr]; NSMutableArray *> @@ -244,13 +247,13 @@ CNInstantMessageAddress *cNSipMsgAddr; if ([[FastAddressBook normalizeSipURI:normSip] containsString:@"@"]) cNSipMsgAddr = [[CNInstantMessageAddress alloc] - initWithUsername:sip - service:[[FastAddressBook normalizeSipURI:normSip] - componentsSeparatedByString:@"@"][1]]; + initWithUsername:sip service:@"SIP"]; + //service:[[FastAddressBook normalizeSipURI:normSip] + // componentsSeparatedByString:@"@"][1]]; else cNSipMsgAddr = - [[CNInstantMessageAddress alloc] initWithUsername:normSip - service:normSip]; + [[CNInstantMessageAddress alloc] initWithUsername:normSip service:@"SIP"]; + //service:normSip]; CNLabeledValue *sipAddress = [CNLabeledValue labeledValueWithLabel:NULL value:cNSipMsgAddr]; NSMutableArray *> @@ -351,12 +354,12 @@ cNSipMsgAddr = [[CNInstantMessageAddress alloc] initWithUsername:[normSip componentsSeparatedByString:@"@"][0] - service:[normSip - componentsSeparatedByString:@"@"][1]]; + service:@"SIP"]; + //service:[normSip componentsSeparatedByString:@"@"][1]]; else cNSipMsgAddr = [[CNInstantMessageAddress alloc] initWithUsername:normSip - service:normSip]; + service:@"SIP"]; CNLabeledValue *sipAddress = [CNLabeledValue labeledValueWithLabel:NULL value:cNSipMsgAddr]; diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index 97657c64e..a7685e5bc 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -75,12 +75,10 @@ - (void)addEntry:(UITableView *)tableview section:(NSInteger)section animated:(BOOL)animated value:(NSString *)value { bool added = FALSE; if (section == ContactSections_Number) { - if ([_contact.phones count] == - [_contact.person.phoneNumbers count]) + if ([_contact.phones count] == [_contact.person.phoneNumbers count]) added = [_contact addPhoneNumber:value]; } else if (section == ContactSections_Sip) { - if ([_contact.sipAddresses count] == - [_contact.person.instantMessageAddresses count]) + if ([_contact.sipAddresses count] == [self countSipAddressFromCNContact:_contact.person]) //[_contact.person.instantMessageAddresses count]) added = [_contact addSipAddress:value]; } else if (section == ContactSections_Email) { if ([_contact.emails count] == @@ -100,6 +98,21 @@ } } +-(NSInteger)countSipAddressFromCNContact:(CNContact*) mCNContact{ + NSInteger count = 0; + if (mCNContact.instantMessageAddresses != NULL) { + for (CNLabeledValue *sipAddr in mCNContact.instantMessageAddresses) { + NSString *username = sipAddr.value.username; + NSString *service = sipAddr.value.service; + if (username && ([service isEqualToString:LinphoneManager.instance.contactSipField] || ([service isEqualToString:@"INSTANT_MESSAGING_NAME"] && [FastAddressBook isSipURI:username]))){ + count ++; + } + } + } + return count; +} + + - (void)setContact:(Contact *)acontact { // if (acontact == _contact) // return; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a6f68c166..d93bbffe3 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1855,7 +1855,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach device = [device stringByReplacingOccurrencesOfString:@" " withString:@"."]; linphone_core_set_user_agent(theLinphoneCore, device.UTF8String, LINPHONE_IOS_VERSION); - _contactSipField = [self lpConfigStringForKey:@"contact_im_type_value" withDefault:@"SIP"]; + _contactSipField = [self lpConfigStringForKey:@"contact_im_type_value" inSection:@"sip" withDefault:@"SIP"]; if (_fastAddressBook == nil) { _fastAddressBook = [[FastAddressBook alloc] init];