marinofaggiana 4 years ago
parent
commit
d033ce3ba9

+ 6 - 6
File Provider Extension/FileProviderData.swift

@@ -74,8 +74,8 @@ class fileProviderData: NSObject {
         if domain == nil {
             
             guard let tableAccount = NCManageDatabase.sharedInstance.getAccountActive() else { return false }
-            let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: tableAccount.account, element: "major")
-            let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesWebDavRoot(account: tableAccount.account)
+            let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+            let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesWebDavRoot)
             
             account = tableAccount.account
             accountUser = tableAccount.user
@@ -99,8 +99,8 @@ class fileProviderData: NSObject {
             let accountDomain = tableAccount.userID + " (" + host + ")"
             if accountDomain == domain {
                 
-                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: tableAccount.account, element: "major")
-                let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesWebDavRoot(account: tableAccount.account)
+                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+                let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesWebDavRoot)
                 
                 account = tableAccount.account
                 accountUser = tableAccount.user
@@ -132,8 +132,8 @@ class fileProviderData: NSObject {
         for tableAccount in tableAccounts {
             if accountFromItemIdentifier == tableAccount.account {
                 
-                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: tableAccount.account, element: "major")
-                let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesWebDavRoot(account: tableAccount.account)
+                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+                let webDavRoot = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: tableAccount.account, elements: NCElementsJSON.shared.capabilitiesWebDavRoot)
                 
                 account = tableAccount.account
                 accountUser = tableAccount.user

+ 5 - 5
Share/ShareViewController.m

@@ -61,8 +61,8 @@
         
     } else {
         
-        NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:tableAccount.account element:@"major"];
-        NSString *webDavRoot = [[NCManageDatabase sharedInstance] getCapabilitiesWebDavRootWithAccount:tableAccount.account];
+        NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:tableAccount.account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
+        NSString *webDavRoot = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:tableAccount.account elements:NCElementsJSON.shared.capabilitiesWebDavRoot];
         
         // Networking
         [[NCCommunicationCommon sharedInstance] setupWithUser:tableAccount.user userId:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] url:tableAccount.url userAgent:[CCUtility getUserAgent] capabilitiesGroup:[NCBrandOptions sharedInstance].capabilitiesGroups webDavRoot:webDavRoot davRoot:nil nextcloudVersion:serverVersionMajor delegate:[NCNetworking sharedInstance]];
@@ -176,9 +176,9 @@
 {
     // Theming
     if ([NCBrandOptions sharedInstance].use_themingColor) {
-        NSString *themingColor = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color"];
-        NSString *themingColorElement = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color-element"];
-        NSString *themingColorText = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color-text"];
+        NSString *themingColor = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColor];
+        NSString *themingColorElement = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColorElement];
+        NSString *themingColorText = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColorText];
         [CCGraphics settingThemingColor:themingColor themingColorElement:themingColorElement themingColorText:themingColorText];
     }
     self.navigationController.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand;

+ 5 - 5
iOSClient/AppDelegate.m

@@ -477,13 +477,13 @@
 
 - (void)settingSetupCommunicationCapabilities:(NSString *)account
 {
-    NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:account element:@"major"];
+    NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
     if (serverVersionMajor > 0) {
         [[OCNetworking sharedManager].sharedOCCommunication setupNextcloudVersion: serverVersionMajor];
         [[NCCommunicationCommon sharedInstance] setupWithNextcloudVersion:serverVersionMajor];
      }
     
-    NSString *webDavRoot = [[NCManageDatabase sharedInstance] getCapabilitiesWebDavRootWithAccount:account];
+    NSString *webDavRoot = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:account elements:NCElementsJSON.shared.capabilitiesWebDavRoot];
     if (webDavRoot != nil) {
         [[NCCommunicationCommon sharedInstance] setupWithWebDavRoot:webDavRoot];
     }
@@ -994,9 +994,9 @@
     
     if ([NCBrandOptions sharedInstance].use_themingColor) {
         
-        NSString *themingColor = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color"];
-        NSString *themingColorElement = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color-element"];
-        NSString *themingColorText = [[NCManageDatabase sharedInstance] getCapabilitiesServerThemingWithAccount:self.activeAccount element:@"color-text"];
+        NSString *themingColor = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColor];
+        NSString *themingColorElement = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColorElement];
+        NSString *themingColorText = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.activeAccount elements:NCElementsJSON.shared.capabilitiesThemingColorText];
 
         [CCGraphics settingThemingColor:themingColor themingColorElement:themingColorElement themingColorText:themingColorText];
         

+ 11 - 3
iOSClient/Database/NCElementsJSON.swift

@@ -29,8 +29,16 @@ import Foundation
         return instance
     }()
     
-    @objc public let capabilitiesVersionString:     Array = ["ocs","data","version","string"]
+    @objc public lazy var capabilitiesVersionString:        Array = ["ocs","data","version","string"]
+    @objc public let capabilitiesVersionMajor:              Array = ["ocs","data","version","major"]
     
-    @objc public let capabilitiesThemingName:       Array = ["ocs","data","capabilities","theming","name"]
-    @objc public let capabilitiesThemingSlogan:     Array = ["ocs","data","capabilities","theming","slogan"]
+    @objc public let capabilitiesThemingColor:              Array = ["ocs","data","capabilities","theming","color"]
+    @objc public let capabilitiesThemingColorElement:       Array = ["ocs","data","capabilities","theming","color-element"]
+    @objc public let capabilitiesThemingColorText:          Array = ["ocs","data","capabilities","theming","color-text"]
+    @objc public let capabilitiesThemingName:               Array = ["ocs","data","capabilities","theming","name"]
+    @objc public let capabilitiesThemingSlogan:             Array = ["ocs","data","capabilities","theming","slogan"]
+       
+    @objc public let capabilitiesWebDavRoot:                Array = ["ocs","data","capabilities","core","webdav-root"]
+    
+    @objc public let capabilitiesE2EEEnabled:               Array = ["ocs","data","capabilities","end-to-end-encryption","enabled"]
 }

+ 0 - 90
iOSClient/Database/NCManageDatabase.swift

@@ -974,78 +974,6 @@ class NCManageDatabase: NSObject {
         return nil
     }
     
-    @objc func getCapabilitiesServerVersion(account: String, element: String) -> Int {
-
-        let realm = try! Realm()
-        realm.refresh()
-        
-        guard let result = realm.objects(tableCapabilities.self).filter("account == %@", account).first else {
-            return 0
-        }
-        guard let jsondata = result.jsondata else {
-            return 0
-        }
-        
-        let json = JSON(jsondata)
-        let data = json["ocs"]["data"]
-
-        return data["version"][element].intValue
-    }
-    
-    @objc func getCapabilitiesServerVersionString(account: String) -> String? {
-
-        let realm = try! Realm()
-        realm.refresh()
-        
-        guard let result = realm.objects(tableCapabilities.self).filter("account == %@", account).first else {
-            return nil
-        }
-        guard let jsondata = result.jsondata else {
-            return nil
-        }
-        
-        let json = JSON(jsondata)
-        let data = json["ocs"]["data"]
-
-        return data["version"]["string"].string
-    }
-    
-    @objc func getCapabilitiesWebDavRoot(account: String) -> String? {
-
-        let realm = try! Realm()
-        realm.refresh()
-        
-        guard let result = realm.objects(tableCapabilities.self).filter("account == %@", account).first else {
-            return nil
-        }
-        guard let jsondata = result.jsondata else {
-            return nil
-        }
-        
-        let json = JSON(jsondata)
-        let dataCapabilities = json["ocs"]["data"]["capabilities"]
-
-        return dataCapabilities["core"]["webdav-root"].string
-    }
-    
-    @objc func getCapabilitiesE2EEEnabled(account: String) -> Bool {
-
-        let realm = try! Realm()
-        realm.refresh()
-        
-        guard let result = realm.objects(tableCapabilities.self).filter("account == %@", account).first else {
-            return false
-        }
-        guard let jsondata = result.jsondata else {
-            return false
-        }
-        
-        let json = JSON(jsondata)
-        let dataCapabilities = json["ocs"]["data"]["capabilities"]
-
-        return dataCapabilities["end-to-end-encryption"]["enabled"].boolValue
-    }
-    
     @objc func getCapabilitiesE2EEVersion(account: String) -> Int {
 
         let realm = try! Realm()
@@ -1068,24 +996,6 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    @objc func getCapabilitiesServerTheming(account: String, element: String) -> String? {
-
-        let realm = try! Realm()
-        realm.refresh()
-        
-        guard let result = realm.objects(tableCapabilities.self).filter("account == %@", account).first else {
-            return nil
-        }
-        guard let jsondata = result.jsondata else {
-            return nil
-        }
-        
-        let json = JSON(jsondata)
-        let dataCapabilities = json["ocs"]["data"]["capabilities"]
-
-        return dataCapabilities["theming"][element].string
-    }
-    
     @objc func getCapabilitiesHandwerkcloudEnabled(account: String) -> Bool {
 
         let realm = try! Realm()

+ 4 - 3
iOSClient/Main/CCMain.m

@@ -1334,7 +1334,8 @@
             }
             
             // Version >= 12
-            if ([[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:appDelegate.activeAccount element:@"major"] >= 12) {
+            NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesVersionMajor];
+            if (serverVersionMajor >= 12) {
                 
                 [_timerWaitInput invalidate];
                 _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
@@ -2625,11 +2626,11 @@
 
 - (void)setTableViewHeader
 {
-    NSInteger versionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:appDelegate.activeAccount element:@"major"];
+    NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesVersionMajor];
 
     NSString *trimmedRichWorkspaceText = [self.richWorkspaceText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
-    if (versionMajor < k_nextcloud_version_18_0 || trimmedRichWorkspaceText.length == 0 ) {
+    if (serverVersionMajor < k_nextcloud_version_18_0 || trimmedRichWorkspaceText.length == 0 ) {
                 
         [self.tableView.tableHeaderView setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightSearchBar)];
         

+ 1 - 1
iOSClient/Main/CCMore.swift

@@ -133,7 +133,7 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         functionMenu.append(item)
         
         // ITEM : Trash
-        let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: appDelegate.activeAccount, element: "major")        
+        let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: appDelegate.activeAccount, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         if serverVersionMajor >= Int(k_trash_version_available) {
             
             item = OCExternalSites.init()

+ 1 - 1
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -45,7 +45,7 @@ extension AppDelegate {
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
         let isEncrypted = CCUtility.isFolderEncrypted(appDelegate.activeMain.serverUrl, e2eEncrypted: false, account: appDelegate.activeAccount)
-        let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: appDelegate.activeAccount, element: "major")
+        let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: appDelegate.activeAccount, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         
         actions.append(
             NCMenuAction(

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -172,7 +172,7 @@ class NCService: NSObject {
                 }
                 
                 // NCTextObtainEditorDetails
-                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: account, element: "major")
+                let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
                 if serverVersionMajor >= k_nextcloud_version_18_0 {
                     NCCommunication.sharedInstance.NCTextObtainEditorDetails(serverUrl: self.appDelegate.activeUrl, customUserAgent: nil, addCustomHeaders: nil, account: self.appDelegate.activeAccount) { (account, editors, creators, errorCode, errorMessage) in
                         if errorCode == 0 && account == self.appDelegate.activeAccount {

+ 4 - 4
iOSClient/Networking/OCNetworking.m

@@ -985,8 +985,8 @@
         completion(account, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
     }
     
-    NSInteger versionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:account element:@"major"];
-    if (versionMajor >= k_nextcloud_version_15_0) {
+    NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
+    if (serverVersionMajor >= k_nextcloud_version_15_0) {
         previews = true;
     }
     
@@ -1605,7 +1605,7 @@
     @synchronized(self) {
         
         AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-        NSInteger versionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:account element:@"major"];
+        NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
         tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
         NSString *token = [CCUtility getPassword:account];
         
@@ -1615,7 +1615,7 @@
             self.checkRemoteUserInProgress = true;
         }
         
-        if (versionMajor >= k_nextcloud_version_17_0) {
+        if (serverVersionMajor >= k_nextcloud_version_17_0) {
             
             [[OCNetworking sharedManager] getRemoteWipeStatusWithAccount:account token:token completion:^(NSString *account, BOOL wipe, NSString *message, NSInteger errorCode) {
                 

+ 2 - 2
iOSClient/Settings/CCSettings.m

@@ -51,7 +51,7 @@
     XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
     XLFormSectionDescriptor *section;
     XLFormRowDescriptor *row;
-    NSInteger versionServer = [[NCManageDatabase sharedInstance] getCapabilitiesServerVersionWithAccount:appDelegate.activeAccount element:@"major"];
+    NSInteger serverVersionMajor = [[NCManageDatabase sharedInstance] getCapabilitiesServerIntWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesVersionMajor];
     
     form.rowNavigationOptions = XLFormRowNavigationOptionNone;
     
@@ -134,7 +134,7 @@
     
     // Section : E2EEncryption From Nextcloud 19 --------------------------------------------------------------
 
-    if (versionServer >= k_nextcloud_version_19_0) {
+    if (serverVersionMajor >= k_nextcloud_version_19_0) {
         
         section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
         [form addFormSection:section];

+ 1 - 2
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -44,8 +44,7 @@
     XLFormSectionDescriptor *section;
     XLFormRowDescriptor *row;
     
-    BOOL isE2EEEnabled = [[NCManageDatabase sharedInstance] getCapabilitiesE2EEEnabledWithAccount:appDelegate.activeAccount];
-    
+    BOOL isE2EEEnabled = [[NCManageDatabase sharedInstance] getCapabilitiesServerBoolWithAccount:appDelegate.activeAccount elements:NCElementsJSON.shared.capabilitiesE2EEEnabled exists:false];
     if (isE2EEEnabled == NO) {
         
         // Section SERVICE NOT AVAILABLE -------------------------------------------------

+ 1 - 1
iOSClient/Utility/CCUtility.m

@@ -419,7 +419,7 @@
 
 + (BOOL)isEndToEndEnabled:(NSString *)account
 {
-    BOOL isE2EEEnabled = [[NCManageDatabase sharedInstance] getCapabilitiesE2EEEnabledWithAccount:account];
+    BOOL isE2EEEnabled = [[NCManageDatabase sharedInstance] getCapabilitiesServerBoolWithAccount:account elements:NCElementsJSON.shared.capabilitiesE2EEEnabled exists:false];
     
     NSString *publicKey = [self getEndToEndPublicKey:account];
     NSString *privateKey = [self getEndToEndPrivateKey:account];