diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index cce625051..61088163d 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -28,7 +28,7 @@ @protocol ChatConversationDelegate - (BOOL)startImageUpload:(UIImage *)image assetId:(NSString *)phAssetId withQuality:(float)quality; -- (BOOL)startFileUpload:(NSData *)data withUrl:(NSURL *)url; +- (BOOL)startFileUpload:(NSData *)data assetId:phAssetId; - (void)resendChat:(NSString *)message withExternalUrl:(NSString *)url; - (void)tableViewIsScrolling; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 09acbb8f8..7a81848c9 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -240,14 +240,9 @@ static UICompositeViewDescription *compositeDescription = nil; NSDictionary *dictText = [defaults valueForKey:@"text"]; if (dict) { //share photo - NSData *data = dict[@"nsData"]; - UIImage *image = [[UIImage alloc] initWithData:data]; - NSString *filename = dict[@"url"]; - if (filename) { - NSMutableDictionary * assetDict = [LinphoneUtils photoAssetsDictionary]; - [self chooseImageQuality:image assetId:[[assetDict objectForKey:filename] localIdentifier]]; - } else - [self chooseImageQuality:image assetId:@""]; + UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]]; + NSMutableDictionary * assetDict = [LinphoneUtils photoAssetsDictionary]; + [self chooseImageQuality:image assetId:[[assetDict objectForKey:dict[@"url"]] localIdentifier]]; [defaults removeObjectForKey:@"img"]; } else if (dictWeb) { //share url, if local file, then upload file @@ -256,19 +251,19 @@ static UICompositeViewDescription *compositeDescription = nil; if ([url hasPrefix:@"file"]) { //local file NSData *data = dictWeb[@"nsData"]; - [self confirmShare:data url:fileUrl text:nil]; + [self confirmShare:data url:fileUrl text:nil assetId:nil]; } else { - [self confirmShare:nil url:nil text:url]; + [self confirmShare:nil url:nil text:url assetId:nil]; } [defaults removeObjectForKey:@"web"]; }else if (dictFile) { //share file - NSData *data = dictFile[@"nsData"]; - [self confirmShare:data url:[NSURL fileURLWithPath:dictFile[@"url"]] text:nil]; + NSMutableDictionary * assetDict = [LinphoneUtils photoAssetsDictionary]; + [self confirmShare:dictFile[@"nsData"] url:nil text:nil assetId:[[assetDict objectForKey:dictFile[@"url"]] localIdentifier]]; [defaults removeObjectForKey:@"mov"]; }else if (dictText) { //share text - [self confirmShare:nil url:nil text:dictText[@"name"]]; + [self confirmShare:nil url:nil text:dictText[@"name"] assetId:nil]; [defaults removeObjectForKey:@"text"]; } } @@ -363,17 +358,15 @@ static UICompositeViewDescription *compositeDescription = nil; }); } -- (void)confirmShare:(NSData *)data url:(NSURL *)url text:(NSString *)text { +- (void)confirmShare:(NSData *)data url:(NSURL *)url text:(NSString *)text assetId:(NSString *)phAssetId { DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"", nil)]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [sheet addButtonWithTitle:@"send to this friend" block:^() { - if(data && url) - [self startFileUpload:data withUrl:url]; + if(phAssetId) + [self startFileUpload:data assetId:phAssetId]; else [self sendMessage:text withExterlBodyUrl:nil withInternalURL:nil]; - }]; [sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil]; @@ -635,7 +628,14 @@ static UICompositeViewDescription *compositeDescription = nil; return TRUE; } -- (BOOL)startFileUpload:(NSData *)data withUrl:(NSURL *)url { +- (BOOL)startFileUpload:(NSData *)data assetId:phAssetId { + FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init]; + [fileTransfer uploadVideo:data withassetId:phAssetId forChatRoom:_chatRoom]; + [_tableController scrollToBottom:true]; + return TRUE; +} + +- (BOOL)startFileUpload:(NSData *)data withUrl:(NSURL *)url { FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init]; [fileTransfer uploadFile:data forChatRoom:_chatRoom withUrl:url]; [_tableController scrollToBottom:true]; diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index b10d52f2e..39345b48a 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -211,6 +211,9 @@ // we did not load the image yet, so start doing so if (_messageImageView.image == nil) { [_messageImageView startLoading]; + if([localImage isEqualToString:@"uknown"]) { + //TODO add default image + } PHFetchResult *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localImage] options:nil]; UIImage *img = [chatTableView.imagesInChatroom objectForKey:localImage]; if (![assets firstObject]) @@ -224,12 +227,20 @@ } else if (localVideo) { if (_messageImageView.image == nil) { [_messageImageView startLoading]; + PHFetchResult *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localVideo] options:nil]; + UIImage *img = [chatTableView.imagesInChatroom objectForKey:localImage]; + if (![assets firstObject]) + [self loadPlaceholder]; + PHAsset *asset = [assets firstObject]; + if (img) + [self loadImageAsset:asset image:img]; + else + [self loadAsset:asset]; // read video from Documents - NSString *filePath = [LinphoneManager documentFile:localVideo]; - NSURL *url = [NSURL fileURLWithPath:filePath]; + /* NSURL *url = [(AVURLAsset*)assets URL]; AVAsset *asset = [AVAsset assetWithURL:url]; if (asset) - [self loadVideoAsset:asset]; + [self loadVideoAsset:asset];*/ } } else if (localFile) { NSString *text = [NSString stringWithFormat:@"📎 %@",localFile]; @@ -278,7 +289,22 @@ } - (IBAction)onPlayClick:(id)sender { - NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message]; + PHAsset *asset = [_messageImageView asset]; + PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init]; + // options.synchronous = TRUE; + [[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) { + if(playerItem) { + AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem]; + AVPlayerViewController *controller = [[AVPlayerViewController alloc] init]; + [PhoneMainView.instance presentViewController:controller animated:YES completion:nil]; + controller.player = player; + [player play]; + } + else { + LOGE(@"Can't read video"); + } + }]; + /* NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message]; NSString *filePath = [LinphoneManager documentFile:localVideo]; NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -291,7 +317,7 @@ [player play]; } else { [self fileErrorBlock]; - } + }*/ } - (IBAction)onOpenClick:(id)event { diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 0623e4204..faf01c0f8 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -235,9 +235,9 @@ if (linphone_chat_message_get_file_transfer_information(_message) != NULL) { NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:_message]; NSNumber *uploadQuality =[LinphoneManager getMessageAppDataForKey:@"uploadQuality" inMessage:_message]; - NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]; + /*NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]; NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message]; - NSString *fileName = localVideo ? localVideo : localFile; + NSString *fileName = localVideo ? localVideo : localFile;*/ [self onDelete]; if(localImage){ ChatConversationTableView *tableView = VIEW(ChatConversationView).tableController; @@ -266,10 +266,10 @@ } }]; } - } else if(fileName) { + } /*else if(fileName) { NSString *filePath = [LinphoneManager documentFile:fileName]; [_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:filePath] withUrl:[NSURL URLWithString:filePath]]; - } + }*/ } else { [self onDelete]; double delayInSeconds = 0.4; diff --git a/Classes/Utils/FileTransferDelegate.h b/Classes/Utils/FileTransferDelegate.h index 17a4bcc5a..9e840cdcb 100644 --- a/Classes/Utils/FileTransferDelegate.h +++ b/Classes/Utils/FileTransferDelegate.h @@ -14,6 +14,7 @@ - (void)upload:(UIImage *)image withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality; - (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url; +- (void)uploadVideo:(NSData *)data withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom; - (void)cancel; - (BOOL)download:(LinphoneChatMessage *)message; - (void)stopAndDestroy; diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index 9268ff0d6..b84c8e403 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -209,7 +209,7 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m linphone_content_set_name(content, [name UTF8String]); linphone_content_set_size(content, _data.length); _message = linphone_chat_room_create_file_transfer_message(chatRoom, content); - linphone_chat_message_add_text_content(_message, [_text UTF8String]); + //linphone_chat_message_add_text_content(_message, [_text UTF8String]); linphone_content_unref(content); linphone_chat_message_cbs_set_file_transfer_send(linphone_chat_message_get_callbacks(_message), @@ -232,7 +232,15 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m if (phAssetId) [self uploadData:UIImageJPEGRepresentation(image, quality) forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localimage" keyData:phAssetId qualityData:[NSNumber numberWithFloat:quality]]; else - [self uploadData:UIImageJPEGRepresentation(image, quality) forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localimage" keyData:nil qualityData:nil]; + [self uploadData:UIImageJPEGRepresentation(image, quality) forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localimage" keyData:@"unknown" qualityData:nil]; +} + +- (void)uploadVideo:(NSData *)data withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom { + NSString *name = [NSString stringWithFormat:@"%f.mov", [NSDate timeIntervalSinceReferenceDate]]; + if (phAssetId) + [self uploadData:data forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localvideo" keyData:phAssetId qualityData:nil]; + else + [self uploadData:data forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localvideo" keyData:nil qualityData:nil]; } - (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url { diff --git a/linphoneExtension/ShareViewController.m b/linphoneExtension/ShareViewController.m index 33a1c06c4..c71ff1a2b 100644 --- a/linphoneExtension/ShareViewController.m +++ b/linphoneExtension/ShareViewController.m @@ -66,22 +66,17 @@ static NSString* groupName = @"group.belledonne-communications.linphone"; NSURL *url = (NSURL *)item; NSData *nsData = [NSData dataWithContentsOfURL:url]; if (nsData) { - NSDictionary *dict; // We get the corresponding PHAsset identifier so we can display the image in the app without having to duplicate it. NSString *imgPath = url.path; - if ([imgPath hasPrefix:@"/var/mobile/Media/"] && ![imgPath containsString:@"OutgoingTemp"]) { // The image comes from the photos app - NSString *filename; - for ( NSString *comp in [imgPath componentsSeparatedByString:@"/"] ) { - if ([comp containsString:@"IMG_"]) { - filename = [[comp componentsSeparatedByString:@"."] firstObject]; - break; - } + NSString *filename; + for ( NSString *comp in [imgPath componentsSeparatedByString:@"/"] ) { + if ([comp containsString:@"IMG_"]) { + filename = [[comp componentsSeparatedByString:@"."] firstObject]; + break; } - dict = @{@"nsData" : nsData, - @"url" : filename}; - } else { - dict = @{@"nsData" : nsData}; } + NSDictionary *dict = @{@"nsData" : nsData, + @"url" : filename}; [defaults setObject:dict forKey:key]; } else { NSLog(@"NSExtensionItem Error, provider = %@", provider);