浏览代码

improved code

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 年之前
父节点
当前提交
3672b13be0

+ 1 - 0
Share/NCShareExtension+Files.swift

@@ -57,6 +57,7 @@ extension NCShareExtension {
     }
     }
 
 
     @objc func didCreateFolder(_ notification: NSNotification) {
     @objc func didCreateFolder(_ notification: NSNotification) {
+        
         guard let userInfo = notification.userInfo as NSDictionary?,
         guard let userInfo = notification.userInfo as NSDictionary?,
               let ocId = userInfo["ocId"] as? String,
               let ocId = userInfo["ocId"] as? String,
               let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
               let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)

+ 5 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -430,9 +430,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
 
         guard let userInfo = notification.userInfo as NSDictionary?,
         guard let userInfo = notification.userInfo as NSDictionary?,
               let ocId = userInfo["ocId"] as? String,
               let ocId = userInfo["ocId"] as? String,
-              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId),
-              metadata.serverUrl == serverUrl,
-              metadata.account == appDelegate.account
+              let serverUrl = userInfo["serverUrl"] as? String,
+              serverUrl == self.serverUrl,
+              let account = userInfo["account"] as? String,
+              account == appDelegate.account,
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
         else { return }
         else { return }
 
 
         pushMetadata(metadata)
         pushMetadata(metadata)

+ 1 - 1
iOSClient/NCGlobal.swift

@@ -347,7 +347,7 @@ class NCGlobal: NSObject {
 
 
     let notificationCenterProgressTask                          = "progressTask"                    // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
     let notificationCenterProgressTask                          = "progressTask"                    // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
 
 
-    let notificationCenterCreateFolder                          = "createFolder"                    // userInfo: ocId
+    let notificationCenterCreateFolder                          = "createFolder"                    // userInfo: ocId, serverUrl, account
     let notificationCenterDeleteFile                            = "deleteFile"                      // userInfo: ocId, fileNameView, serverUrl, account, classFile, onlyLocalCache
     let notificationCenterDeleteFile                            = "deleteFile"                      // userInfo: ocId, fileNameView, serverUrl, account, classFile, onlyLocalCache
     let notificationCenterRenameFile                            = "renameFile"                      // userInfo: ocId, errorCode, errorDescription
     let notificationCenterRenameFile                            = "renameFile"                      // userInfo: ocId, errorCode, errorDescription
     let notificationCenterMoveFile                              = "moveFile"                        // userInfo: ocId, serverUrlFrom
     let notificationCenterMoveFile                              = "moveFile"                        // userInfo: ocId, serverUrlFrom

+ 1 - 1
iOSClient/Networking/NCNetworking.swift

@@ -991,7 +991,7 @@ import Photos
                         NCManageDatabase.shared.addDirectory(encrypted: metadata.e2eEncrypted, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: nil, permissions: metadata.permissions, serverUrl: fileNameFolderUrl, account: account)
                         NCManageDatabase.shared.addDirectory(encrypted: metadata.e2eEncrypted, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: nil, permissions: metadata.permissions, serverUrl: fileNameFolderUrl, account: account)
                     }
                     }
                     if let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadataFolder?.ocId) {
                     if let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadataFolder?.ocId) {
-                        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterCreateFolder, userInfo: ["ocId": metadata.ocId])
+                        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterCreateFolder, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
                     }
                     }
                 }
                 }
                 completion(errorCode, errorDescription)
                 completion(errorCode, errorDescription)

+ 8 - 7
iOSClient/Select/NCSelect.swift

@@ -213,13 +213,14 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
 
 
     @objc func createFolder(_ notification: NSNotification) {
     @objc func createFolder(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-                if metadata.serverUrl == serverUrl {
-                    pushMetadata(metadata)
-                }
-            }
-        }
+        guard let userInfo = notification.userInfo as NSDictionary?,
+              let ocId = userInfo["ocId"] as? String,
+              let serverUrl = userInfo["serverUrl"] as? String,
+              serverUrl == self.serverUrl,
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
+        else { return }
+
+        pushMetadata(metadata)
     }
     }
 
 
     // MARK: - Empty
     // MARK: - Empty

+ 6 - 7
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -117,14 +117,13 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
 
 
     @objc func favoriteFile(_ notification: NSNotification) {
     @objc func favoriteFile(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+        guard let userInfo = notification.userInfo as NSDictionary?,
+              let ocId = userInfo["ocId"] as? String,
+              ocId == self.metadata.ocId,
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
+        else { return }
 
 
-                if metadata.ocId == self.metadata.ocId {
-                    self.metadata = metadata
-                }
-            }
-        }
+        self.metadata = metadata
     }
     }
 
 
     @objc func keyboardDidShow(notification: Notification) {
     @objc func keyboardDidShow(notification: Notification) {

+ 6 - 7
iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift

@@ -124,14 +124,13 @@ class NCViewerRichdocument: UIViewController, WKNavigationDelegate, WKScriptMess
 
 
     @objc func favoriteFile(_ notification: NSNotification) {
     @objc func favoriteFile(_ notification: NSNotification) {
 
 
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+        guard let userInfo = notification.userInfo as NSDictionary?,
+              let ocId = userInfo["ocId"] as? String,
+              ocId == self.metadata.ocId,
+              let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
+        else { return }
 
 
-                if metadata.ocId == self.metadata.ocId {
-                    self.metadata = metadata
-                }
-            }
-        }
+        self.metadata = metadata
     }
     }
 
 
     @objc func keyboardDidShow(notification: Notification) {
     @objc func keyboardDidShow(notification: Notification) {