diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index 551a22a4d..a29288367 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -28,6 +28,8 @@ @protocol ChatConversationDelegate - (BOOL)startImageUpload:(UIImage *)image assetId:(NSString *)phAssetId withQuality:(float)quality; +- (BOOL)startFileUpload:(NSData *)data assetId:(NSString *)phAssetId; +- (BOOL)startFileUpload:(NSData *)data withName:(NSString *)name; - (void)resendChat:(NSString *)message withExternalUrl:(NSString *)url; - (void)tableViewIsScrolling; diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 422cad12a..3fa69519f 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -32,7 +32,7 @@ #include "linphone/linphonecore.h" @interface ChatConversationView - : TPMultiLayoutViewController { OrderedDictionary *imageQualities; BOOL scrollOnGrowingEnabled; @@ -61,7 +61,6 @@ @property (weak, nonatomic) IBOutlet UIIconButton *infoButton; @property (weak, nonatomic) IBOutlet UILabel *particpantsLabel; @property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController; -@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker; @property NSMutableArray *imagesArray; @property NSMutableArray *assetIdsArray; @property NSMutableArray *qualitySettingsArray; @@ -81,7 +80,6 @@ - (IBAction)onDeleteClick:(id)sender; - (IBAction)onEditionChangeClick:(id)sender; - (void)update; -- (void)getIcloudFiles; - (void)openFile:(NSString *) filePath; - (void)clearMessageView; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index cd0d3edd4..840cc3d7f 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -626,7 +626,7 @@ static UICompositeViewDescription *compositeDescription = nil; return TRUE; } -- (BOOL)startFileUpload:(NSData *)data assetId:phAssetId { +- (BOOL)startFileUpload:(NSData *)data assetId:(NSString *)phAssetId { FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init]; [fileTransfer uploadVideo:data withassetId:phAssetId forChatRoom:_chatRoom]; [_tableController scrollToBottom:true]; @@ -907,16 +907,6 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog * [view.tableController scrollToBottom:true]; } -- (void)getIcloudFiles -{ - _documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"] - inMode:UIDocumentPickerModeImport]; - _documentPicker.delegate = self; - - _documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; - [self presentViewController:_documentPicker animated:YES completion:nil]; -} - - (void)openFile:(NSString *) filePath { // Open the controller. @@ -931,21 +921,6 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog * } } -- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { - - NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil]; - [fileCoordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges error:nil byAccessor:^(NSURL * _Nonnull newURL) { - - NSString *fileName = [newURL lastPathComponent]; - NSData *data = [NSData dataWithContentsOfURL:newURL]; - - NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName]; - - [[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil]; - [self openFile:filePath]; - }]; -} - - (void)deleteImageWithAssetId:(NSString *)assetId { NSUInteger key = [_assetIdsArray indexOfObject:assetId]; [_imagesArray removeObjectAtIndex:key]; diff --git a/Classes/ImagePickerView.m b/Classes/ImagePickerView.m index fdf5f602c..f5a0cc62f 100644 --- a/Classes/ImagePickerView.m +++ b/Classes/ImagePickerView.m @@ -163,9 +163,13 @@ static UICompositeViewDescription *compositeDescription = nil; [self dismiss]; NSURL *alassetURL = [info objectForKey:UIImagePickerControllerReferenceURL]; - PHFetchResult *phFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[alassetURL] options:nil]; - PHAsset *phasset = [phFetchResult firstObject]; - //PHAsset *phasset = [info objectForKey:UIImagePickerControllerPHAsset]; + PHAsset *phasset = nil; + // when photo from camera, it hasn't be saved + if (alassetURL) { + PHFetchResult *phFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[alassetURL] options:nil]; + phasset = [phFetchResult firstObject]; + } + UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage] ? [info objectForKey:UIImagePickerControllerEditedImage] : [info objectForKey:UIImagePickerControllerOriginalImage]; if (!phasset) { __block PHObjectPlaceholder *placeHolder; diff --git a/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib index 50403d66f..c453ff689 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatBubblePhotoCell.xib @@ -19,8 +19,10 @@ - + + + @@ -29,7 +31,6 @@ - @@ -74,14 +75,6 @@ - @@ -144,7 +137,6 @@ - @@ -179,6 +171,29 @@ + + + + + + + + @@ -200,11 +215,6 @@ - - - - - diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.h b/Classes/LinphoneUI/UIChatBubblePhotoCell.h index 1aa697eec..c39967456 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.h +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.h @@ -34,11 +34,12 @@ @property(weak, nonatomic) IBOutlet UIProgressView *fileTransferProgress; @property(weak, nonatomic) IBOutlet UIButton *cancelButton; @property(weak, nonatomic) IBOutlet UIView *imageSubView; -@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *openRecognizer; @property(weak, nonatomic) IBOutlet UIView *totalView; @property (weak, nonatomic) IBOutlet UIView *finalAssetView; @property (weak, nonatomic) IBOutlet UIImageView *finalImage; @property(strong, nonatomic) IBOutlet UITapGestureRecognizer *imageGestureRecognizer; +@property (weak, nonatomic) IBOutlet UIButton *fileButton; +@property (weak, nonatomic) IBOutlet UIView *fileView; - (void)setEvent:(LinphoneEventLog *)event; - (void)setChatMessage:(LinphoneChatMessage *)message; @@ -48,8 +49,7 @@ - (IBAction)onCancelClick:(id)sender; - (IBAction)onResendClick:(id)event; - (IBAction)onPlayClick:(id)sender; -- (IBAction)onOpenClick:(id)event; - +- (IBAction)onFileClick:(id)sender; @end diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index ca81111a7..c9e4ed27c 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -72,7 +72,6 @@ - (void)setChatMessage:(LinphoneChatMessage *)amessage { _imageGestureRecognizer.enabled = NO; - _openRecognizer.enabled = NO; _messageImageView.image = nil; _finalImage.image = nil; _finalImage.hidden = TRUE; @@ -131,9 +130,8 @@ - (void) loadFileAsset { dispatch_async(dispatch_get_main_queue(), ^{ - _fileName.hidden = NO; + _fileName.hidden = _fileView.hidden = _fileButton.hidden = NO; _imageGestureRecognizer.enabled = NO; - _openRecognizer.enabled = YES; }); } @@ -167,14 +165,14 @@ if (!(localImage || localVideo || localFile)) { _playButton.hidden = YES; - _fileName.hidden = YES; + _fileName.hidden = _fileView.hidden = _fileButton.hidden = YES; _messageImageView.hidden = _cancelButton.hidden = (_ftd.message == nil); _downloadButton.hidden = !_cancelButton.hidden; _fileTransferProgress.hidden = NO; } else { // file is being saved on device - just wait for it if ([localImage isEqualToString:@"saving..."] || [localVideo isEqualToString:@"saving..."] || [localFile isEqualToString:@"saving..."]) { - _cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = YES; + _cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = _fileView.hidden = _fileButton.hidden = YES; fullScreenImage = YES; } else if(!assetIsLoaded) { assetIsLoaded = TRUE; @@ -191,7 +189,7 @@ } } else if (localFile) { - NSString *text = [NSString stringWithFormat:@"📎 %@",localFile]; + NSString *text = [NSString stringWithFormat:@"📎 %@",localFile]; _fileName.text = text; [self loadFileAsset]; } @@ -202,12 +200,12 @@ _fileTransferProgress.hidden = NO; _downloadButton.hidden = YES; _playButton.hidden = YES; - _fileName.hidden = YES; + _fileName.hidden = _fileView.hidden = _fileButton.hidden =YES; } else { _cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES; fullScreenImage = YES; _playButton.hidden = localVideo ? NO : YES; - _fileName.hidden = localFile ? NO : YES; + _fileName.hidden = _fileView.hidden = _fileButton.hidden = localFile ? NO : YES; // Should fix cell not resizing after doanloading image. [self layoutSubviews]; } @@ -250,7 +248,7 @@ _cancelButton.hidden = NO; _downloadButton.hidden = YES; _playButton.hidden = YES; - _fileName.hidden = YES; + _fileName.hidden = _fileView.hidden = _fileButton.hidden = YES; } - (IBAction)onPlayClick:(id)sender { @@ -271,7 +269,7 @@ }]; } -- (IBAction)onOpenClick:(id)event { +- (IBAction)onFileClick:(id)sender { ChatConversationView *view = VIEW(ChatConversationView); NSString *cachedFile = [LinphoneManager getMessageAppDataForKey:@"cachedfile" inMessage:self.message]; if (cachedFile) { @@ -281,8 +279,10 @@ } else { [self fileErrorBlock]; } - } else - [view getIcloudFiles]; + } else { + [LinphoneManager setValueInMessageAppData:@"onFileClick" forKey:@"icloudFileOption" inMessage:self.message]; + [super getIcloudFiles]; + } } @@ -401,7 +401,7 @@ } bubbleFrame.origin.x = origin_x; - + super.bubbleView.frame = bubbleFrame; // Resizing Image view diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.h b/Classes/LinphoneUI/UIChatBubbleTextCell.h index 18f5d879c..1d66bc5b8 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.h +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.h @@ -23,7 +23,7 @@ #import "ChatConversationTableView.h" #import "UIRoundedImageView.h" -@interface UIChatBubbleTextCell : UITableViewCell +@interface UIChatBubbleTextCell : UITableViewCell @property(readonly, nonatomic) LinphoneEventLog *event; @property(readonly, nonatomic) LinphoneChatMessage *message; @@ -40,11 +40,14 @@ @property(weak, nonatomic) IBOutlet UIImageView *imdmIcon; @property(weak, nonatomic) IBOutlet UILabel *imdmLabel; +@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker; + + (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width; + (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width; - (void)setEvent:(LinphoneEventLog *)event; - (void)setChatMessage:(LinphoneChatMessage *)message; +- (void)getIcloudFiles; - (void)onDelete; - (void)onResend; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 85b20dce9..8e207f682 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -128,7 +128,7 @@ _statusInProgressSpinner.accessibilityLabel = @"Delivery in progress"; - if (_messageText) { + if (_messageText && ![LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]) { LOGD(_messageText.text); [_messageText setHidden:FALSE]; /* We need to use an attributed string here so that data detector don't mess @@ -207,6 +207,36 @@ [PhoneMainView.instance presentViewController:errView animated:YES completion:nil]; } +- (void)getIcloudFiles { + _documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"] + inMode:UIDocumentPickerModeImport]; + _documentPicker.delegate = self; + + _documentPicker.modalPresentationStyle = UIModalPresentationOverCurrentContext ; + ChatConversationView *view = VIEW(ChatConversationView); + [view presentViewController:_documentPicker animated:YES completion:nil]; + } + + - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { + NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil]; + [fileCoordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges error:nil byAccessor:^(NSURL * _Nonnull newURL) { + + NSString *fileName = [newURL lastPathComponent]; + NSData *data = [NSData dataWithContentsOfURL:newURL]; + NSString *option = [LinphoneManager getMessageAppDataForKey:@"icloudFileOption" inMessage:self.message]; + + if ([option isEqualToString:@"onResend"]) + [_chatRoomDelegate startFileUpload:data withName:fileName]; + else if ([option isEqualToString:@"onFileClick"]) { + ChatConversationView *view = VIEW(ChatConversationView); + NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName]; + [[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil]; + [view openFile:filePath]; + } + }]; +} + + #pragma mark - Action Functions - (void)onDelete { @@ -235,10 +265,8 @@ if (linphone_chat_message_get_file_transfer_information(_message) != NULL) { NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:_message]; NSNumber *uploadQuality =[LinphoneManager getMessageAppDataForKey:@"uploadQuality" inMessage:_message]; - - // TODO: do resend for video and files - /*NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]; - NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message];*/ + NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message]; + NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message]; [self onDelete]; if(localImage){ @@ -254,6 +282,9 @@ if (![assets firstObject]) return; PHAsset *asset = [assets firstObject]; + if (asset.mediaType != PHAssetMediaTypeImage) + return; + PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = TRUE; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options @@ -268,10 +299,36 @@ } }]; } - } /*else if(fileName) { - NSString *filePath = [LinphoneManager documentFile:fileName]; - [_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:filePath] withUrl:[NSURL URLWithString:filePath]]; - }*/ + } else if (localVideo) { + PHFetchResult *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localVideo] options:nil]; + if (![assets firstObject]) + return; + PHAsset *asset = [assets firstObject]; + if (asset.mediaType != PHAssetMediaTypeVideo) + return; + + PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init]; + options.version = PHImageRequestOptionsVersionCurrent; + options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic; + + [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) { + AVURLAsset *urlAsset = (AVURLAsset *)asset; + + NSURL *url = urlAsset.URL; + NSData *data = [NSData dataWithContentsOfURL:url]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), + ^(void) { + [_chatRoomDelegate startFileUpload:data assetId:localVideo]; + }); + }]; + + } else if (localFile) { + [LinphoneManager setValueInMessageAppData:@"onResend" forKey:@"icloudFileOption" inMessage:_message]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), + ^(void) { + [self getIcloudFiles]; + }); + } } else { [self onDelete]; double delayInSeconds = 0.4; diff --git a/linphoneExtension/ShareViewController.m b/linphoneExtension/ShareViewController.m index 1f656a9bc..788ac49af 100644 --- a/linphoneExtension/ShareViewController.m +++ b/linphoneExtension/ShareViewController.m @@ -77,12 +77,12 @@ static NSString* groupName = @"group.belledonne-communications.linphone"; NSDictionary *dict = @{@"nsData" : nsData, @"url" : filename}; [defaults setObject:dict forKey:@"photoData"]; - } else if ([imgPath containsString:@"var/mobile/Library/Mobile Documents/com~apple~CloudDocs"]) { + } else if ([imgPath containsString:@"var/mobile/Library/Mobile Documents/com~apple~CloudDocs"] || [[url scheme] isEqualToString:@"file"]) { // shared files from icloud drive NSDictionary *dict = @{@"nsData" : nsData, @"url" : filename}; [defaults setObject:dict forKey:@"icloudData"]; - }else { + } else { //Others NSDictionary *dict = @{@"url" : [url absoluteString]}; [defaults setObject:dict forKey:@"url"]; diff --git a/submodules/linphone b/submodules/linphone index f319f5cf1..4c7c3de24 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit f319f5cf17eb0f54596fdd02a0c1bd6f1ebca552 +Subproject commit 4c7c3de24bf6fc2d1d95c3c6d025b788275f9554