Эх сурвалжийг харах

fix activity

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
43a1067492

+ 19 - 44
iOSClient/Activity/NCActivityTableViewCell.swift

@@ -140,54 +140,29 @@ extension NCActivityTableViewCell: UICollectionViewDelegate {
                 }
             }
 
-            var pathComponents = activityPreview.link.components(separatedBy: "?")
-            pathComponents = pathComponents[1].components(separatedBy: "&")
-            var serverUrlFileName = pathComponents[0].replacingOccurrences(of: "dir=", with: "").removingPercentEncoding!
-            serverUrlFileName = NCUtilityFileSystem.shared.getHomeServer(account: activityPreview.account) + serverUrlFileName + "/" + activitySubjectRich.name
-            let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(activitySubjectRich.id, fileNameView: activitySubjectRich.name)!
-
-            if let backgroundView = appDelegate.window?.rootViewController?.view {
-                NCActivityIndicator.shared.start(backgroundView: backgroundView)
-            }
-
-            NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in
-
-            }, taskHandler: { _ in
-
-            }, progressHandler: { _ in
-
-            }) { account, _, _, _, _, _, error in
-
-                if account == self.appDelegate.account && error == .success {
-
-                    let serverUrl = (serverUrlFileName as NSString).deletingLastPathComponent
-                    let fileName = (serverUrlFileName as NSString).lastPathComponent
-                    let serverUrlFileName = serverUrl + "/" + fileName
-
-                    NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName) { account, metadata, error in
-
+            NCActivityIndicator.shared.start()
+            NextcloudKit.shared.getFileFromFileId(nil, link: activityPreview.link) { account, file, data, error in
+                if let file = file {
+                    
+                    let metadata = NCManageDatabase.shared.convertNCFileToMetadata(file, isEncrypted: file.e2eEncrypted, account: account)
+                    NCManageDatabase.shared.addMetadata(metadata)
+
+                    let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
+                    let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+
+                    NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in
+                    }, taskHandler: { _ in
+                    }, progressHandler: { _ in
+                    }) { account, _, _, _, _, _, error in
                         NCActivityIndicator.shared.stop()
-
-                        DispatchQueue.main.async {
-                            if account == self.appDelegate.account, error == .success, let metadata = metadata {
-
-                                // move from id to oc:id + instanceid (ocId)
-                                let atPath = CCUtility.getDirectoryProviderStorage()! + "/" + activitySubjectRich.id
-                                let toPath = CCUtility.getDirectoryProviderStorage()! + "/" + metadata.ocId
-
-                                CCUtility.moveFile(atPath: atPath, toPath: toPath)
-
-                                NCManageDatabase.shared.addMetadata(metadata)
-                                if let viewController = self.viewController {
-                                    NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: cell?.imageView.image)
-                                }
+                        if account == self.appDelegate.account && error == .success {
+                            if let viewController = self.viewController {
+                                NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: cell?.imageView.image)
                             }
                         }
                     }
-
-                } else {
-
-                    NCActivityIndicator.shared.stop()
+                } else if error != .success {
+                    NCContentPresenter.shared.showError(error: error)
                 }
             }
         }

+ 1 - 1
iOSClient/Utility/NCActivityIndicator.swift

@@ -38,7 +38,7 @@ class NCActivityIndicator: NSObject {
         start(backgroundView: backgroundView, style: style)
     }
 
-    func start(backgroundView: UIView? = nil, bottom: CGFloat? = nil, top: CGFloat? = nil, style: UIActivityIndicatorView.Style = .whiteLarge) {
+    func start(backgroundView: UIView? = nil, bottom: CGFloat? = nil, top: CGFloat? = nil, style: UIActivityIndicatorView.Style = .large) {
 
         if self.activityIndicator != nil { stop() }