Marino Faggiana пре 7 година
родитељ
комит
2fb7b9ca49
1 измењених фајлова са 84 додато и 1 уклоњено
  1. 84 1
      iOSClient/Networking/NCService.swift

+ 84 - 1
iOSClient/Networking/NCService.swift

@@ -23,7 +23,7 @@
 
 import Foundation
 
-class NCService: NSObject {
+class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegateWeb {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
@@ -32,6 +32,8 @@ class NCService: NSObject {
         return instance
     }()
 
+    //MARK: -
+    //MARK: middlewarePing
     
      @objc func middlewarePing() {
        
@@ -48,4 +50,85 @@ class NCService: NSObject {
         
         //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
+    
+    //MARK: -
+    //MARK: requestServerCapabilities
+    
+    func getCapabilitiesOfServerSuccessFailure(_ metadataNet: CCMetadataNet!, capabilities: OCCapabilities?, message: String?, errorCode: Int) {
+        
+        // Check Active Account
+        if (metadataNet.account != appDelegate.activeAccount) {
+            return;
+        }
+        
+        if (errorCode == 0) {
+            
+            // Update capabilities db
+            NCManageDatabase.sharedInstance.addCapabilities(capabilities!)
+            
+            // ------ THEMING -----------------------------------------------------------------------
+            
+            // Download Theming Background & Change Theming color
+            DispatchQueue.global().async {
+                
+                if (NCBrandOptions.sharedInstance.use_themingBackground) {
+                }
+            }
+            
+            // ------ SEARCH ------------------------------------------------------------------------
+            
+            if (NCManageDatabase.sharedInstance.getServerVersion() != capabilities!.versionMajor && appDelegate.activeMain != nil) {
+                appDelegate.activeMain.cancelSearchBar()
+            }
+            
+            // ------ GET OTHER SERVICE -------------------------------------------------------------
+            
+        } else {
+            
+            // Unauthorized
+            if (errorCode == kOCErrorServerUnauthorized) {
+                appDelegate.openLoginView(self, loginType: loginModifyPasswordUser)
+            }
+            
+            let error = "Get Capabilities failure error \(errorCode) \(message!)"
+            print("[LOG] \(message!)")
+            
+            NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionCapabilities, selector: "Get Capabilities of Server", note: error, type: k_activityTypeFailure, verbose: true, activeUrl: appDelegate.activeUrl)
+            
+            // Change Theming color
+            appDelegate.settingThemingColorBrand()
+        }
+    }
+    
+    @objc func requestServerCapabilities() {
+        
+        if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {
+            return;
+        }
+    
+        guard let metadataNet = CCMetadataNet.init(account: appDelegate.activeAccount) else {
+            return
+        }
+    
+        metadataNet.action = actionGetCapabilities;
+        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+    }
+
+    //MARK: -
+    //MARK: Delegate : Login
+    
+    func loginSuccess(_ loginType: Int) {
+        
+        // go to home sweet home
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "initializeMain"), object: nil)
+    }
+
+    func loginClose() {
+        appDelegate.activeLogin = nil;
+    }
+    
+    func loginWebClose() {
+        appDelegate.activeLoginWeb = nil;
+    }
+    
 }