Fix local notification issue when in chat room

This commit is contained in:
Yann Diorcet 2012-10-16 12:16:27 +02:00
parent 56c15e4a9e
commit 01222d7de4
3 changed files with 41 additions and 34 deletions

View file

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

View file

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

View file

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