Bläddra i källkod

cleaning code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 år sedan
förälder
incheckning
2d1c83968d

+ 2 - 2
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -235,7 +235,7 @@ extension tableMetadata {
         NCUtility.shared.isDirectoryE2EE(account: account, urlBase: urlBase, userId: userId, serverUrl: serverUrl)
     }
 
-    var isDirectoryTopE2EE: Bool {
+    var isDirectoryE2EETop: Bool {
         NCUtility.shared.isDirectoryE2EETop(account: account, serverUrl: serverUrl)
     }
 
@@ -249,7 +249,7 @@ extension tableMetadata {
         guard NCGlobal.shared.capabilityFileSharingApiEnabled else { return false }
 
         if NCGlobal.shared.capabilityE2EEApiVersion == NCGlobal.shared.e2eeVersionV20, isDirectoryE2EE {
-            return !isDirectoryTopE2EE
+            return !isDirectoryE2EETop
         } else if !e2eEncrypted && !isDirectoryE2EE {
             return true
         } else if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion26 && directory {

+ 6 - 6
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1445,6 +1445,12 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
 
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return cell }
 
+        defer {
+            if appDelegate.disableSharesView || !metadata.isSharable() {
+                cell.hideButtonShare(true)
+            }
+        }
+
         var isShare = false
         var isMounted = false
         var a11yValues: [String] = []
@@ -1658,12 +1664,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             cell.hideButtonMore(true)
         }
 
-        // ** IMPORT MUST BE AT THE END **
-        // Disable Share Button
-        if appDelegate.disableSharesView || !metadata.isSharable() {
-            cell.hideButtonShare(true)
-        }
-
         return cell
     }
 

+ 2 - 5
iOSClient/Networking/E2EE/NCNetworkingE2EERename.swift

@@ -32,9 +32,6 @@ class NCNetworkingE2EERename: NSObject {
         return instance
     }()
 
-    let errorEncodeMetadata = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: NSLocalizedString("_e2e_error_encode_metadata_", comment: ""))
-    let fileAlreadyExists = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_file_already_exists_")
-
     func rename(metadata: tableMetadata, fileNameNew: String, indexPath: IndexPath) async -> (NKError) {
 
         var error = NKError()
@@ -44,7 +41,7 @@ class NCNetworkingE2EERename: NSObject {
             // Get last metadata
             let results = await NextcloudKit.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken)
             guard results.error == .success, let e2eMetadata = results.e2eMetadata else {
-                return errorEncodeMetadata
+                return results.error
             }
 
             error = NCEndToEndMetadata().decodeMetadata(e2eMetadata, signature: results.signature, serverUrl: metadata.serverUrl, account: metadata.account, urlBase: metadata.urlBase, userId: metadata.userId, ownerId: metadata.ownerId)
@@ -63,7 +60,7 @@ class NCNetworkingE2EERename: NSObject {
 
         // verify if exists the new fileName
         if NCManageDatabase.shared.getE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, fileNameNew)) != nil {
-            return fileAlreadyExists
+            return NKError(errorCode: NCGlobal.shared.errorUnexpectedResponseFromDB, errorDescription: "_file_already_exists_")
         }
 
         // ** Lock **

+ 15 - 12
iOSClient/Utility/NCUtility.swift

@@ -773,20 +773,23 @@ class NCUtility: NSObject {
     }
 
     func getDirectoryE2EETop(serverUrl: String, account: String) -> tableDirectory? {
+
         var serverUrl = serverUrl
-        var top = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl)
-        while true {
-            if let url = URL(string: serverUrl)?.deletingLastPathComponent() {
-                serverUrl = String(url.absoluteString.dropLast())
-                if let directory = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl) {
-                    if directory.e2eEncrypted {
-                        top = directory
-                    } else {
-                        return top
-                    }
-                } else { return top }
-            } else { return top }
+        var top: tableDirectory?
+
+        while let url = URL(string: serverUrl)?.deletingLastPathComponent(),
+              let directory = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl) {
+
+            if directory.e2eEncrypted {
+                top = directory
+            } else {
+                return top
+            }
+
+            serverUrl = String(url.absoluteString.dropLast())
         }
+
+        return top
     }
 
     func createViewImageAndText(image: UIImage, title: String? = nil) -> UIView {