diff --git a/Classes/Contact.m b/Classes/Contact.m index 6938b0989..cd33657f3 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -57,8 +57,9 @@ linphone_friend_add_phone_number(_friend, phone.UTF8String); #endif } - if (_friend) + if (_friend) { linphone_core_add_friend(LC, _friend); + } } linphone_friend_ref(_friend); } else if (_friend) { diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index c7e7c38c6..6ffe88b29 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -50,7 +50,7 @@ extern NSString *const kLinphoneBluetoothAvailabilityUpdate; extern NSString *const kLinphoneConfiguringStateUpdate; extern NSString *const kLinphoneGlobalStateUpdate; extern NSString *const kLinphoneNotifyReceived; -extern NSString *const kLinphoneNotifyPresenceReceived; +extern NSString *const kLinphoneNotifyPresenceReceivedForUriOrTel; extern NSString *const kLinphoneCallEncryptionChanged; extern NSString *const kLinphoneFileTransferSendUpdate; extern NSString *const kLinphoneFileTransferRecvUpdate; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index f42d2225d..ec4b186e0 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -66,7 +66,7 @@ NSString *const kLinphoneBluetoothAvailabilityUpdate = @"LinphoneBluetoothAvaila NSString *const kLinphoneConfiguringStateUpdate = @"LinphoneConfiguringStateUpdate"; NSString *const kLinphoneGlobalStateUpdate = @"LinphoneGlobalStateUpdate"; NSString *const kLinphoneNotifyReceived = @"LinphoneNotifyReceived"; -NSString *const kLinphoneNotifyPresenceReceived = @"LinphoneNotifyPresenceReceived"; +NSString *const kLinphoneNotifyPresenceReceivedForUriOrTel = @"LinphoneNotifyPresenceReceivedForUriOrTel"; NSString *const kLinphoneCallEncryptionChanged = @"LinphoneCallEncryptionChanged"; NSString *const kLinphoneFileTransferSendUpdate = @"LinphoneFileTransferSendUpdate"; NSString *const kLinphoneFileTransferRecvUpdate = @"LinphoneFileTransferRecvUpdate"; @@ -1066,15 +1066,27 @@ static void linphone_iphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev content:body]; } -- (void)onNotifyPresenceReceived:(LinphoneCore *)lc friend:(LinphoneFriend *)lf { +- (void)onNotifyPresenceReceivedForUriOrTel:(LinphoneCore *)lc + friend:(LinphoneFriend *)lf + uri:(const char *)uri + presenceModel:(const LinphonePresenceModel *)model { // Post event NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSValue valueWithPointer:lf] forKey:@"friend"]; - [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneNotifyPresenceReceived object:self userInfo:dict]; + [dict setObject:[NSValue valueWithPointer:uri] forKey:@"uri"]; + [dict setObject:[NSValue valueWithPointer:model] forKey:@"presence_model"]; + [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneNotifyPresenceReceivedForUriOrTel + object:self + userInfo:dict]; } -static void linphone_iphone_notify_presence_received(LinphoneCore *lc, LinphoneFriend *lf) { - [(__bridge LinphoneManager *)linphone_core_get_user_data(lc) onNotifyPresenceReceived:lc friend:lf]; +static void linphone_iphone_notify_presence_received_for_uri_or_tel(LinphoneCore *lc, LinphoneFriend *lf, + const char *uri_or_tel, + const LinphonePresenceModel *presence_model) { + [(__bridge LinphoneManager *)linphone_core_get_user_data(lc) onNotifyPresenceReceivedForUriOrTel:lc + friend:lf + uri:uri_or_tel + presenceModel:presence_model]; } static void linphone_iphone_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t on, @@ -1362,11 +1374,9 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach static LinphoneCoreVTable linphonec_vtable = { .call_state_changed = (LinphoneCoreCallStateChangedCb)linphone_iphone_call_state, .registration_state_changed = linphone_iphone_registration_state, - .notify_presence_received = linphone_iphone_notify_presence_received, - .new_subscription_requested = NULL, + .notify_presence_received_for_uri_or_tel = linphone_iphone_notify_presence_received_for_uri_or_tel, .auth_info_requested = linphone_iphone_popup_password_request, .message_received = linphone_iphone_message_received, - .dtmf_received = NULL, .transfer_state_changed = linphone_iphone_transfer_state_changed, .is_composing_received = linphone_iphone_is_composing_received, .configuring_status = linphone_iphone_configuring_status_changed, diff --git a/Classes/LinphoneUI/UIAvatarPresence.m b/Classes/LinphoneUI/UIAvatarPresence.m index 712df342e..0c082002e 100644 --- a/Classes/LinphoneUI/UIAvatarPresence.m +++ b/Classes/LinphoneUI/UIAvatarPresence.m @@ -13,7 +13,7 @@ INIT_WITH_COMMON_CF { [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onPresenceChanged:) - name:kLinphoneNotifyPresenceReceived + name:kLinphoneNotifyPresenceReceivedForUriOrTel object:nil]; if (!_presenceImage) { @@ -46,8 +46,7 @@ INIT_WITH_COMMON_CF { - (void)onPresenceChanged:(NSNotification *)k { LinphoneFriend *f = [[k.userInfo valueForKey:@"friend"] pointerValue]; // only consider event if it's about us - if (!_friend || - !linphone_address_weak_equal(linphone_friend_get_address(f), linphone_friend_get_address(_friend))) { + if (!_friend || f != _friend) { return; } [self updatePresenceImage]; diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index d49005bca..78a49ad27 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -43,14 +43,31 @@ frame.origin.x -= frame.size.width / 2; _linphoneImage.frame = frame; } + + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(onPresenceChanged:) + name:kLinphoneNotifyPresenceReceivedForUriOrTel + object:nil]; } return self; } +#pragma mark - Notif + +- (void)onPresenceChanged:(NSNotification *)k { + LinphoneFriend *f = [[k.userInfo valueForKey:@"friend"] pointerValue]; + // only consider event if it's about us + if (!_contact.friend || f != _contact.friend) { + return; + } + [self setContact:_contact]; +} + #pragma mark - Property Functions - (void)setContact:(Contact *)acontact { _contact = acontact; + [ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact]; _linphoneImage.hidden = ! (_contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(_contact.friend)) == LinphonePresenceBasicStatusOpen); } diff --git a/submodules/linphone b/submodules/linphone index dce0f4d49..9313618cb 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit dce0f4d495d4ab239d39eb42b5bd2b3ef609815e +Subproject commit 9313618cbd90cee6b37b3ead80a1a98e485d49f3