From edea29fd49063319814548ec18720106b08de89b Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 18 May 2021 16:23:43 +0200 Subject: [PATCH] fix vfs display --- Classes/ChatConversationTableView.h | 1 - Classes/ChatConversationTableView.m | 6 +----- Classes/ChatConversationView.m | 2 +- Classes/LinphoneAppDelegate.m | 5 +++++ Classes/LinphoneUI/UIChatBubblePhotoCell.h | 2 +- Classes/LinphoneUI/UIChatBubblePhotoCell.m | 23 +++++++++++++--------- Classes/LinphoneUI/UIChatBubbleTextCell.h | 3 +-- Classes/LinphoneUI/UIChatBubbleTextCell.m | 20 ++++++++++++------- Classes/Utils/FileTransferDelegate.m | 2 +- 9 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index b0e701f60..39fd08ba6 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -57,7 +57,6 @@ @property(nonatomic) NSInteger currentIndex; @property(nonatomic, strong) id chatRoomDelegate; @property NSMutableDictionary *imagesInChatroom; -@property(nonatomic) BOOL vfsEnabled; - (void)addEventEntry:(LinphoneEventLog *)event; - (void)scrollToBottom:(BOOL)animated; diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 0df8ff435..6b3d7eebc 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -183,10 +183,6 @@ #pragma mark - Property Functions - (void)setChatRoom:(LinphoneChatRoom *)room { - if (room) { - _vfsEnabled = [VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && (linphone_chat_room_get_capabilities(room) & LinphoneChatRoomCapabilitiesEncrypted); - } - _chatRoom = room; [self reloadData]; } @@ -270,7 +266,7 @@ static const int BASIC_EVENT_LIST=15; UIChatBubbleTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; - [cell setEvent:event vfsEnabled:_vfsEnabled]; + [cell setEvent:event]; if (chat) { cell.isFirst = [self isFirstIndexInTableView:indexPath chat:chat]; cell.isLast = [self isLastIndexInTableView:indexPath chat:chat]; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 43ac5f8a3..031132c73 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -1492,7 +1492,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog [LinphoneManager setValueInMessageAppData:name forKey:key inMessage:message]; dispatch_async(dispatch_get_main_queue(), ^{ [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:view]; - if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { + if (![VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && [ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { [ChatConversationView writeMediaToGallery:name fileType:fileType]; } }); diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 320ca404f..c34381278 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -327,6 +327,11 @@ - (void)applicationWillTerminate:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); + if (PhoneMainView.instance.currentView == ChatConversationView.compositeViewDescription) { + ChatConversationView *view = VIEW(ChatConversationView); + [view.tableController setChatRoom:NULL]; + } + LinphoneManager.instance.conf = TRUE; linphone_core_terminate_all_calls(LC); [CallManager.instance removeAllCallInfos]; diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.h b/Classes/LinphoneUI/UIChatBubblePhotoCell.h index 71d45bcfb..43b6b6eed 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.h +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.h @@ -45,7 +45,7 @@ @property(strong, nonatomic) NSMutableArray *contentViews; -- (void)setEvent:(LinphoneEventLog *)event vfsEnabled:(BOOL)enabled; +- (void)setEvent:(LinphoneEventLog *)event; - (void)setChatMessage:(LinphoneChatMessage *)message; - (void)connectToFileDelegate:(FileTransferDelegate *)ftd; - (IBAction)onDownloadClick:(id)event; diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index f33884a1f..e807560bd 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -63,11 +63,11 @@ } #pragma mark - -- (void)setEvent:(LinphoneEventLog *)event vfsEnabled:(BOOL)enabled { +- (void)setEvent:(LinphoneEventLog *)event { if (!event || !(linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceChatMessage)) return; - [super setEvent:event vfsEnabled:enabled]; + [super setEvent:event]; [self setChatMessage:linphone_event_log_get_chat_message(event)]; } @@ -133,6 +133,7 @@ _fileName.hidden = _fileView.hidden = _fileButton.hidden = NO; _imageGestureRecognizer.enabled = NO; _plusLongGestureRecognizer.enabled = NO; + _playButton.hidden = YES; }); } @@ -162,7 +163,7 @@ if (multiParts) { if (!assetIsLoaded) { NSMutableDictionary *encrptedFilePaths = NULL; - if (self.vfsEnabled) { + if ([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]) { encrptedFilePaths = [LinphoneManager getMessageAppDataForKey:@"encryptedfiles" inMessage:self.message]; if (!encrptedFilePaths) { encrptedFilePaths = [NSMutableDictionary dictionary]; @@ -178,7 +179,7 @@ LinphoneContent *content = (LinphoneContent *)it->data; if (linphone_content_is_file_transfer(content) || linphone_content_is_file(content)){ UIChatContentView *contentView = [[UIChatContentView alloc] initWithFrame: CGRectMake(0,0,0,0)]; - if(self.vfsEnabled && (linphone_chat_message_is_outgoing(self.message) || linphone_content_is_file(content))) { + if([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && (linphone_chat_message_is_outgoing(self.message) || linphone_content_is_file(content))) { // downloaded or ougoing message NSString *name = [NSString stringWithUTF8String:linphone_content_get_name(content)]; NSString *filePath = [encrptedFilePaths valueForKey:name]; @@ -187,7 +188,9 @@ if (cPath) { if (strcmp(cPath, "") != 0) { NSString *tempPath = [NSString stringWithUTF8String:cPath]; - filePath = [tempPath stringByDeletingPathExtension]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + filePath = [paths objectAtIndex:0]; + filePath = [filePath stringByAppendingPathComponent:name]; [[NSFileManager defaultManager] moveItemAtPath:tempPath toPath:filePath error:nil]; } ms_free(cPath); @@ -202,7 +205,7 @@ i++; } } - if (self.vfsEnabled) { + if ([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]) { [LinphoneManager setValueInMessageAppData:encrptedFilePaths forKey:@"encryptedfiles" inMessage:self.message]; } assetIsLoaded = TRUE; @@ -251,11 +254,13 @@ NSString *fileName = [NSString stringWithUTF8String:linphone_content_get_name(fileContent)]; if (!filePath) { - char *cPath = self.vfsEnabled ? linphone_content_get_plain_file_path(fileContent) : NULL; + char *cPath = [VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] ? linphone_content_get_plain_file_path(fileContent) : NULL; if (cPath) { if (strcmp(cPath, "") != 0) { NSString *tempPath = [NSString stringWithUTF8String:cPath]; - filePath = [tempPath stringByDeletingPathExtension]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + filePath = [paths objectAtIndex:0]; + filePath = [filePath stringByAppendingPathComponent:fileName]; [[NSFileManager defaultManager] moveItemAtPath:tempPath toPath:filePath error:nil]; } ms_free(cPath); @@ -312,7 +317,7 @@ // If the file has been downloaded in background, save it in the folders and display it. [LinphoneManager setValueInMessageAppData:fileName forKey:key inMessage:self.message]; dispatch_async(dispatch_get_main_queue(), ^ { - if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { + if (![VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && [ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { [ChatConversationView writeMediaToGallery:fileName fileType:fileType]; } }); diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.h b/Classes/LinphoneUI/UIChatBubbleTextCell.h index ba3f981dd..bf34937d2 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.h +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.h @@ -49,7 +49,6 @@ @property(nonatomic) BOOL isFirst; @property(nonatomic) BOOL isLast; @property(nonatomic) BOOL notDelivered; -@property(nonatomic) BOOL vfsEnabled; + (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width; + (CGSize)ViewHeightForMessageText:(LinphoneChatMessage *)chat withWidth:(int)width textForImdn:(NSString *)imdnText; @@ -57,7 +56,7 @@ + (UIImage *)getImageFromVideoUrl:(NSURL *)url; + (UIImage *)getImageFromContent:(LinphoneContent *)content filePath:(NSString *)filePath; -- (void)setEvent:(LinphoneEventLog *)event vfsEnabled:(BOOL)enabled; +- (void)setEvent:(LinphoneEventLog *)event; - (void)setChatMessageForCbs:(LinphoneChatMessage *)message; - (void)clearEncryptedFiles; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 87328adee..db4c78928 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -62,18 +62,20 @@ } - (void)dealloc { - [self setEvent:NULL vfsEnabled:_vfsEnabled]; + [self setEvent:NULL]; [self setChatMessageForCbs:NULL]; } #pragma mark - - (void)clearEncryptedFiles { - if (_vfsEnabled) { + if ([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]) { NSMutableDictionary *encrptedFilePaths = [LinphoneManager getMessageAppDataForKey:@"encryptedfiles" inMessage:_message]; if ([encrptedFilePaths count] > 0) { for(NSString *path in [encrptedFilePaths allValues]) { - [[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; + if (![path isEqualToString:@""]) { + [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; + } } [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfiles" inMessage:_message]; return; @@ -81,19 +83,23 @@ NSString *filePath = [LinphoneManager getMessageAppDataForKey:@"encryptedfile" inMessage:_message]; if (filePath) { - if (![filePath isEqualToString:@""]) - [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; + if (![filePath isEqualToString:@""]) { + NSError *error = nil; + [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; + if (error) { + LOGI(@"clean failed %@", error.description); + } + } [LinphoneManager setValueInMessageAppData:NULL forKey:@"encryptedfile" inMessage:_message]; } } } -- (void)setEvent:(LinphoneEventLog *)event vfsEnabled:(BOOL)enabled { +- (void)setEvent:(LinphoneEventLog *)event { if(!event) return; _event = event; - _vfsEnabled = enabled; if (!(linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceChatMessage)) { LOGE(@"Impossible to create a ChatBubbleText whit a non message event"); return; diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index de7c259ee..970288c86 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -57,7 +57,7 @@ static void file_transfer_progress_indication_recv(LinphoneChatMessage *message, forKey:key inMessage:message]; dispatch_async(dispatch_get_main_queue(), ^{ - if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { + if (![VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] && [ConfigManager.instance lpConfigBoolForKeyWithKey:@"auto_write_to_gallery_preference"]) { [ChatConversationView writeMediaToGallery:name fileType:fileType]; } });