From b4bfdb2e7e9e807221e6e421806bfb216df6d938 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Thu, 6 Mar 2014 14:33:23 +0100 Subject: [PATCH] Better user compose detection --- Classes/ChatRoomViewController.m | 42 +++++++++++-------- .../Utils/GrowingTextView/HPGrowingTextView.m | 5 +-- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 4d83d98d0..f9f0fa29f 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -263,9 +263,17 @@ static UICompositeViewDescription *compositeDescription = nil; linphone_address_destroy(linphoneAddress); } [messageField setText:@""]; + + if( chatRoom != NULL ){ + linphone_chat_room_destroy(chatRoom); + chatRoom = NULL; + } + + chatRoom = linphone_core_get_or_create_chat_room([LinphoneManager getLc], [remoteAddress cStringUsingEncoding:[NSString defaultCStringEncoding]]); [self update]; [tableController setRemoteAddress: remoteAddress]; [ChatModel readConversation:remoteAddress]; + [self checkComposeForRoom:chatRoom]; [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self]; } @@ -434,6 +442,21 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta }); } +- (void)checkComposeForRoom:(LinphoneChatRoom*)room { + if( room && room == chatRoom ){ + BOOL composing = linphone_chat_room_is_remote_composing(room); + + if( composing ){ + [composeLabel setText:[NSString stringWithFormat:NSLocalizedString(@"%@ is composing...", @""), [addressLabel text]]]; + [composeLabel setAlpha:0]; + [composeLabel setHidden:FALSE]; + [UIView animateWithDuration:0.3 animations:^{ composeLabel.alpha = 1.0; }]; + } else { + [UIView animateWithDuration:0.3 animations:^{ composeLabel.alpha = 0.0; } completion:^(BOOL f) { [composeLabel setHidden:TRUE]; }]; + } + } +} + #pragma mark - Event Functions @@ -471,26 +494,9 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta - (void)textComposeEvent:(NSNotification*)notif { LinphoneChatRoom* room = [[[notif userInfo] objectForKey:@"room"] pointerValue]; - if( room ){ - const LinphoneAddress* remote_peer = linphone_chat_room_get_peer_address(room); - LinphoneAddress* current_peer= linphone_address_new([remoteAddress cStringUsingEncoding:[NSString defaultCStringEncoding]]); - - BOOL composing = linphone_chat_room_is_remote_composing(room); - - if( composing && linphone_address_weak_equal(remote_peer, current_peer) ){ - [composeLabel setText:[NSString stringWithFormat:NSLocalizedString(@"%@ is composing...", @""), [addressLabel text]]]; - [composeLabel setAlpha:0]; - [composeLabel setHidden:FALSE]; - [UIView animateWithDuration:0.3 animations:^{ composeLabel.alpha = 1.0; }]; - } else { - [UIView animateWithDuration:0.3 animations:^{ composeLabel.alpha = 0.0; } completion:^(BOOL f) { [composeLabel setHidden:TRUE]; }]; - } - - linphone_address_destroy(current_peer); - } + [self checkComposeForRoom:room]; } - #pragma mark - UITextFieldDelegate Functions - (BOOL)growingTextViewShouldBeginEditing:(HPGrowingTextView *)growingTextView { diff --git a/Classes/Utils/GrowingTextView/HPGrowingTextView.m b/Classes/Utils/GrowingTextView/HPGrowingTextView.m index 6eec61c24..f8c143f9c 100755 --- a/Classes/Utils/GrowingTextView/HPGrowingTextView.m +++ b/Classes/Utils/GrowingTextView/HPGrowingTextView.m @@ -233,6 +233,8 @@ - (void)textViewDidChange:(UITextView *)textView { [self refreshHeight]; + if( [delegate respondsToSelector:@selector(growingTextChanged:text:)]) + [delegate growingTextChanged:self text:[textView text]]; } - (void)refreshHeight @@ -627,9 +629,6 @@ //weird 1 pixel bug when clicking backspace when textView is empty if(![textView hasText] && [atext isEqualToString:@""]) return NO; - if( [delegate respondsToSelector:@selector(growingTextChanged:text:)]) - [delegate growingTextChanged:self text:atext]; - //Added by bretdabaker: sometimes we want to handle this ourselves if ([delegate respondsToSelector:@selector(growingTextView:shouldChangeTextInRange:replacementText:)]) return [delegate growingTextView:self shouldChangeTextInRange:range replacementText:atext];