diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m
index f070e0646..0e7f5ea10 100644
--- a/Classes/LinphoneAppDelegate.m
+++ b/Classes/LinphoneAppDelegate.m
@@ -265,9 +265,9 @@
#ifdef USE_CRASHLYTICS
[FIRApp configure];
#endif
-
-
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"vfs_enabled"] && !VFSUtil.activateVFS) {
+
+
+ if ([[LinphoneManager instance] lpConfigBoolForKey:@"vfs_enabled_preference"] && !VFSUtil.activateVFS) {
[VFSUtil oslogWithLog:@"[VFS] Error unable to activate." level:OS_LOG_TYPE_ERROR];
}
diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m
index cb993f0a5..946760e31 100644
--- a/Classes/LinphoneCoreSettingsStore.m
+++ b/Classes/LinphoneCoreSettingsStore.m
@@ -339,6 +339,7 @@
int maxSize = linphone_core_get_max_size_for_auto_download_incoming_files(LC);
[self setObject:maxSize==0 ? @"Always" : (maxSize==-1 ? @"Nerver" : @"Customize") forKey:@"auto_download_mode"];
[self setInteger:maxSize forKey:@"auto_download_incoming_files_max_size"];
+ [self setBool:[lm lpConfigBoolForKey:@"vfs_enabled_preference" withDefault:NO] forKey:@"vfs_enabled_mode"];
[self setBool:[lm lpConfigBoolForKey:@"auto_write_to_gallery_preference" withDefault:YES] forKey:@"auto_write_to_gallery_mode"];
}
@@ -780,6 +781,11 @@
}
linphone_core_set_max_size_for_auto_download_incoming_files(LC, maxSize);
[lm lpConfigSetString:[self stringForKey:@"auto_download_mode"] forKey:@"auto_download_mode"];
+ BOOL vfsEnabled = [self boolForKey:@"vfs_enabled_mode"] || [lm lpConfigBoolForKey:@"vfs_enabled_preference"];
+ if (vfsEnabled) {
+ [lm lpConfigSetBool:TRUE forKey:@"vfs_enabled_preference"];
+ [self setBool:TRUE forKey:@"vfs_enabled_mode"];
+ }
[lm lpConfigSetBool:[self boolForKey:@"auto_write_to_gallery_mode"] forKey:@"auto_write_to_gallery_preference"];
// network section
diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m
index 3100c0d83..e6dfd2b16 100644
--- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m
+++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m
@@ -57,6 +57,15 @@
return self;
}
+- (void)dealloc {
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:self.message];
+ if (filePath) {
+ [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
+ [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfile" inMessage:self.message];
+ }
+}
+
+
- (void)onDelete {
[super onDelete];
}
@@ -92,6 +101,7 @@
}
[super setChatMessageForCbs:amessage];
+ [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfile" inMessage:self.message];
}
- (void) loadImageAsset:(PHAsset*) asset image:(UIImage *)image {
@@ -161,6 +171,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:self.message];
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:self.message];
assert(is_external || localImage || localVideo || localFile);
LinphoneContent *fileContent = linphone_chat_message_get_file_transfer_information(self.message);
@@ -190,9 +201,17 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
NSString *fileType = [NSString stringWithUTF8String:linphone_content_get_type(fileContent)];
NSString *fileName = [NSString stringWithUTF8String:linphone_content_get_name(fileContent)];
- NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
-
+ if (!filePath) {
+ char *cPath = linphone_content_get_plain_file_path(fileContent);
+ if (cPath) {
+ filePath = [NSString stringWithUTF8String:cPath];
+ ms_free(cPath);
+ [LinphoneManager setValueInMessageAppData:filePath forKey:@"encryptedfile" inMessage:self.message];
+ } else {
+ filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
+ }
+ }
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
// already downloaded
if (!assetIsLoaded) {
@@ -201,7 +220,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
if ([key isEqualToString:@"localimage"]) {
// we did not load the image yet, so start doing so
if (_messageImageView.image == nil) {
- NSData* data = [NSData dataWithContentsOfFile:filePath];
+ NSData *data = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [[UIImage alloc] initWithData:data];
if (image) {
[self loadImageAsset:nil image:image];
@@ -213,7 +232,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
}
} else if ([key isEqualToString:@"localvideo"]) {
if (_messageImageView.image == nil) {
- UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:fileName]];
+ UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[NSURL fileURLWithPath:filePath]];
if (image) {
[self loadImageAsset:nil image:image];
_imageGestureRecognizer.enabled = NO;
@@ -224,11 +243,11 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
}
} else if ([key isEqualToString:@"localfile"]) {
if ([fileType isEqualToString:@"video"]) {
- UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:fileName]];
+ UIImage* image = [UIChatBubbleTextCell getImageFromVideoUrl:[NSURL fileURLWithPath:filePath]];
[self loadImageAsset:nil image:image];
_imageGestureRecognizer.enabled = NO;
} else if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"] || [fileName hasSuffix:@"jpg"] || [fileName hasSuffix:@"png"]) {
- NSData *data = [ChatConversationView getCacheFileData:fileName];
+ NSData *data = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [[UIImage alloc] initWithData:data];
[self loadImageAsset:nil image:image];
_imageGestureRecognizer.enabled = YES;
@@ -390,14 +409,15 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
}
- (IBAction)onPlayClick:(id)sender {
- NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message];
- NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
- if (localVideo && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localVideo]]) {
- AVPlayer *player = [AVPlayer playerWithURL:[ChatConversationView getCacheFileUrl:localVideo]];
- [self playVideoByPlayer:player];
- return;
- } else if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localFile]]) {
- AVPlayer *player = [AVPlayer playerWithURL:[ChatConversationView getCacheFileUrl:localFile]];
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:self.message];
+ if (!filePath) {
+ NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message];
+ NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
+ filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:(localVideo?:localFile)];
+ }
+
+ if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+ AVPlayer *player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:filePath]];
[self playVideoByPlayer:player];
return;
}
@@ -449,6 +469,11 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
- (IBAction)onFileClick:(id)sender {
ChatConversationView *view = VIEW(ChatConversationView);
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:self.message];
+ if (filePath) {
+ [view openFileWithURL:[NSURL URLWithString:filePath]];
+ return;
+ }
NSString *name = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
if([[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name]]) {
[view openFileWithURL:[ChatConversationView getCacheFileUrl:name]];
@@ -487,6 +512,14 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
if (![_messageImageView isLoading]) {
ImageView *view = VIEW(ImageView);
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:self.message];
+ if (filePath) {
+ NSData *data = [NSData dataWithContentsOfFile:filePath];
+ UIImage *image = [[UIImage alloc] initWithData:data];
+ [view setImage:image];
+ return;
+ }
+
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:self.message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
NSString *imageName = NULL;
diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m
index 4522ff5b9..3509b9772 100644
--- a/Classes/LinphoneUI/UIChatBubbleTextCell.m
+++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m
@@ -278,25 +278,31 @@
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:_message];
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message];
-
+
/*FileTransferDelegate *thiz = [FileTransferDelegate messageDelegate:_message];
if (thiz) {
[thiz stop]
}*/
[self onDelete];
- if(localImage){
- dispatch_async(dispatch_get_main_queue(), ^ {
- [_chatRoomDelegate resendFile:[ChatConversationView getCacheFileData:localImage] withName:localImage type:@"image" key:@"localimage" message:self.textMessage];
- });
- } else if (localVideo) {
- dispatch_async(dispatch_get_main_queue(), ^ {
- [_chatRoomDelegate resendFile:[ChatConversationView getCacheFileData:localVideo] withName:localVideo type:@"video" key:@"localvideo" message:self.textMessage];
- });
- } else if (localFile) {
- dispatch_async(dispatch_get_main_queue(), ^ {
- [_chatRoomDelegate resendFile:[ChatConversationView getCacheFileData:localFile] withName:localFile type:@"image" key:@"localfile" message:self.textMessage];
- });
- }
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ LinphoneContent *fileContent = linphone_chat_message_get_file_transfer_information(_message);
+ NSData *data = NULL;
+ char *cPath = linphone_content_get_plain_file_path(fileContent);
+ if (cPath) {
+ NSString *filePath = [NSString stringWithUTF8String:linphone_content_get_plain_file_path(fileContent)];
+ data = [NSData dataWithContentsOfFile:filePath];
+ ms_free(cPath);
+ [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
+ }
+
+ if (localImage) {
+ [_chatRoomDelegate resendFile: (data?:[ChatConversationView getCacheFileData:localImage]) withName:localImage type:@"image" key:@"localimage" message:self.textMessage];
+ } else if (localVideo) {
+ [_chatRoomDelegate resendFile:(data?:[ChatConversationView getCacheFileData:localVideo]) withName:localVideo type:@"video" key:@"localvideo" message:self.textMessage];
+ } else {
+ [_chatRoomDelegate resendFile:(data?:[ChatConversationView getCacheFileData:localFile]) withName:localFile type:@"image" key:@"localfile" message:self.textMessage];
+ }
+ });
} else {
[self onDelete];
double delayInSeconds = 0.4;
@@ -403,6 +409,7 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:chat];
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:chat];
+ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:chat];
CGSize textSize = CGSizeMake(0, 0);
if (![messageText isEqualToString:@"🗻"]) {
@@ -416,10 +423,12 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
if (localFile) {
UIImage *image = nil;
NSString *type = [NSString stringWithUTF8String:linphone_content_get_type(fileContent)];
- NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localFile];
+ if (!filePath) {
+ filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localFile];
+ }
if ([type isEqualToString:@"video"]) {
if ([[NSFileManager defaultManager] fileExistsAtPath: filePath]) {
- image = [self getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:localFile]];
+ image = [self getImageFromVideoUrl:[NSURL fileURLWithPath:filePath]];
} else {
image = [self getImageFromVideoUrl:[VIEW(ChatConversationView) getICloudFileUrl:localFile]];
}
@@ -442,15 +451,22 @@ static const CGFloat CELL_IMAGE_X_MARGIN = 100;
return CGSizeMake(CELL_MIN_WIDTH + CELL_MESSAGE_X_MARGIN, CELL_MIN_HEIGHT + CELL_MESSAGE_Y_MARGIN + textSize.height + 20);
}
- if (localImage && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localImage]]) {
- NSData* data = [ChatConversationView getCacheFileData:localImage];
+ if (!filePath) {
+ if (localImage) {
+ filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localImage];
+ } else {
+ filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localVideo];
+ }
+ }
+ if (localImage && [[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+ NSData* data = [NSData dataWithContentsOfFile:filePath];
UIImage *image = [[UIImage alloc] initWithData:data];
if (!image) {
return [self ViewHeightForFile:width];
}
originalImageSize = image.size;
- } else if (localVideo && [[NSFileManager defaultManager] fileExistsAtPath:[[LinphoneManager cacheDirectory] stringByAppendingPathComponent:localVideo]]) {
- UIImage *image = [UIChatBubbleTextCell getImageFromVideoUrl:[ChatConversationView getCacheFileUrl:localVideo]];
+ } else if (localVideo && [[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+ UIImage *image = [UIChatBubbleTextCell getImageFromVideoUrl:[NSURL URLWithString:filePath]];
if (!image) {
return [self ViewHeightForFile:width];
}
diff --git a/Settings/InAppSettings.bundle/Chat.plist b/Settings/InAppSettings.bundle/Chat.plist
index ac258525b..d5e3c9395 100644
--- a/Settings/InAppSettings.bundle/Chat.plist
+++ b/Settings/InAppSettings.bundle/Chat.plist
@@ -26,6 +26,16 @@
Customize
+
+ DefaultValue
+
+ Key
+ vfs_enabled_mode
+ Title
+ Enable VFS
+ Type
+ PSToggleSwitchSpecifier
+
DefaultValue