marinofaggiana 4 年之前
父节点
当前提交
bf3405367b

+ 4 - 9
iOSClient/Database/NCManageDatabase.swift

@@ -2495,7 +2495,7 @@ class NCManageDatabase: NSObject {
     //MARK: -
     //MARK: Table Share
     
-    @objc func addShare(account: String, activeUrl: String, shares: [NCCommunicationShare]) -> [tableShare] {
+    @objc func addShare(account: String, activeUrl: String, shares: [NCCommunicationShare]) {
         
         let realm = try! Realm()
         realm.beginWrite()
@@ -2503,13 +2503,10 @@ class NCManageDatabase: NSObject {
         for share in shares {
             
             let addObject = tableShare()
-            let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + "/" + share.path
+            let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + share.path
+            let serverUrl = CCUtility.deletingLastPathComponent(fromServerUrl: fullPath)!
             let fileName = NSString(string: fullPath).lastPathComponent
-            var serverUrl = NSString(string: fullPath).substring(to: (fullPath.count - fileName.count - 1))
-            if serverUrl.hasSuffix("/") {
-                serverUrl = NSString(string: serverUrl).substring(to: (serverUrl.count - 1))
-            }
-            
+                        
             addObject.account = account
             addObject.fileName = fileName
             addObject.serverUrl = serverUrl
@@ -2554,8 +2551,6 @@ class NCManageDatabase: NSObject {
         } catch let error {
             print("[LOG] Could not write to database: ", error)
         }
-        
-        return self.getTableShares(account: account)
     }
     
     @objc func getTableShares(account: String) -> [tableShare] {

+ 3 - 4
iOSClient/Main/CCMain.m

@@ -274,10 +274,6 @@
     }
 
     if (appDelegate.activeAccount.length > 0 && self.serverUrl != nil) {
-        
-        // Get Shares
-        appDelegate.shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount serverUrl:self.serverUrl];
-        
         // Get RichWorkspace
         tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
         self.richWorkspaceText = directory.richWorkspace;
@@ -1986,6 +1982,9 @@
     if ([serverUrl isEqualToString:self.serverUrl] == NO || self.serverUrl == nil)
         return;
     
+    // load share
+    appDelegate.shares = [[NCManageDatabase sharedInstance] getTableSharesWithAccount:appDelegate.activeAccount];
+    
     // Search Mode
     if (self.searchController.isActive) {
         

+ 2 - 3
iOSClient/Networking/NCService.swift

@@ -160,14 +160,13 @@ class NCService: NSObject {
                 // File Sharing
                 let isFilesSharingEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
                 if (isFilesSharingEnabled && self.appDelegate.activeMain != nil) {
-                    
                     NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
                         if errorCode == 0 {
                             NCManageDatabase.sharedInstance.deleteTableShare(account: account)
                             if shares != nil {
-//                                self.appDelegate.shares
-                                _ = NCManageDatabase.sharedInstance.addShare(account: account, activeUrl: self.appDelegate.activeUrl, shares: shares!)
+                                NCManageDatabase.sharedInstance.addShare(account: account, activeUrl: self.appDelegate.activeUrl, shares: shares!)
                             }
+                            self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: account)
                         } else {
                             NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                         }

+ 12 - 25
iOSClient/Share/NCShareNetworking.swift

@@ -46,7 +46,8 @@ class NCShareNetworking: NSObject {
         NCCommunication.shared.readShares(path: CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl)) { (account, shares, errorCode, errorDescription) in
             NCUtility.sharedInstance.stopActivityIndicator()
              if errorCode == 0 && shares != nil {
-                self.appDelegate.shares = NCManageDatabase.sharedInstance.addShare(account: self.metadata.account, activeUrl: self.activeUrl, shares: shares!)
+                NCManageDatabase.sharedInstance.addShare(account: self.metadata.account, activeUrl: self.activeUrl, shares: shares!)
+                self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: self.metadata.account)
                 self.appDelegate.activeMain?.tableView?.reloadData()
                 self.appDelegate.activeFavorites?.tableView?.reloadData()
             } else {
@@ -59,31 +60,17 @@ class NCShareNetworking: NSObject {
     func shareLink(password: String?) {
         NCUtility.sharedInstance.startActivityIndicator(view: view)
         let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl)!
-        NCCommunication.shared.createShareLink(path: filenamePath, password: password) { (account, sharee, errorCode, errorDescription) in
-            
-        }
-        
-        /*
-        OCNetworking.sharedManager()?.share(withAccount: metadata.account, fileName: fileName, password: password, permission: permission, hideDownload: hideDownload, completion: { (account, message, errorCode) in
-            if errorCode == 0 {
-                OCNetworking.sharedManager()?.readShare(withAccount: account, path: CCUtility.returnFileNamePath(fromFileName: self.metadata.fileName, serverUrl: self.metadata.serverUrl, activeUrl: self.activeUrl), completion: { (account, items, message, errorCode) in
-                    NCUtility.sharedInstance.stopActivityIndicator()
-                    if errorCode == 0 {
-                        let itemsOCSharedDto = items as! [OCSharedDto]
-                        self.appDelegate.shares = NCManageDatabase.sharedInstance.addShare(account: self.metadata.account, activeUrl: self.activeUrl, items: itemsOCSharedDto)
-                        self.appDelegate.activeMain?.tableView?.reloadData()
-                        self.appDelegate.activeFavorites?.tableView?.reloadData()
-                    } else {
-                        NCContentPresenter.shared.messageNotification("_share_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: 0)
-                    }
-                    self.delegate?.shareCompleted()
-                })
-            } else {
-                NCUtility.sharedInstance.stopActivityIndicator()
-                NCContentPresenter.shared.messageNotification("_share_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: 0)
+        NCCommunication.shared.createShareLink(path: filenamePath, password: password) { (account, share, errorCode, errorDescription) in
+            NCUtility.sharedInstance.stopActivityIndicator()
+            if errorCode == 0 && share != nil{
+                NCManageDatabase.sharedInstance.addShare(account: self.metadata.account, activeUrl: self.activeUrl, shares: [share!])
+                self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: self.metadata.account)
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["serverUrl":self.metadata.serverUrl])
+            } else if errorCode != 0 {
+                NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: 0)
             }
-        })
-        */
+            self.delegate?.shareCompleted()
+        }
     }
     
     func unShare(idShare: Int) {