From 733405e0c684340a56eb863f8dd77d79af19215e Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Mon, 22 Sep 2014 14:31:10 +0200 Subject: [PATCH] Fix new notification handling behavior for messages --- Classes/LinphoneAppDelegate.m | 10 ++++++---- Classes/LinphoneManager.m | 6 +++--- Classes/PhoneMainView.h | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 45da851d0..835b88311 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -427,25 +427,27 @@ } - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler { + LinphoneCore* lc = [LinphoneManager getLc]; [LinphoneLogger log:LinphoneLoggerLog format:@"%@", NSStringFromSelector(_cmd)]; if( [notification.category isEqualToString:@"incoming_call"]) { if( [identifier isEqualToString:@"answer"] ){ // use the standard handler [self application:application didReceiveLocalNotification:notification]; } else if( [identifier isEqualToString:@"decline"] ){ - LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); - if( call ) linphone_core_decline_call([LinphoneManager getLc], call, LinphoneReasonDeclined); + LinphoneCall* call = linphone_core_get_current_call(lc); + if( call ) linphone_core_decline_call(lc, call, LinphoneReasonDeclined); } } else if( [notification.category isEqualToString:@"incoming_msg"] ){ if( [identifier isEqualToString:@"reply"] ){ // use the standard handler [self application:application didReceiveLocalNotification:notification]; } else if( [identifier isEqualToString:@"mark_read"] ){ - LinphoneChatRoom* room = [[notification.userInfo objectForKey:@"room"] pointerValue]; + NSString* from = [notification.userInfo objectForKey:@"from"]; + LinphoneChatRoom* room = linphone_core_get_or_create_chat_room(lc, [from UTF8String]); if( room ){ linphone_chat_room_mark_as_read(room); + [[PhoneMainView instance] updateApplicationBadgeNumber]; } - } } completionHandler(); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 26b20632c..ee9d64838 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -871,7 +871,7 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { - const LinphoneAddress* remoteAddress = linphone_chat_message_get_from(msg); + const LinphoneAddress* remoteAddress = linphone_chat_message_get_from_address(msg); char* c_address = linphone_address_as_string_uri_only(remoteAddress); NSString* address = [NSString stringWithUTF8String:c_address]; NSString* from_address = [address copy]; @@ -894,11 +894,11 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo UILocalNotification* notif = [[[UILocalNotification alloc] init] autorelease]; if (notif) { notif.repeatInterval = 0; - notif.category = @"@incoming_msg"; + notif.category = @"incoming_msg"; notif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"IM_MSG",nil), address]; notif.alertAction = NSLocalizedString(@"Show", nil); notif.soundName = @"msg.caf"; - notif.userInfo = @{@"from":from_address, @"room":[NSValue valueWithPointer:room] }; + notif.userInfo = @{@"from":from_address}; [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 0c1f5edb9..0586e1619 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -73,6 +73,7 @@ - (void)addInhibitedEvent:(id)event; - (BOOL)removeInhibitedEvent:(id)event; +- (void)updateApplicationBadgeNumber; + (PhoneMainView*) instance; @end