Marino Faggiana il y a 2 ans
Parent
commit
52f5374383

+ 10 - 7
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -353,15 +353,17 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     @objc func deleteFile(_ notification: NSNotification) {
 
         guard let userInfo = notification.userInfo as NSDictionary?,
-              let ocId = userInfo["ocId"] as? String,
-              let fileNameView = userInfo["fileNameView"] as? String,
-              let serverUrl = userInfo["serverUrl"] as? String,
-              serverUrl == self.serverUrl,
-              let account = userInfo["account"] as? String,
-              account == appDelegate.account,
-              let onlyLocalCache = userInfo["onlyLocalCache"] as? Bool
+              let ocId = userInfo["ocId"] as? [String],
+              let error = userInfo["error"] as? NKError
         else { return }
 
+        if error == .success {
+            
+        } else {
+
+        }
+        
+        /*
         if fileNameView.lowercased() == NCGlobal.shared.fileNameRichWorkspace.lowercased() {
             reloadDataSourceNetwork(forced: true)
         } else if onlyLocalCache {
@@ -380,6 +382,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 reloadDataSource()
             }
         }
+        */
     }
 
     @objc func moveFile(_ notification: NSNotification) {

+ 10 - 4
iOSClient/Menu/NCContextMenu.swift

@@ -154,11 +154,14 @@ class NCContextMenu: NSObject {
             let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .destructive) { _ in
                 Task {
+                    var ocId: [String] = []
                     let error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: false)
-                    if error != .success {
+                    if error == .success {
+                        ocId.append(metadata.ocId)
+                    } else {
                         NCContentPresenter.shared.showError(error: error)
                     }
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": [metadata.ocId], "error": error])
+                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
                 }
             })
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in })
@@ -168,11 +171,14 @@ class NCContextMenu: NSObject {
         let deleteConfirmLocal = UIAction(title: NSLocalizedString("_remove_local_file_", comment: ""),
                                           image: UIImage(systemName: "trash"), attributes: .destructive) { _ in
             Task {
+                var ocId: [String] = []
                 let error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: true)
-                if error != .success {
+                if error == .success {
+                    ocId.append(metadata.ocId)
+                } else {
                     NCContentPresenter.shared.showError(error: error)
                 }
-                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": [metadata.ocId], "error": error])
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
             }
         }
 

+ 8 - 2
iOSClient/Menu/NCMenuAction.swift

@@ -138,13 +138,16 @@ extension NCMenuAction {
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
                         Task {
                             var error = NKError()
+                            var ocId: [String] = []
                             for metadata in selectedMetadatas where error == .success {
                                 error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: false)
+                                if error == .success {
+                                    ocId.append(metadata.ocId)
+                                }
                             }
                             if error != .success {
                                 NCContentPresenter.shared.showError(error: error)
                             }
-                            let ocId = selectedMetadatas.map { $0.ocId }
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
                         }
                         completion?()
@@ -156,13 +159,16 @@ extension NCMenuAction {
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
                         Task {
                             var error = NKError()
+                            var ocId: [String] = []
                             for metadata in selectedMetadatas where error == .success {
                                 error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: true)
+                                if error == .success {
+                                    ocId.append(metadata.ocId)
+                                }
                             }
                             if error != .success {
                                 NCContentPresenter.shared.showError(error: error)
                             }
-                            let ocId = selectedMetadatas.map { $0.ocId }
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "error": error])
                         }
                         completion?()

+ 2 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -365,12 +365,11 @@ class NCViewerMediaPage: UIViewController {
     @objc func deleteFile(_ notification: NSNotification) {
 
         guard let userInfo = notification.userInfo as NSDictionary?,
-              let ocIds = userInfo["ocId"] as? [String],
-              let ocId = ocIds.first,
+              let ocId = userInfo["ocId"] as? [String],
               let error = userInfo["error"] as? NKError
         else { return }
 
-        if error == .success {
+        if error == .success, let ocId = ocId.first {
             // Stop media
             if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
                 ncplayer.playerPause()

+ 2 - 1
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -336,10 +336,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     @objc func deleteFile(_ notification: NSNotification) {
 
         guard let userInfo = notification.userInfo as NSDictionary?,
+              let ocId = userInfo["ocId"] as? [String],
               let error = userInfo["error"] as? NKError
         else { return }
 
-        if error == .success {
+        if error == .success, let ocId = ocId.first, metadata.ocId == ocId {
             viewUnload()
         }
     }