From 2e8de3d321f7140b99fe97acd74182da6f5e6bfc Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 16 Nov 2016 11:28:07 +0100 Subject: [PATCH] Better presence detection --- Classes/AssistantLinkView.m | 2 +- Classes/Contact.m | 16 ++++----- Classes/ContactDetailsView.m | 8 +++++ Classes/LinphoneUI/UIContactCell.m | 1 + Classes/LinphoneUI/UIContactDetailsCell.h | 1 + Classes/LinphoneUI/UIContactDetailsCell.m | 40 +++++++++++++++++++++-- Classes/Utils/Utils.m | 2 +- submodules/linphone | 2 +- 8 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Classes/AssistantLinkView.m b/Classes/AssistantLinkView.m index f4c6abc65..adb5a30f1 100644 --- a/Classes/AssistantLinkView.m +++ b/Classes/AssistantLinkView.m @@ -162,9 +162,9 @@ void assistant_activate_phone_number_link(LinphoneAccountCreator *creator, Linph linphone_proxy_config_set_dial_prefix(cfg, prefix[0] == '+' ? &prefix[1] : prefix); linphone_proxy_config_done(cfg); } - [LinphoneManager.instance.fastAddressBook reload]; [PhoneMainView.instance popToView:DialerView.compositeViewDescription]; [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneAddressBookUpdate object:NULL]; + [LinphoneManager.instance.fastAddressBook reload]; } else { [thiz showErrorPopup:resp]; } diff --git a/Classes/Contact.m b/Classes/Contact.m index 57b07ca29..0445d8eb7 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -258,8 +258,8 @@ if (_person) { ret = [self addInProperty:kABPersonPhoneProperty value:(__bridge CFTypeRef)(phone)]; } else { - char *cphone = - linphone_proxy_config_normalize_phone_number(NULL, phone.UTF8String) ?: ms_strdup(phone.UTF8String); + char *cphone = ms_strdup(phone.UTF8String); + // linphone_proxy_config_normalize_phone_number(NULL, phone.UTF8String) ?: ms_strdup(phone.UTF8String); if (cphone) { linphone_friend_add_phone_number(_friend, cphone); phone = [NSString stringWithUTF8String:cphone]; @@ -354,12 +354,12 @@ NSInteger index = ABMultiValueGetIndexForIdentifier(map, identifier); if (index != -1) { NSString *valueRef = CFBridgingRelease(ABMultiValueCopyValueAtIndex(map, index)); - char *normalizedPhone = linphone_proxy_config_normalize_phone_number( - linphone_core_get_default_proxy_config(LC), valueRef.UTF8String); - if (normalizedPhone) { - valueRef = [NSString stringWithUTF8String:normalizedPhone]; - ms_free(normalizedPhone); - } + // char *normalizedPhone = linphone_proxy_config_normalize_phone_number( + // linphone_core_get_default_proxy_config(LC), valueRef.UTF8String); + // if (normalizedPhone) { + // valueRef = [NSString stringWithUTF8String:normalizedPhone]; + // ms_free(normalizedPhone); + //} [_phoneNumbers addObject:valueRef]; } diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 1b7f3ae39..28dccac48 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -186,6 +186,14 @@ _editButton.hidden = TRUE; _deleteButton.hidden = TRUE; } + + // Update presence for contact + for (NSInteger j = 0; j < [self.tableController.tableView numberOfSections]; ++j) { + for (NSInteger i = 0; i < [self.tableController.tableView numberOfRowsInSection:j]; ++i) { + [(UIContactDetailsCell *)[self.tableController.tableView + cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]] shouldHideLinphoneImageOfAddress]; + } + } } - (void)deviceOrientationDidChange:(NSNotification*)notif { diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index 5235db8af..0b74e267b 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -73,6 +73,7 @@ - (void)setContact:(Contact *)acontact { _contact = acontact; + _linphoneImage.hidden = TRUE; if(_contact) { [ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact]; _linphoneImage.hidden = diff --git a/Classes/LinphoneUI/UIContactDetailsCell.h b/Classes/LinphoneUI/UIContactDetailsCell.h index 03969d632..c068b45ff 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.h +++ b/Classes/LinphoneUI/UIContactDetailsCell.h @@ -39,6 +39,7 @@ - (id)initWithIdentifier:(NSString *)identifier; - (void)setAddress:(NSString *)address; - (void)hideDeleteButton:(BOOL)hidden; +- (void)shouldHideLinphoneImageOfAddress; - (IBAction)onCallClick:(id)sender; - (IBAction)onChatClick:(id)sender; diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index 7a43fd3e4..06ae8524b 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -44,11 +44,12 @@ - (void)setAddress:(NSString *)address { _addressLabel.text = _editTextfield.text = address; + char *normAddr = (char *)_addressLabel.text.UTF8String; if(_addressLabel.text && linphone_proxy_config_is_phone_number(linphone_core_get_default_proxy_config(LC), _addressLabel.text.UTF8String)) { - char * normAddr = linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), _addressLabel.text.UTF8String); - _addressLabel.text = [NSString stringWithUTF8String:normAddr]; + normAddr = linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), + _addressLabel.text.UTF8String); } - LinphoneAddress *addr = linphone_core_interpret_url(LC, _addressLabel.text.UTF8String); + LinphoneAddress *addr = linphone_core_interpret_url(LC, normAddr); _chatButton.enabled = _callButton.enabled = (addr != NULL); _chatButton.accessibilityLabel = @@ -56,6 +57,39 @@ _callButton.accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"Call %@", nil), _addressLabel.text]; // Test presence Contact* contact = [FastAddressBook getContactWithAddress:(addr)]; + + _linphoneImage.hidden = TRUE; + if (contact) { + self.linphoneImage.hidden = + !((contact.friend && + linphone_presence_model_get_basic_status(linphone_friend_get_presence_model_for_uri_or_tel( + contact.friend, _addressLabel.text.UTF8String)) == LinphonePresenceBasicStatusOpen) || + (!linphone_proxy_config_is_phone_number(linphone_core_get_default_proxy_config(LC), + _addressLabel.text.UTF8String) && + [FastAddressBook isSipURIValid:_addressLabel.text])); + } + + if (addr) { + linphone_address_destroy(addr); + } +} + +- (void)shouldHideLinphoneImageOfAddress { + if (!_addressLabel.text) { + return; + } + + char *normAddr = (char *)_addressLabel.text.UTF8String; + if (linphone_proxy_config_is_phone_number(linphone_core_get_default_proxy_config(LC), + _addressLabel.text.UTF8String)) { + normAddr = linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), + _addressLabel.text.UTF8String); + } + LinphoneAddress *addr = linphone_core_interpret_url(LC, normAddr); + + // Test presence + Contact *contact = [FastAddressBook getContactWithAddress:(addr)]; + if (contact) { self.linphoneImage.hidden = ! ((contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model_for_uri_or_tel(contact.friend, _addressLabel.text.UTF8String)) == LinphonePresenceBasicStatusOpen) || (!linphone_proxy_config_is_phone_number(linphone_core_get_default_proxy_config(LC), _addressLabel.text.UTF8String) && [FastAddressBook isSipURIValid:_addressLabel.text])); } diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 6404273b4..088269f8a 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -471,7 +471,7 @@ if (c && c.friend) { LinphoneFriend *f = c.friend; const LinphonePresenceModel *m = - f ? linphone_friend_get_presence_model_for_uri_or_tel(f, normvalue) : NULL; + f ? linphone_friend_get_presence_model_for_uri_or_tel(f, value.UTF8String) : NULL; const char *contact = m ? linphone_presence_model_get_contact(m) : NULL; if (contact) { LinphoneAddress *contact_addr = linphone_address_new(contact); diff --git a/submodules/linphone b/submodules/linphone index a14a8f9f2..619f7bffd 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit a14a8f9f2119fae927c1c36d64849ba64431759e +Subproject commit 619f7bffd40d120c6e60fc00fcaa924baa78530b