presence: handle dynamically notifies

This commit is contained in:
Gautier Pelloux-Prayer 2016-09-05 15:10:46 +02:00
parent 280bed6aff
commit cb158dfb04
6 changed files with 41 additions and 14 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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,

View file

@ -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];

View file

@ -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);
}

@ -1 +1 @@
Subproject commit dce0f4d495d4ab239d39eb42b5bd2b3ef609815e
Subproject commit 9313618cbd90cee6b37b3ead80a1a98e485d49f3