diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.h b/Classes/LinphoneUI/UIChatBubblePhotoCell.h index f0788fdc0..31d1b9a3c 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.h +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.h @@ -32,6 +32,7 @@ @property(weak, nonatomic) IBOutlet UIProgressView *fileTransferProgress; @property(weak, nonatomic) IBOutlet UIButton *cancelButton; @property(weak, nonatomic) IBOutlet UIView *imageSubView; +@property(weak, nonatomic) IBOutlet UIView *totalView; - (void)setChatMessage:(LinphoneChatMessage *)message; - (void)connectToFileDelegate:(FileTransferDelegate *)ftd; diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 09057cc84..e7b140cdd 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -57,11 +57,9 @@ return; } - [self disconnectFromFileDelegate]; _messageImageView.image = nil; _fileTransferProgress.progress = 0; - - [super setChatMessage:amessage]; + [self disconnectFromFileDelegate]; if (amessage) { const LinphoneContent *c = linphone_chat_message_get_file_transfer_information(amessage); @@ -70,15 +68,18 @@ for (FileTransferDelegate *aftd in [[LinphoneManager instance] fileTransferDelegates]) { if (linphone_chat_message_get_file_transfer_information(aftd.message) && strcmp(name, linphone_content_get_name( - linphone_chat_message_get_file_transfer_information(amessage))) == 0) { - LOGI(@"Chat message [%p] with file transfer delegate [%p], connecting to it!", amessage, aftd); - [self connectToFileDelegate:aftd]; + linphone_chat_message_get_file_transfer_information(aftd.message))) == 0) { + if (ftd != aftd) { + LOGI(@"Chat message [%p] with file transfer delegate [%p], connecting to it!", amessage, aftd); + [self connectToFileDelegate:aftd]; + } break; } } } } - [self update]; + + [super setChatMessage:amessage]; } - (void)update { @@ -88,19 +89,11 @@ } [super update]; - LinphoneChatMessageState state = linphone_chat_message_get_state(self.message); - if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) { - if (ftd) { - [ftd stopAndDestroy]; - ftd = nil; - } - } - const char *url = linphone_chat_message_get_external_body_url(self.message); BOOL is_external = (url && (strstr(url, "http") == url)) || linphone_chat_message_get_file_transfer_information(self.message); NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:self.message]; - + BOOL fullScreenImage = NO; assert(is_external || localImage); if (localImage) { // we did not load the image yet, so start doing so @@ -134,18 +127,23 @@ _downloadButton.hidden = YES; } else { _cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES; + fullScreenImage = YES; } // we must download the image: either it has already started (show cancel button) or not yet (show download // button) } else { - // CGRect newFrame = _imageSubView.frame; - // newFrame.origin.y = _messageImageView.frame.origin.y + ((ftd.message == nil) ? 0 : - //_messageImageView.frame.size.height); - // _imageSubView.frame = newFrame; _messageImageView.hidden = _cancelButton.hidden = (ftd.message == nil); _downloadButton.hidden = !_cancelButton.hidden; _fileTransferProgress.hidden = NO; } + + // resize image so that it take the full bubble space available + CGRect newFrame = _totalView.frame; + newFrame.origin.x = newFrame.origin.y = 0; + if (!fullScreenImage) { + newFrame.size.height -= _imageSubView.frame.size.height; + } + _messageImageView.frame = newFrame; } - (IBAction)onDownloadClick:(id)event { @@ -188,7 +186,6 @@ - (void)connectToFileDelegate:(FileTransferDelegate *)aftd { ftd = aftd; - // assert(ftd.message == self.message); _fileTransferProgress.progress = 0; [[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -219,7 +216,8 @@ _fileTransferProgress.progress = MAX(_fileTransferProgress.progress, progress); _fileTransferProgress.hidden = _cancelButton.hidden = (_fileTransferProgress.progress == 1.f); } else { - [self update]; + ChatConversationView *view = VIEW(ChatConversationView); + [view.tableController updateChatEntry:self.message]; } } - (void)onFileTransferRecvUpdate:(NSNotification *)notif { @@ -229,7 +227,8 @@ _fileTransferProgress.progress = MAX(_fileTransferProgress.progress, progress); _fileTransferProgress.hidden = _cancelButton.hidden = (_fileTransferProgress.progress == 1.f); } else { - [self update]; + ChatConversationView *view = VIEW(ChatConversationView); + [view.tableController updateChatEntry:self.message]; } } diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.xib b/Classes/LinphoneUI/UIChatBubblePhotoCell.xib index 6882fb8da..7b6cf81f5 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.xib +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.xib @@ -18,6 +18,7 @@ + @@ -52,57 +53,64 @@ - - - - - - - - - - - - + + - - + + + + + + + + + + - + + - - - - - - - - - + @@ -128,12 +136,12 @@ - + - + diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index b2bc99daa..31589cdbf 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -202,10 +202,7 @@ } #pragma mark - State changed handling static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState state) { - UIChatBubbleTextCell *thiz = (__bridge UIChatBubbleTextCell *)linphone_chat_message_get_user_data(msg); LOGI(@"State for message [%p] changed to %s", msg, linphone_chat_message_state_to_string(state)); - [thiz update]; - ChatConversationView *view = VIEW(ChatConversationView); [view.tableController updateChatEntry:msg]; } diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index e4d8f1512..a46bffeab 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -75,12 +75,14 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con postNotificationName:kLinphoneFileTransferRecvUpdate object:thiz userInfo:@{ - @"state" : @(linphone_chat_message_get_state(message)), + @"state" : @(LinphoneChatMessageStateDelivered), // we dont want to + // trigger + // FileTransferDone here @"image" : image, - @"progress" : - @([thiz.data length] * 1.f / linphone_content_get_size(content)), + @"progress" : @(1.f), }]; + [thiz stopAndDestroy]; CFRelease((__bridge CFTypeRef)thiz); }]; } else {