marinofaggiana 5 лет назад
Родитель
Сommit
009bb44e00

+ 1 - 1
iOSClient/Favorites/CCFavorites.m

@@ -409,7 +409,7 @@
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-        [[NCNetworking sharedInstance] deleteMetadata:metadata completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+        [[NCNetworking sharedInstance] deleteMetadata:metadata user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
     }]];
     
    

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -1447,7 +1447,7 @@
     _dateReadDataSource = nil;
     
     for (tableMetadata *metadata in metadatas) {
-        [[NCNetworking sharedInstance] deleteMetadata:metadata completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+        [[NCNetworking sharedInstance] deleteMetadata:metadata user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
     }
 
     // End Select Table View

+ 1 - 1
iOSClient/Main/Menu/NCDetailNavigationController+Menu.swift

@@ -57,7 +57,7 @@ extension NCDetailNavigationController {
                     let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
                     
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
-                        NCNetworking.sharedInstance.deleteMetadata(metadata) { (errorCode, errorDescription) in }
+                        NCNetworking.sharedInstance.deleteMetadata(metadata, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl) { (errorCode, errorDescription) in }
                     })
                     
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })

+ 1 - 1
iOSClient/Media/NCMedia.swift

@@ -577,7 +577,7 @@ extension NCMedia {
                 
         for ocId in selectocId {
             if let metadata = NCManageDatabase.sharedInstance.getMedia(predicate: NSPredicate(format: "ocId == %@", ocId)) {
-                NCNetworking.sharedInstance.deleteMetadata(metadata) { (errorCode, errorDescription) in }
+                NCNetworking.sharedInstance.deleteMetadata(metadata, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
             }
         }
     }

+ 38 - 3
iOSClient/Networking/NCNetworking.swift

@@ -247,7 +247,20 @@ import NCCommunication
     
     //MARK: - WebDav
     
-    @objc func deleteMetadata(_ metadata: tableMetadata, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
+    @objc func deleteMetadata(_ metadata: tableMetadata, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
+        
+        if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
+            if directory.e2eEncrypted {
+                self.deleteMetadataE2EE(metadata, directory: directory, user: user, userID: userID, password: password, url: url, completion: completion)
+            } else {
+                self.deleteMetadataPlain(metadata, completion: completion)
+            }
+        } else {
+            completion(Int(k_CCErrorInternalError), "Internal Error")
+        }
+    }
+    
+    @objc func deleteMetadataPlain(_ metadata: tableMetadata, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
         
         // verify permission
         let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_delete)
@@ -286,8 +299,30 @@ import NCCommunication
         }
     }
     
-    @objc func deleteMetadataE2EE(_ metadata: tableMetadata, directory: tableDirectory, user: String, userID: String, password: String, url: String,completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
+    @objc func deleteMetadataE2EE(_ metadata: tableMetadata, directory: tableDirectory, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
                         
-        let error = NCNetworkingEndToEnd.sharedManager()?.lockFolderEncrypted(onServerUrl: directory.serverUrl, ocId: directory.ocId, user: user, userID: userID, password: password, url: url)
+        DispatchQueue.global().async {
+            if let error = NCNetworkingEndToEnd.sharedManager().lockFolderEncrypted(onServerUrl: directory.serverUrl, ocId: directory.ocId, user: user, userID: userID, password: password, url: url) {
+                DispatchQueue.main.async {
+                    NCContentPresenter.shared.messageNotification("_delete_", description: error.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                    completion(Int(k_CCErrorInternalError), error.localizedDescription)
+                    return
+                }
+            }
+        }
+        
+        self.deleteMetadataPlain(metadata) { (errorCode, errorDescription) in
+            
+            if errorCode == 0 {
+                NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameIdentifier == %@", metadata.account, directory.serverUrl, metadata.fileName))
+            }
+            
+            DispatchQueue.global().async {
+                NCNetworkingEndToEnd.sharedManager().rebuildAndSendMetadata(onServerUrl: directory.serverUrl, account: self.account, user: user, userID: userID, password: password, url: url)
+                DispatchQueue.main.async {
+                    completion(errorCode, errorDescription)
+                }
+            }
+        }
     }
 }

+ 1 - 1
iOSClient/Offline/NCOffline.swift

@@ -774,7 +774,7 @@ extension NCOffline {
         
         actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
             if item is DestructiveButton  {
-                NCNetworking.sharedInstance.deleteMetadata(metadata) { (errorCode, errorDescription) in }
+                NCNetworking.sharedInstance.deleteMetadata(metadata, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl) { (errorCode, errorDescription) in }
             }
             if item is CancelButton { print("Cancel buttons has the value `true`") }
         })