diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 87d4d5779..c1b125408 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -531,7 +531,7 @@ static UICompositeViewDescription *compositeDescription = nil; BOOL basic = [ChatConversationView isBasicChatRoom:_chatRoom]; if (message && message.length > 0) { if (!basic) - linphone_chat_message_add_utf8_text_content(msg, message.UTF8String); + linphone_chat_message_add_utf8_text_content(msg, message.UTF8String); } if (externalUrl) { diff --git a/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib index 8cae658dc..f714fbc23 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib @@ -1,9 +1,9 @@ - + - + diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 60bdea98b..cf6c18807 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -277,22 +277,15 @@ if (!is_outgoing) { LinphoneChatMessageState state = linphone_chat_message_get_state(self.message); if (state != LinphoneChatMessageStateFileTransferDone && state != LinphoneChatMessageStateDisplayed) { - if (state == LinphoneChatMessageStateFileTransferInProgress) { - _cancelButton.hidden = _fileTransferProgress.hidden = NO; - _downloadButton.hidden = YES; - _playButton.hidden = YES; - _fileName.hidden = _fileView.hidden = _fileButton.hidden =YES; - } else { - _downloadButton.hidden = YES; - UIChatContentView * contentView = [[UIChatContentView alloc] init]; - [contentView setContent:fileContent message:self.message]; - contentView.position = 0; - [_contentViews addObject:contentView]; - _cancelButton.hidden = _fileTransferProgress.hidden = YES; - _playButton.hidden = YES; - _fileName.hidden = _fileView.hidden = _fileButton.hidden = YES; - [self layoutSubviews]; - } + _downloadButton.hidden = YES; + UIChatContentView * contentView = [[UIChatContentView alloc] init]; + [contentView setContent:fileContent message:self.message]; + contentView.position = 0; + [_contentViews addObject:contentView]; + _cancelButton.hidden = _fileTransferProgress.hidden = YES; + _playButton.hidden = YES; + _fileName.hidden = _fileView.hidden = _fileButton.hidden = YES; + [self layoutSubviews]; return; } } diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 14d95e2da..4ee9ae625 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -314,6 +314,9 @@ #pragma mark - State changed handling static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState state) { LOGI(@"State for message [%p] changed to %s", msg, linphone_chat_message_state_to_string(state)); + if (state == LinphoneChatMessageStateFileTransferInProgress) + return; + if (!linphone_chat_message_is_outgoing(msg) || (state != LinphoneChatMessageStateFileTransferDone && state != LinphoneChatMessageStateFileTransferInProgress)) { LinphoneEventLog *event = (LinphoneEventLog *)linphone_chat_message_cbs_get_user_data(linphone_chat_message_get_callbacks(msg)); ChatConversationView *view = VIEW(ChatConversationView); @@ -373,10 +376,8 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; CGSize cached = [SwiftUtil getCachedMessageHeightWithCmessage:chat]; if (cached.height != 0) { - LOGI(@"ViewHeightForMessage - found cached value %f",cached.height); return cached; } - LOGI(@"ViewHeightForMessage - computing value"); CGSize size = [self ViewHeightForMessageText:chat withWidth:width textForImdn:nil]; size.height += linphone_chat_message_is_forward(chat) || linphone_chat_message_is_reply(chat) ? REPLY_OR_FORWARD_TAG_HEIGHT : 0; diff --git a/Classes/LinphoneUI/UIChatContentView.h b/Classes/LinphoneUI/UIChatContentView.h index 9851ca3a9..b5d530de1 100644 --- a/Classes/LinphoneUI/UIChatContentView.h +++ b/Classes/LinphoneUI/UIChatContentView.h @@ -28,6 +28,8 @@ @property(readonly, nonatomic) LinphoneChatMessage *message; @property(nonatomic) UIButton *downloadButton; @property(nonatomic) NSString *filePath; +@property(nonatomic) UIProgressView *progress; + - (void)setContent:(LinphoneContent *)content message:(LinphoneChatMessage *)message; diff --git a/Classes/LinphoneUI/UIChatContentView.m b/Classes/LinphoneUI/UIChatContentView.m index f43467ccc..31c35da80 100644 --- a/Classes/LinphoneUI/UIChatContentView.m +++ b/Classes/LinphoneUI/UIChatContentView.m @@ -24,7 +24,13 @@ @implementation UIChatContentView +static NSMutableDictionary *instances; + - (void)setContent:(LinphoneContent *)content message:(LinphoneChatMessage *)message { + + if (!instances) + instances = [[NSMutableDictionary alloc] init]; + _content = content; _message = message; self.userInteractionEnabled = YES; @@ -41,11 +47,14 @@ UIFont *boldFont = [UIFont systemFontOfSize:12]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.alignment = NSTextAlignmentCenter; - NSMutableAttributedString *boldText = [[NSMutableAttributedString alloc] initWithString:@"Download" attributes:@{ NSFontAttributeName : boldFont, NSParagraphStyleAttributeName:paragraphStyle,NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle) }]; [_downloadButton setAttributedTitle:boldText forState:UIControlStateNormal]; _downloadButton.frame = CGRectMake(0, 90, 120, 30); [self addSubview:_downloadButton]; + _progress = [[UIProgressView alloc] initWithFrame:CGRectMake(5, 75, 110, 30)]; + _progress.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A.png"]]; + _progress.hidden = true; + [self addSubview:_progress]; } else { if (_filePath == NULL) { NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)]; @@ -70,8 +79,27 @@ -(IBAction)onDownloadClick:(id)sender { _downloadButton.enabled = NO; linphone_content_set_file_path(_content, [[LinphoneManager imagesDirectory] stringByAppendingPathComponent:[NSString stringWithUTF8String:linphone_content_get_name(_content)]].UTF8String); + linphone_chat_message_cbs_set_file_transfer_progress_indication(linphone_chat_message_get_callbacks(_message), file_transfer_progress_indication_recv); + _progress.hidden = false; + _downloadButton.enabled = false; + [instances setValue:self forKey:[NSString stringWithUTF8String:linphone_content_get_name(_content)]]; + linphone_chat_message_download_content(_message, _content); } +static void file_transfer_progress_indication_recv(LinphoneChatMessage *message, LinphoneContent* content, size_t offset, size_t total) { + CGFloat p = offset * 1.f / total; + dispatch_async(dispatch_get_main_queue(), ^{ + UIChatContentView *thiz = [instances objectForKey:[NSString stringWithUTF8String:linphone_content_get_name(content)]]; + if (offset == total) { + thiz.progress.hidden = true; + } else { + thiz.progress.hidden = false; + thiz.progress.progress = p; + LOGD(@"Transfer of %s (%d bytes): already %ld recv progress = %f", linphone_content_get_name(content), total, p); + } + }); +} + @end diff --git a/Classes/SwiftUtil.swift b/Classes/SwiftUtil.swift index 1a0c4e91e..fd712318f 100644 --- a/Classes/SwiftUtil.swift +++ b/Classes/SwiftUtil.swift @@ -105,10 +105,16 @@ import linphonesw cacheMessageSize[message.messageId] = size } + @objc static func removeCachedMessageHeight(cmessage:OpaquePointer) { + let message = ChatMessage.getSwiftObject(cObject: cmessage) + cacheMessageSize.removeValue(forKey: message.messageId) + } + @objc static func messageHeightCanBeCached(cmessage:OpaquePointer) -> Bool { let message = ChatMessage.getSwiftObject(cObject: cmessage) - return (message.isOutgoing && [.Delivered, .DeliveredToUser, .Displayed].contains(message.state)) || (!message.isOutgoing && ![.InProgress, .FileTransferInProgress, .FileTransferError].contains(message.state)) + return (message.isOutgoing && [.Delivered, .DeliveredToUser, .Displayed].contains(message.state)) || (!message.isOutgoing && [.Displayed].contains(message.state)) } + }