Browse Source

fix conflict e2ee

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
10ed12a28d

+ 1 - 0
Share/NCShareExtension.swift

@@ -329,6 +329,7 @@ extension NCShareExtension {
             conflict.serverUrl = self.serverUrl
             conflict.metadatasUploadInConflict = conflicts
             conflict.delegate = self
+            conflict.isE2EE = CCUtility.isFolderEncrypted(self.serverUrl, e2eEncrypted: false, account: activeAccount.account, urlBase: activeAccount.urlBase)
             self.present(conflict, animated: true, completion: nil)
         } else {
             upload()

+ 1 - 0
iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift

@@ -394,6 +394,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
                         conflict.metadatasNOConflict = metadatasNOConflict
                         conflict.metadatasUploadInConflict = metadatasUploadInConflict
                         conflict.delegate = self.appDelegate
+                        conflict.isE2EE = CCUtility.isFolderEncrypted(self.serverUrl, e2eEncrypted: false, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase)
 
                         self.appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
                     }

+ 16 - 11
iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift

@@ -57,6 +57,7 @@ extension NCCreateFormUploadConflictDelegate {
     @objc weak var delegate: NCCreateFormUploadConflictDelegate?
     @objc var alwaysNewFileNameNumber: Bool = false
     @objc var textLabelDetailNewFile: String?
+    @objc var isE2EE: Bool = false
 
     var metadatasConflictNewFiles: [String] = []
     var metadatasConflictAlreadyExistingFiles: [String] = []
@@ -148,15 +149,17 @@ extension NCCreateFormUploadConflictDelegate {
         let conflictAlert = UIAlertController(title: tile, message: "", preferredStyle: .alert)
 
         // REPLACE
-        conflictAlert.addAction(UIAlertAction(title: titleReplace, style: .default, handler: { action in
+        if !isE2EE {
+            conflictAlert.addAction(UIAlertAction(title: titleReplace, style: .default, handler: { action in
 
-            for metadata in self.metadatasUploadInConflict {
-                self.metadatasNOConflict.append(metadata)
-            }
-
-            self.buttonContinueTouch(action)
-        }))
+                for metadata in self.metadatasUploadInConflict {
+                    self.metadatasNOConflict.append(metadata)
+                }
 
+                self.buttonContinueTouch(action)
+            }))
+        }
+        
         // KEEP BOTH
         conflictAlert.addAction(UIAlertAction(title: titleKeep, style: .default, handler: { action in
 
@@ -174,10 +177,12 @@ extension NCCreateFormUploadConflictDelegate {
             }
         }))
 
-        conflictAlert.addAction(UIAlertAction(title: NSLocalizedString("_more_action_title_", comment: ""), style: .default, handler: { _ in
-            self.blurView.removeFromSuperview()
-        }))
-
+        if !isE2EE {
+            conflictAlert.addAction(UIAlertAction(title: NSLocalizedString("_more_action_title_", comment: ""), style: .default, handler: { _ in
+                self.blurView.removeFromSuperview()
+            }))
+        }
+        
         self.present(conflictAlert, animated: true, completion: nil)
     }
 

+ 10 - 8
iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift

@@ -272,14 +272,16 @@ import XLForm
 
                 let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: String(describing: fileNameForm), fileNameView: String(describing: fileNameForm), ocId: "", serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "")
 
-                guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
-                conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
-                conflictViewController.alwaysNewFileNameNumber = true
-                conflictViewController.serverUrl = serverUrl
-                conflictViewController.metadatasUploadInConflict = [metadataForUpload]
-                conflictViewController.delegate = self
-
-                self.present(conflictViewController, animated: true, completion: nil)
+                guard let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
+
+                conflict.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
+                conflict.alwaysNewFileNameNumber = true
+                conflict.serverUrl = serverUrl
+                conflict.metadatasUploadInConflict = [metadataForUpload]
+                conflict.delegate = self
+                conflict.isE2EE = CCUtility.isFolderEncrypted(serverUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
+
+                self.present(conflict, animated: true, completion: nil)
 
             } else {
 

+ 8 - 6
iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift

@@ -406,13 +406,15 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
 
         if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileName: fileNameSave) != nil {
 
-            guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
-            conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
-            conflictViewController.serverUrl = serverUrl
-            conflictViewController.metadatasUploadInConflict = [metadataForUpload]
-            conflictViewController.delegate = self
+            guard let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
 
-            self.present(conflictViewController, animated: true, completion: nil)
+            conflict.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
+            conflict.serverUrl = serverUrl
+            conflict.metadatasUploadInConflict = [metadataForUpload]
+            conflict.delegate = self
+            conflict.isE2EE = CCUtility.isFolderEncrypted(serverUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
+
+            self.present(conflict, animated: true, completion: nil)
 
         } else {
 

+ 9 - 7
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -233,13 +233,15 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
 
         if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileName: fileNameSave) != nil {
 
-            guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
-            conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
-            conflictViewController.serverUrl = serverUrl
-            conflictViewController.metadatasUploadInConflict = [metadataForUpload]
-            conflictViewController.delegate = self
-
-            self.present(conflictViewController, animated: true, completion: nil)
+            guard let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
+            
+            conflict.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
+            conflict.serverUrl = serverUrl
+            conflict.metadatasUploadInConflict = [metadataForUpload]
+            conflict.delegate = self
+            conflict.isE2EE = CCUtility.isFolderEncrypted(serverUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
+
+            self.present(conflict, animated: true, completion: nil)
 
         } else {
 

+ 2 - 0
iOSClient/Main/NCPickerViewController.swift

@@ -165,9 +165,11 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
                 if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileName: fileName) != nil {
 
                     if let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
+
                         conflict.delegate = appDelegate
                         conflict.serverUrl = serverUrl
                         conflict.metadatasUploadInConflict = [metadataForUpload]
+                        conflict.isE2EE = CCUtility.isFolderEncrypted(serverUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
 
                         appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
                     }

+ 9 - 6
iOSClient/Networking/NCNetworking.swift

@@ -399,13 +399,17 @@ import Photos
 
         if metadata.e2eEncrypted {
             #if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
-            NCNetworkingE2EE.shared.upload(metadata: metadata, start: start) { error in
-                completion(error)
+            DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
+                NCNetworkingE2EE.shared.upload(metadata: metadata, start: start) { error in
+                    completion(error)
+                }
             }
             #endif
         } else if metadata.chunk {
-            uploadChunkedFile(metadata: metadata, start: start) { error in
-                completion(error)
+            DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
+                self.uploadChunkedFile(metadata: metadata, start: start) { error in
+                    completion(error)
+                }
             }
         } else if metadata.session == NKCommon.shared.sessionIdentifierUpload {
             uploadFile(metadata: metadata, start: start) { error in
@@ -506,7 +510,6 @@ import Photos
                 return
             }
             let ocIdTemp = metadata.ocId
-            var errorDescription = error.errorDescription
             let selector = metadata.sessionSelector
 
             if error == .success, let ocId = ocId, size == metadata.size {
@@ -554,7 +557,7 @@ import Photos
 
                 } else {
                     
-                    NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
+                    NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: error.errorDescription, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusUploadError)
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
                 }
             }