浏览代码

new view share

marinofaggiana 5 年之前
父节点
当前提交
e4a4367ed0
共有 3 个文件被更改,包括 57 次插入43 次删除
  1. 5 41
      iOSClient/Database/NCManageDatabase.swift
  2. 1 1
      iOSClient/Main/CCMain.m
  3. 51 1
      iOSClient/Share/NCShare.swift

+ 5 - 41
iOSClient/Database/NCManageDatabase.swift

@@ -2328,7 +2328,7 @@ class NCManageDatabase: NSObject {
         return ["\(serverUrl)\(fileName)" : share]
     }
     
-    @objc func addShareV2(shareLink: String, shareUserAndGroup: String, fileName: String, serverUrl: String, account: String, sharedDto: OCSharedDto) {
+    @objc func addShareV2(fileName: String, serverUrl: String, account: String, sharedDto: OCSharedDto) {
         
         let realm = try! Realm()
 
@@ -2368,8 +2368,6 @@ class NCManageDatabase: NSObject {
 
         addObject.fileName = fileName
         addObject.serverUrl = serverUrl
-        addObject.shareLink = shareLink
-        addObject.shareUserAndGroup = shareUserAndGroup
         
         realm.add(addObject)
         
@@ -2452,43 +2450,11 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    @objc func updateShareV2(_ items: [String:OCSharedDto], activeUrl: String, account: String) {
+    @objc func updateShareV2(_ items: [OCSharedDto], activeUrl: String, account: String) {
         
         self.removeShareActiveAccount(account: account)
         
-        var itemsLink = [OCSharedDto]()
-        var itemsUsersAndGroups = [OCSharedDto]()
-        
-        for (_, itemOCSharedDto) in items {
-            
-            if (itemOCSharedDto.shareType == Int(shareTypeLink.rawValue)) {
-                itemsLink.append(itemOCSharedDto)
-            }
-            
-            if (itemOCSharedDto.shareWith.count > 0 && (itemOCSharedDto.shareType == Int(shareTypeUser.rawValue) || itemOCSharedDto.shareType == Int(shareTypeGroup.rawValue) || itemOCSharedDto.shareType == Int(shareTypeRemote.rawValue)  )) {
-                itemsUsersAndGroups.append(itemOCSharedDto)
-            }
-        }
-        
-        // Manage sharesLink
-        
-        for itemOCSharedDto in itemsLink {
-            
-            let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + "\(itemOCSharedDto.path!)"
-            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))
-            }
-            
-            if itemOCSharedDto.idRemoteShared > 0 {
-                _ = self.addShareV2(shareLink: "\(itemOCSharedDto.idRemoteShared)", shareUserAndGroup: "", fileName: fileName, serverUrl: serverUrl, account: account, sharedDto: itemOCSharedDto)
-            }
-        }
-        
-        // Manage sharesUserAndGroup
-        
-        for itemOCSharedDto in itemsUsersAndGroups {
+        for itemOCSharedDto in items {
             
             let fullPath = CCUtility.getHomeServerUrlActiveUrl(activeUrl) + "\(itemOCSharedDto.path!)"
             let fileName = NSString(string: fullPath).lastPathComponent
@@ -2496,10 +2462,8 @@ class NCManageDatabase: NSObject {
             if serverUrl.hasSuffix("/") {
                 serverUrl = NSString(string: serverUrl).substring(to: (serverUrl.count - 1))
             }
-            
-            if itemOCSharedDto.idRemoteShared > 0 {
-                _ = self.addShareV2(shareLink: "", shareUserAndGroup: "\(itemOCSharedDto.idRemoteShared)", fileName: fileName, serverUrl: serverUrl, account: account, sharedDto: itemOCSharedDto)
-            }
+                
+            addShareV2(fileName: fileName, serverUrl: serverUrl, account: account, sharedDto: itemOCSharedDto)
         }
     }
     

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -1919,7 +1919,7 @@
                 [appDelegate.sharesID setObject:item forKey:[@(item.idRemoteShared) stringValue]];
             
 #ifdef DEBUG
-            [[NCManageDatabase sharedInstance] updateShareV2:appDelegate.sharesID activeUrl:appDelegate.activeUrl account:appDelegate.activeAccount];
+            [[NCManageDatabase sharedInstance] updateShareV2:items activeUrl:appDelegate.activeUrl account:account];
 #else
             NSArray *result = [[NCManageDatabase sharedInstance] updateShare:appDelegate.sharesID activeUrl:appDelegate.activeUrl account:appDelegate.activeAccount];
             if (result) {

+ 51 - 1
iOSClient/Share/NCShare.swift

@@ -411,9 +411,12 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
     @IBOutlet weak var buttonAddAnotherLink: UIButton!
     @IBOutlet weak var labelAddAnotherLink: UILabel!
     
+    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+
     public let width: CGFloat = 250
     public let height: CGFloat = 470
     public var tableShare: tableShare?
+    public var metadata: tableMetadata?
     public var viewWindow: UIView?
     
     override func awakeFromNib() {
@@ -504,10 +507,57 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
             textViewNoteToRecipient.text = ""
         }
     }
+    
+    func readShareNetwork() {
+        OCNetworking.sharedManager()?.readShare(withAccount: metadata!.account, completion: { (account, items, message, errorCode) in
+            if errorCode == 0 {
+                let itemsOCSharedDto = items as! [OCSharedDto]
+                NCManageDatabase.sharedInstance.updateShareV2(itemsOCSharedDto, activeUrl: self.appDelegate.activeUrl, account: account!)
+                for item in itemsOCSharedDto {
+                    if self.tableShare!.idRemoteShared == item.idRemoteShared {
+                    }
+                }
+            } else {
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+            }
+            
+            
+        })
+    }
+    
+    func shareNetwork(password: String, permission: Int, hideDownload: Bool) {
+        let fileName = CCUtility.returnFileNamePath(fromFileName: metadata!.fileName, serverUrl: metadata!.serverUrl, activeUrl: appDelegate.activeUrl)!
+        OCNetworking.sharedManager()?.share(withAccount: metadata!.account, fileName: fileName, password: password, permission: permission, hideDownload: hideDownload, completion: { (account, message, errorCode) in
+            if errorCode == 0 {
+            } else {
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+            }
+        })
+    }
+    
+    func unShareNetwork() {
+        OCNetworking.sharedManager()?.unshareAccount(metadata!.account, shareID: tableShare!.idRemoteShared, completion: { (account, message, errorCode) in
+            if errorCode == 0 {
+                
+            } else {
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+            }
+        })
+    }
+    
+    func updateShareNetwork(password: String?, permission: Int, expirationTime: String?, hideDownload: Bool) {
+        OCNetworking.sharedManager()?.shareUpdateAccount(metadata!.account, shareID: tableShare!.idRemoteShared, password: password, permission: permission, expirationTime: expirationTime, hideDownload: hideDownload, completion: { (account, message, errorCode) in
+            if errorCode == 0 {
+                
+            } else {
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+            }
+        })
+    }
 }
 
 // --------------------------------------------------------------------------------------------
-// ===== Networking =====
+// ===== Utility =====
 // --------------------------------------------------------------------------------------------
 
 class NCShareUtility: NSObject {