diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 4fdf2b3ba..7f4d4d360 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -165,6 +165,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100; NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message]; BOOL fullScreenImage = NO; assert(is_external || localImage || localVideo || localFile); + NSString *type = [NSString stringWithUTF8String:linphone_chat_message_get_content_type(self.message)]; if (!(localImage || localVideo || localFile)) { _playButton.hidden = YES; @@ -193,13 +194,13 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100; } } else if (localFile) { - if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) { - NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; - UIImage *image = [[UIImage alloc] initWithData:data]; + if ([type isEqualToString:@"video/"]) { + UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; [self loadImageAsset:nil image:image]; _imageGestureRecognizer.enabled = YES; - } else if ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) { - UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; + } else if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) { + NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; + UIImage *image = [[UIImage alloc] initWithData:data]; [self loadImageAsset:nil image:image]; _imageGestureRecognizer.enabled = YES; } else { @@ -219,7 +220,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100; } else { _cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES; fullScreenImage = YES; - _playButton.hidden = localVideo ? NO : ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) ? NO : YES; + _playButton.hidden = ![type isEqualToString:@"video/"]; _fileName.hidden = _fileView.hidden = _fileButton.hidden = localFile ? NO : YES; // Should fix cell not resizing after doanloading image. [self layoutSubviews]; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index e772cd12b..4290bbc70 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -467,11 +467,12 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100; if(localFile) { UIImage *image = nil; - if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) { + NSString *type = [NSString stringWithUTF8String:linphone_chat_message_get_content_type(chat)]; + if ([type isEqualToString:@"video/"]) { + image = [self getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; + } else if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"] || [localFile hasSuffix:@"jpg"] || [localFile hasSuffix:@"png"]) { NSData *data = [NSData dataWithContentsOfURL:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; image = [[UIImage alloc] initWithData:data]; - } else if ([localFile hasSuffix:@"MOV"] || [localFile hasSuffix:@"mov"]) { - image = [self getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]]; } if (image) { diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index 34475f575..715a89710 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -296,8 +296,16 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m - (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withName:(NSString *)name { // we will write local files into ours folder of icloud ChatConversationView *view = VIEW(ChatConversationView); - if ([view writeFileInICloud:data fileURL:[view getICloudFileUrl:name]]) - [self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil]; + NSURL *url = [view getICloudFileUrl:name]; + if ([view writeFileInICloud:data fileURL:url]) { + AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; + if ([[asset tracksWithMediaType:AVMediaTypeVideo] count] > 0) { + // if it's a video + [self uploadData:data forChatRoom:chatRoom type:@"video" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil]; + } else { + [self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil]; + } + } }