瀏覽代碼

start getCapabilitiesOfServer add account

Marino Faggiana 6 年之前
父節點
當前提交
de8cc34f5b
共有 4 個文件被更改,包括 130 次插入152 次删除
  1. 0 1
      iOSClient/CCGlobal.h
  2. 110 121
      iOSClient/Networking/NCService.swift
  3. 2 3
      iOSClient/Networking/OCNetworking.h
  4. 18 27
      iOSClient/Networking/OCNetworking.m

+ 0 - 1
iOSClient/CCGlobal.h

@@ -217,7 +217,6 @@
 #define selectorUploadFile                              @"uploadFile"
 
 // Metadata.Net ACTION
-#define actionGetCapabilities                           @"getCapabilitiesOfServer"
 #define actionGetUserAndGroup                           @"getUserAndGroup"
 #define actionGetUserProfile                            @"getUserProfile"
 #define actionGetNotificationServer                     @"getNotificationServer"

+ 110 - 121
iOSClient/Networking/NCService.swift

@@ -57,12 +57,115 @@ class NCService: NSObject, OCNetworkingDelegate {
             return
         }
         
-        guard let metadataNet = CCMetadataNet.init(account: appDelegate.activeAccount) else {
-            return
-        }
-        
-        metadataNet.action = actionGetCapabilities
-        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
+        ocNetworking?.getCapabilitiesOfServer(appDelegate.activeAccount, completion: { (account, capabilities, message, errorCode) in
+            
+            if (errorCode == 0 && self.appDelegate.activeAccount == account!) {
+                
+                // Update capabilities db
+                NCManageDatabase.sharedInstance.addCapabilities(capabilities!, account: account!)
+                
+                // ------ THEMING -----------------------------------------------------------------------
+                
+                if (NCBrandOptions.sharedInstance.use_themingBackground && capabilities!.themingBackground != "") {
+                    
+                    // Download Logo
+                    let fileNameThemingLogo = CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingLogo.png"
+                    NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true)
+                    
+                    // Download Theming Background
+                    DispatchQueue.global().async {
+                        
+                        let backgroundURL = capabilities!.themingBackground!.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
+                        let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingBackground.png"
+                        
+                        guard let imageData = try? Data(contentsOf: URL(string: backgroundURL)!) else {
+                            DispatchQueue.main.async {
+                                self.appDelegate.settingThemingColorBrand()
+                            }
+                            return
+                        }
+                        
+                        DispatchQueue.main.async {
+                            
+                            guard let image = UIImage(data: imageData) else {
+                                try? FileManager.default.removeItem(atPath: fileNamePath)
+                                self.appDelegate.settingThemingColorBrand()
+                                return
+                            }
+                            
+                            if let data = image.pngData() {
+                                try? data.write(to: URL(fileURLWithPath: fileNamePath))
+                            }
+                            
+                            self.appDelegate.settingThemingColorBrand()
+                        }
+                    }
+                    
+                } else {
+                    
+                    self.appDelegate.settingThemingColorBrand()
+                }
+                
+                // ------ SEARCH ------------------------------------------------------------------------
+                
+                if (NCManageDatabase.sharedInstance.getServerVersion(account: account!) != capabilities!.versionMajor && self.appDelegate.activeMain != nil) {
+                    self.appDelegate.activeMain.cancelSearchBar()
+                }
+                
+                // ------ GET OTHER SERVICE -------------------------------------------------------------
+                
+                // Read Notification
+                if (capabilities!.isNotificationServerEnabled) {
+                    
+                    //metadataNet.action = actionGetNotificationServer
+                    //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+                    
+                } else {
+                    
+                    // Remove all Notification
+                    self.appDelegate.listOfNotifications.removeAllObjects()
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notificationReloadData"), object: nil)
+                    // Update Main NavigationBar
+                    if (self.appDelegate.activeMain != nil && self.appDelegate.activeMain.isSelectedMode == false) {
+                        self.appDelegate.activeMain.setUINavigationBarDefault()
+                    }
+                }
+                
+                // Read External Sites
+                if (capabilities!.isExternalSitesServerEnabled) {
+                    
+                    //metadataNet.action = actionGetExternalSitesServer
+                    //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+                    
+                } else {
+                    
+                    NCManageDatabase.sharedInstance.deleteExternalSites(account: account!)
+                }
+                
+                // Read Share
+                if (capabilities!.isFilesSharingAPIEnabled && self.appDelegate.activeMain != nil) {
+                    
+                    self.appDelegate.sharesID.removeAllObjects()
+                    //metadataNet.action = actionReadShareServer
+                    //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: appDelegate.activeMain, metadataNet: metadataNet)
+                }
+                
+            } else {
+                
+                // Change Theming color
+                self.appDelegate.settingThemingColorBrand()
+                
+                var error = ""
+                if let message = message {
+                    error = "Get Capabilities failure error \(errorCode) \(message)"
+                } else {
+                    error = "Get Capabilities failure error \(errorCode)"
+                }
+                
+                NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionCapabilities, selector: "Get Capabilities of Server", note: error, type: k_activityTypeFailure, verbose: true, activeUrl: "")
+            }
+        })
     }
     
     private func requestUserProfile() {
@@ -141,121 +244,7 @@ class NCService: NSObject, OCNetworkingDelegate {
     //MARK: -
     //MARK: Delegate Service API NC
     
-    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!, account: metadataNet.account)
-            
-            // ------ THEMING -----------------------------------------------------------------------
-            
-            if (NCBrandOptions.sharedInstance.use_themingBackground && capabilities!.themingBackground != "") {
-                
-                // Download Logo
-                let fileNameThemingLogo = CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingLogo.png"
-                NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true)
-                
-                // Download Theming Background
-                DispatchQueue.global().async {
-                
-                    let backgroundURL = capabilities!.themingBackground!.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
-                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingBackground.png"
-
-                    guard let imageData = try? Data(contentsOf: URL(string: backgroundURL)!) else {
-                        DispatchQueue.main.async {
-                            self.appDelegate.settingThemingColorBrand()
-                        }
-                        return
-                    }
-                    
-                    DispatchQueue.main.async {
-                        
-                        guard let image = UIImage(data: imageData) else {
-                            try? FileManager.default.removeItem(atPath: fileNamePath)
-                            self.appDelegate.settingThemingColorBrand()
-                            return
-                        }
-                    
-                        if let data = image.pngData() {
-                            try? data.write(to: URL(fileURLWithPath: fileNamePath))
-                        }
-                    
-                        self.appDelegate.settingThemingColorBrand()
-                    }
-                }
-                
-            } else {
-                
-                self.appDelegate.settingThemingColorBrand()
-            }
-            
-            // ------ SEARCH ------------------------------------------------------------------------
-            
-            if (NCManageDatabase.sharedInstance.getServerVersion(account: metadataNet.account) != capabilities!.versionMajor && appDelegate.activeMain != nil) {
-                appDelegate.activeMain.cancelSearchBar()
-            }
-            
-            // ------ GET OTHER SERVICE -------------------------------------------------------------
-
-            // Read Notification
-            if (capabilities!.isNotificationServerEnabled) {
-                
-                metadataNet.action = actionGetNotificationServer
-                appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
-                
-            } else {
-                
-                // Remove all Notification
-                self.appDelegate.listOfNotifications.removeAllObjects()
-                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notificationReloadData"), object: nil)
-                // Update Main NavigationBar
-                if (appDelegate.activeMain != nil && self.appDelegate.activeMain.isSelectedMode == false) {
-                    self.appDelegate.activeMain.setUINavigationBarDefault()
-                }
-            }
-            
-            // Read External Sites
-            if (capabilities!.isExternalSitesServerEnabled) {
-                
-                metadataNet.action = actionGetExternalSitesServer
-                appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
-                
-            } else {
-                
-                NCManageDatabase.sharedInstance.deleteExternalSites(account: appDelegate.activeAccount)
-            }
-            
-            // Read Share
-            if (capabilities!.isFilesSharingAPIEnabled && appDelegate.activeMain != nil) {
-                
-                appDelegate.sharesID.removeAllObjects()
-                metadataNet.action = actionReadShareServer
-                appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: appDelegate.activeMain, metadataNet: metadataNet)
-            }
-            
-        } else {
-            
-            // Change Theming color
-            appDelegate.settingThemingColorBrand()
-            
-            var error = ""
-            if let message = message {
-                error = "Get Capabilities failure error \(errorCode) \(message)"
-            } else {
-                error = "Get Capabilities failure error \(errorCode)"
-            }
-                        
-            NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionCapabilities, selector: "Get Capabilities of Server", note: error, type: k_activityTypeFailure, verbose: true, activeUrl: appDelegate.activeUrl)
-        }
-    }
-    
-   func getUserProfileSuccessFailure(_ metadataNet: CCMetadataNet!, userProfile: OCUserProfile?, message: String?, errorCode: Int) {
+    func getUserProfileSuccessFailure(_ metadataNet: CCMetadataNet!, userProfile: OCUserProfile?, message: String?, errorCode: Int) {
         
         // Check Active Account
         if (metadataNet.account != appDelegate.activeAccount) {

+ 2 - 3
iOSClient/Networking/OCNetworking.h

@@ -71,6 +71,8 @@
 
 - (void)getActivityServer:(NSString *)account success:(void(^)(NSString *account, NSArray *listOfActivity))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure;
 
+- (void)getCapabilitiesOfServer:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion;
+
 - (void)subscribingPushNotificationServer:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey success:(void(^)(NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
 - (void)unsubscribingPushNotificationServer:(NSString *)url deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
@@ -103,9 +105,6 @@
 - (void)getSharePermissionsFileSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions;
 - (void)getSharePermissionsFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
-// Capabilities
-- (void)getCapabilitiesOfServerSuccessFailure:(CCMetadataNet *)metadataNet capabilities:(OCCapabilities *)capabilities message:(NSString *)message errorCode:(NSInteger)errorCode;
-
 // External Sites
 - (void)getExternalSitesServerSuccessFailure:(CCMetadataNet *)metadataNet listOfExternalSites:(NSArray *)listOfExternalSites message:(NSString *)message errorCode:(NSInteger)errorCode;
 

+ 18 - 27
iOSClient/Networking/OCNetworking.m

@@ -1848,53 +1848,44 @@
 #pragma mark ===== Capabilities =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getCapabilitiesOfServer
+- (void)getCapabilitiesOfServer:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion
 {
+    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
+    if (tableAccount == nil) {
+        completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
+    }
+    
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
-    [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
+    [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:tableAccount.password];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    [communication getCapabilitiesOfServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer) {
+    [communication getCapabilitiesOfServer:[tableAccount.url stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer) {
         
-        // Test active account
-        tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
-        if (![recordAccount.account isEqualToString:_metadataNet.account]) {
-            if ([self.delegate respondsToSelector:@selector(getCapabilitiesOfServerSuccessFailure:capabilities:message:errorCode:)])
-                [self.delegate getCapabilitiesOfServerSuccessFailure:_metadataNet capabilities:nil message:NSLocalizedString(@"_error_user_not_available_", nil) errorCode:k_CCErrorUserNotAvailble];
-            
-            [self complete];
-            return;
-        }
-        
-        if ([self.delegate respondsToSelector:@selector(getCapabilitiesOfServerSuccessFailure:capabilities:message:errorCode:)])
-            [self.delegate getCapabilitiesOfServerSuccessFailure:_metadataNet capabilities:capabilities message:nil errorCode:0];
-        
-        [self complete];
+        completion(account, capabilities, nil, 0);
         
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
         
+        NSString *message = @"";
         NSInteger errorCode = response.statusCode;
         if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
             errorCode = error.code;
-
+        
         // Error
-        if ([self.delegate respondsToSelector:@selector(getCapabilitiesOfServerSuccessFailure:capabilities:message:errorCode:)]) {
-
-            if (errorCode == 503)
-                [self.delegate getCapabilitiesOfServerSuccessFailure:_metadataNet capabilities:nil message:NSLocalizedString(@"_server_error_retry_", nil) errorCode:errorCode];
-            else
-                [self.delegate getCapabilitiesOfServerSuccessFailure:_metadataNet capabilities:nil message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        if (errorCode == 503) {
+            message = NSLocalizedString(@"_server_error_retry_", nil);
+        } else {
+            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
         }
-
+        
         // Request trusted certificated
         if ([error code] == NSURLErrorServerCertificateUntrusted && self.delegate)
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
-
+        
         // Activity
         [[NCManageDatabase sharedInstance] addActivityClient:_activeUrl fileID:@"" action:k_activityDebugActionCapabilities selector:@"" note:[error.userInfo valueForKey:@"NSLocalizedDescription"] type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:_activeUrl];
         
-        [self complete];
+        completion(account, nil, message, errorCode);
     }];
 }