marinofaggiana 4 years ago
parent
commit
6c6f600abc

+ 11 - 12
iOSClient/Activity/NCActivity.swift

@@ -402,24 +402,23 @@ extension activityTableViewCell: UICollectionViewDelegate {
                     let fileName = (url as NSString).lastPathComponent
                     let serverUrlFileName = serverUrl + "/" + fileName
                     
-                    NCCommunication.sharedInstance.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles(), account: activityPreview.account) { (account, files, errorCode, errorDescription) in
-                       
+                    NCNetworking.sharedInstance.readFile(serverUrlFileName: serverUrlFileName, account: activityPreview.account) { (account, metadata, errorCode, errorDescription) in
+                        
                         NCUtility.sharedInstance.stopActivityIndicator()
                         
-                        if account == self.appDelegate.activeAccount && errorCode == 0 && files != nil  {
-                            
-                            let metadata = NCNetworking.sharedInstance.convertFileToMetadata(files![0])
-                            metadata.fileName = fileName
-                            metadata.fileNameView = fileName
+                        if account == self.appDelegate.activeAccount && errorCode == 0  {
                             
+                            metadata!.fileName = fileName
+                            metadata!.fileNameView = fileName
+                                                       
                             // move from id to oc:id + instanceid (ocId)
-                            
+                                                       
                             let atPath = CCUtility.getDirectoryProviderStorage()! + "/" + activitySubjectRich.id
-                            let toPath = CCUtility.getDirectoryProviderStorage()! + "/" + metadata.ocId
-                            
+                            let toPath = CCUtility.getDirectoryProviderStorage()! + "/" + metadata!.ocId
+                                                       
                             CCUtility.moveFile(atPath: atPath, toPath: toPath)
-                            
-                            if let metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) {
+                                                       
+                            if let metadata = NCManageDatabase.sharedInstance.addMetadata(metadata!) {
                                 self.appDelegate.activeMain.performSegue(withIdentifier: "segueDetail", sender: metadata)
                             }
                         }

+ 7 - 11
iOSClient/Main/CCMain.m

@@ -1392,28 +1392,24 @@
         [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
     });
     
-    [[NCCommunication sharedInstance] readFileOrFolderWithServerUrlFileName:self.serverUrl depth:@"0" showHiddenFiles:[CCUtility getShowHiddenFiles] account:appDelegate.activeAccount completionHandler:^(NSString *account, NSArray*files, NSInteger errorCode, NSString *errorMessage) {
-          
-        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount] && files != nil) {
-            
-            NCFile *file = files[0];
+    [[NCNetworking sharedInstance] readFileWithServerUrlFileName:self.serverUrl account:appDelegate.activeAccount completion:^(NSString *account, tableMetadata *metadata, NSInteger errorCode, NSString *errorDescription) {
+        
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
             // Rich Workspace
-            [[NCManageDatabase sharedInstance] setDirectoryWithOcId:file.ocId serverUrl:self.serverUrl richWorkspace:file.richWorkspace account:account];
-            self.richWorkspaceText = file.richWorkspace;
+            [[NCManageDatabase sharedInstance] setDirectoryWithOcId:metadata.ocId serverUrl:self.serverUrl richWorkspace:metadata.richWorkspace account:account];
+            self.richWorkspaceText = metadata.richWorkspace;
             [self setTableViewHeader];
             
             tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, self.serverUrl]];
             
             // Read folder: No record, Change etag or BLINK
-            if ([sectionDataSource.allRecordsDataSource count] == 0 || [file.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
+            if ([sectionDataSource.allRecordsDataSource count] == 0 || [metadata.etag isEqualToString:directory.etag] == NO || self.blinkFileNamePath != nil) {
                 [self readFolder:self.serverUrl];
             }
             
         } else if (errorCode != 0) {
-            [[NCContentPresenter shared] messageNotification:@"_error_" description:errorMessage delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
-        } else {
-            NSLog(@"[LOG] It has been changed user during networking process, error.");
+            [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
         }
     }];
 }

+ 16 - 0
iOSClient/Networking/NCNetworking.swift

@@ -258,6 +258,22 @@ import NCCommunication
         }
     }
     
+    @objc func readFile(serverUrlFileName: String, account: String, completion: @escaping (_ account: String, _ metadata: tableMetadata?, _ errorCode: Int, _ errorDescription: String)->()) {
+        
+        NCCommunication.sharedInstance.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles(), account: account) { (account, files, errorCode, errorDescription) in
+
+            if errorCode == 0 && files != nil {
+                
+                let metadata = NCNetworking.sharedInstance.convertFileToMetadata(files![0])
+                completion(account, metadata, errorCode, "")
+                
+            } else {
+
+                completion(account, nil, errorCode, errorDescription!)
+            }
+        }
+    }
+    
     @objc func deleteMetadata(_ metadata: tableMetadata, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
                 
         let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl))

+ 7 - 9
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -55,17 +55,15 @@ import MarkdownKit
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         
-        NCCommunication.sharedInstance.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles(), account: appDelegate.activeAccount) { (account, files, errorCode, errorMessage) in
+        NCNetworking.sharedInstance.readFile(serverUrlFileName: serverUrl, account: appDelegate.activeAccount) { (account, metadata, errorCode, errorDescription) in
             
-            if errorCode == 0 && account == self.appDelegate.activeAccount && files != nil {
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
                 
-                if let file = files?[0] {
-                    NCManageDatabase.sharedInstance.setDirectory(ocId: file.ocId, serverUrl: self.serverUrl, richWorkspace: file.richWorkspace, account: account)
-                    if self.richWorkspaceText != file.richWorkspace {
-                        self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
-                        self.richWorkspaceText = file.richWorkspace
-                        self.textView.attributedText = self.markdownParser.parse(file.richWorkspace)
-                    }
+                NCManageDatabase.sharedInstance.setDirectory(ocId: metadata!.ocId, serverUrl: self.serverUrl, richWorkspace: metadata!.richWorkspace, account: account)
+                if self.richWorkspaceText != metadata?.richWorkspace {
+                    self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
+                    self.richWorkspaceText = metadata!.richWorkspace
+                    self.textView.attributedText = self.markdownParser.parse(metadata!.richWorkspace)
                 }
             }
         }

+ 4 - 4
iOSClient/Shares/NCShares.m

@@ -296,14 +296,14 @@
         
         NSString *serverUrlFileName = [NSString stringWithFormat:@"%@/%@", table.serverUrl, table.fileName];
                
-        [[NCCommunication sharedInstance] readFileOrFolderWithServerUrlFileName:serverUrlFileName depth:@"0" showHiddenFiles:[CCUtility getShowHiddenFiles] account:appDelegate.activeAccount completionHandler:^(NSString *account, NSArray*files, NSInteger errorCode, NSString *errorDescription) {        
-            if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount] && files != nil) {
-                tableMetadata *metadata = [[NCNetworking sharedInstance] convertFileToMetadata:files[0]];
+        [[NCNetworking sharedInstance] readFileWithServerUrlFileName:serverUrlFileName account:appDelegate.activeAccount completion:^(NSString *account, tableMetadata *metadata, NSInteger errorCode, NSString *errorDescription) {
+            
+            if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
                 metadata.fileName = table.fileName;
                 metadata.fileNameView = table.fileName;
                 [[NCManageDatabase sharedInstance] addMetadata:metadata];
                 [self reloadDatasource];
-            } 
+            }
         }];
     }
     

+ 5 - 6
iOSClient/Synchronize/CCSynchronize.m

@@ -211,9 +211,9 @@
 {
     NSString *serverUrlFileName = [NSString stringWithFormat:@"%@/%@", serverUrl, fileName];
 
-    [[NCCommunication sharedInstance] readFileOrFolderWithServerUrlFileName:serverUrlFileName depth:@"0" showHiddenFiles:[CCUtility getShowHiddenFiles] account:account completionHandler:^(NSString *account, NSArray*files, NSInteger errorCode, NSString *errorMessage) {
-                
-        if (errorCode == 0 && [account isEqualToString:account] && files != nil) {
+    [[NCNetworking sharedInstance] readFileWithServerUrlFileName:serverUrlFileName account:account completion:^(NSString *account, tableMetadata *metadata, NSInteger errorCode, NSString *errorDescription) {
+        
+        if (errorCode == 0 && [account isEqualToString:account]) {
             
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                 
@@ -223,17 +223,16 @@
                     withDownload = YES;
                 
                 //Add/Update Metadata
-                tableMetadata *metadata = [[NCNetworking sharedInstance] convertFileToMetadata:files[0]];
                 tableMetadata *addMetadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
                 if (addMetadata)
                     [self verifyChangeMedatas:[[NSArray alloc] initWithObjects:addMetadata, nil] serverUrl:serverUrl account:account withDownload:withDownload];
             });
             
         } else if (errorCode == kOCErrorServerPathNotFound) {
-            
+                
             [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
             [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
-            
+                
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl ocId:nil action:k_action_NULL];
         }
     }];