diff --git a/Classes/ChatRoomTableViewController.m b/Classes/ChatRoomTableViewController.m index 1555b96f2..1234b40a6 100644 --- a/Classes/ChatRoomTableViewController.m +++ b/Classes/ChatRoomTableViewController.m @@ -138,8 +138,6 @@ } self->remoteAddress = [aremoteAddress copy]; [self loadData]; - [ChatModel readConversation:remoteAddress]; - [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; } diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 552be969f..0915a4abe 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -143,7 +143,11 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [[NSNotificationCenter defaultCenter] addObserver:self + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationWillEnterForeground:) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; @@ -186,6 +190,10 @@ static UICompositeViewDescription *compositeDescription = nil; linphone_chat_room_destroy(chatRoom); chatRoom = NULL; } + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; @@ -226,6 +234,15 @@ static UICompositeViewDescription *compositeDescription = nil; [messageField setText:@""]; [self update]; [tableController setRemoteAddress: remoteAddress]; + [ChatModel readConversation:remoteAddress]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; +} + +- (void)applicationWillEnterForeground:(NSNotification*)notif { + if(remoteAddress != nil) { + [ChatModel readConversation:remoteAddress]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; + } } - (void)update { @@ -398,16 +415,16 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta } 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) { + if([[NSString stringWithUTF8String:fromStr] + caseInsensitiveCompare:remoteAddress] == NSOrderedSame) { + if (![[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] + || [UIApplication sharedApplication].applicationState == UIApplicationStateActive) { [chat setRead:[NSNumber numberWithInt:1]]; [chat update]; [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; - [tableController addChatEntry:chat]; - [tableController scrollToLastUnread:TRUE]; } + [tableController addChatEntry:chat]; + [tableController scrollToLastUnread:TRUE]; } ms_free(fromStr); }