mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
avoid copy photo and video
This commit is contained in:
parent
0a3cc7424e
commit
754b1cf7d9
7 changed files with 73 additions and 43 deletions
|
|
@ -28,7 +28,7 @@
|
|||
@protocol ChatConversationDelegate <NSObject>
|
||||
|
||||
- (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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <NSString *, PHAsset *> * assetDict = [LinphoneUtils photoAssetsDictionary];
|
||||
[self chooseImageQuality:image assetId:[[assetDict objectForKey:filename] localIdentifier]];
|
||||
} else
|
||||
[self chooseImageQuality:image assetId:@""];
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
NSMutableDictionary <NSString *, PHAsset *> * 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 <NSString *, PHAsset *> * 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];
|
||||
|
|
|
|||
|
|
@ -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<PHAsset *> *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<PHAsset *> *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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue