From 01222d7de4d3f4da2ecd61025cc91aeba9774907 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Tue, 16 Oct 2012 12:16:27 +0200 Subject: [PATCH] Fix local notification issue when in chat room --- Classes/ChatRoomViewController.m | 16 +++++++++------- Classes/LinphoneManager.m | 31 ++++++++++++++++++++++++++++++- Classes/PhoneMainView.m | 28 ++-------------------------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 5559df4c2..552be969f 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -393,10 +393,14 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta LinphoneAddress *from = [[[notif userInfo] objectForKey:@"from"] pointerValue]; ChatModel *chat = [[notif userInfo] objectForKey:@"chat"]; - if(from != NULL && chat != NULL) { - char *fromStr = linphone_address_as_string_uri_only(from); - if(fromStr != NULL) { - if([[NSString stringWithUTF8String:fromStr] + if(from == NULL || chat == NULL) { + return; + } + char *fromStr = linphone_address_as_string_uri_only(from); + if(fromStr != NULL) { + if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] + || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { + if([[NSString stringWithUTF8String:fromStr] caseInsensitiveCompare:remoteAddress] == NSOrderedSame) { [chat setRead:[NSNumber numberWithInt:1]]; [chat update]; @@ -404,10 +408,8 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta [tableController addChatEntry:chat]; [tableController scrollToLastUnread:TRUE]; } - ms_free(fromStr); } - } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Invalid textReceivedEvent"]; + ms_free(fromStr); } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 492854388..93238e9b2 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -398,7 +398,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char char* lAddress = linphone_address_as_string_uri_only(addr); if(lAddress) { NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:[NSString stringWithUTF8String:lAddress]]; - ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; + ABRecordRef contact = [fastAddressBook getContact:normalizedSipAddress]; if(contact) { address = [FastAddressBook getContactDisplayName:contact]; useLinphoneAddress = false; @@ -533,6 +533,35 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo [chat create]; ms_free(fromStr); + + + if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] + && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + + NSString* address = [chat remoteContact]; + NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:address]; + ABRecordRef contact = [fastAddressBook getContact:normalizedSipAddress]; + if(contact) { + address = [FastAddressBook getContactDisplayName:contact]; + } + if(address == nil) { + address = @"Unknown"; + } + + // Create a new notification + UILocalNotification* notif = [[[UILocalNotification alloc] init] autorelease]; + if (notif) { + notif.repeatInterval = 0; + notif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"IM_MSG",nil), address]; + notif.alertAction = NSLocalizedString(@"Show", nil); + notif.soundName = @"msg.caf"; + notif.userInfo = [NSDictionary dictionaryWithObject:[chat remoteContact] forKey:@"chat"]; + + + [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; + } + } + // Post event NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSValue valueWithPointer:room], @"room", diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index ef7a8108f..ed00dd10f 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -621,32 +621,8 @@ static PhoneMainView* phoneMainViewInstance=nil; #pragma mark - ActionSheet Functions - (void)displayMessage:(ChatModel*)chat { - if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] - && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { - - NSString* address = [chat remoteContact]; - NSString *normalizedSipAddress = [FastAddressBook normalizeSipURI:address]; - ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:normalizedSipAddress]; - if(contact) { - address = [FastAddressBook getContactDisplayName:contact]; - } - if(address == nil) { - address = @"Unknown"; - } - - // Create a new notification - UILocalNotification* notif = [[[UILocalNotification alloc] init] autorelease]; - if (notif) { - notif.repeatInterval = 0; - notif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"IM_MSG",nil), address]; - notif.alertAction = NSLocalizedString(@"Show", nil); - notif.soundName = @"msg.caf"; - notif.userInfo = [NSDictionary dictionaryWithObject:[chat remoteContact] forKey:@"chat"]; - - - [[UIApplication sharedApplication] presentLocalNotificationNow:notif]; - } - } else { + if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] + || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { if(![self removeInhibitedEvent:kLinphoneTextReceived]) { AudioServicesPlaySystemSound([LinphoneManager instance].sounds.message); }