Browse Source

add setAccountHCFeatures

marinofaggiana 5 years ago
parent
commit
7e4473b8ee

+ 1 - 1
File Provider Extension/FileProviderExtension-Bridging-Header.h

@@ -29,9 +29,9 @@
 #import "CCBKPasscode.h"
 #import "CCUtility.h"
 #import "NCEndToEndEncryption.h"
-
 #import "OCActivity.h"
 #import "OCUserProfile.h"
 #import "OCCapabilities.h"
 #import "OCExternalSites.h"
 #import "OCSharedDto.h"
+#import "HCFeatures.h"

+ 1 - 1
Share/Share-Bridging-Header.h

@@ -5,9 +5,9 @@
 #import "CCHud.h"
 #import "ShareViewController.h"
 #import "NCEndToEndEncryption.h"
-
 #import "OCActivity.h"
 #import "OCUserProfile.h"
 #import "OCCapabilities.h"
 #import "OCExternalSites.h"
 #import "OCSharedDto.h"
+#import "HCFeatures.h"

+ 8 - 0
iOSClient/Database/NCDatabase.swift

@@ -63,6 +63,14 @@ class tableAccount: Object {
     @objc dynamic var userID = ""
     @objc dynamic var webpage = ""
     @objc dynamic var zip = ""
+    // HC
+    @objc dynamic var hcIsTrial: Bool = false
+    @objc dynamic var hcTrialExpired: Bool = false
+    @objc dynamic var hcTrialRemainingSec: Double = 0
+    @objc dynamic var hcTrialEndTime: NSDate? = nil
+    @objc dynamic var hcAccountRemoveExpired: Bool = false
+    @objc dynamic var hcAccountRemoveRemainingSec: Double = 0
+    @objc dynamic var hcAccountRemoveTime: NSDate? = nil
 }
 
 class tableActivity: Object {

+ 39 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -64,7 +64,7 @@ class NCManageDatabase: NSObject {
         var config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 45,
+            schemaVersion: 46,
             
             // 10 : Version 2.18.0
             // 11 : Version 2.18.2
@@ -102,6 +102,7 @@ class NCManageDatabase: NSObject {
             // 43 : Version 2.23.2.0
             // 44 : Version 2.23.4.3
             // 45 : Version 2.23.4.4
+            // 46 : Version 2.23.4.5
 
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0
@@ -520,6 +521,43 @@ class NCManageDatabase: NSObject {
         return activeAccount
     }
     
+    @objc func setAccountHCFeatures(_ features: HCFeatures) -> tableAccount? {
+        
+        guard let activeAccount = self.getAccountActive() else {
+            return nil
+        }
+        
+        let realm = try! Realm()
+        
+        do {
+            try realm.write {
+                
+                guard let result = realm.objects(tableAccount.self).filter("account = %@", activeAccount.account).first else {
+                    return
+                }
+                
+                result.hcIsTrial = features.isTrial
+                result.hcTrialExpired = features.trialExpired
+                result.hcTrialRemainingSec = features.trialRemainingSec
+                if features.trialEndTime > 0 {
+                    result.hcTrialEndTime = Date(timeIntervalSince1970: features.trialEndTime) as NSDate
+                } else {
+                    result.hcTrialEndTime = nil
+                }
+                result.hcAccountRemoveExpired = features.accountRemoveExpired
+                result.hcAccountRemoveRemainingSec = features.accountRemoveRemainingSec
+                if features.accountRemoveTime > 0 {
+                    result.hcAccountRemoveTime = Date(timeIntervalSince1970: features.accountRemoveTime) as NSDate
+                } else {
+                    result.hcAccountRemoveTime = nil
+                }
+            }
+        } catch let error {
+            print("[LOG] Could not write to database: ", error)
+        }
+        
+        return activeAccount
+    }
     @objc func setAccountDateSearchContentTypeImageVideo(_ date: Date) {
         
         guard let activeAccount = self.getAccountActive() else {

+ 4 - 4
iOSClient/Library/OCCommunicationLib/HCFeatures.h

@@ -26,12 +26,12 @@
 
 @property BOOL isTrial;
 @property BOOL trialExpired;
-@property NSInteger trialRemainingSec;
-@property NSInteger trialEndTime;
+@property double trialRemainingSec;
+@property double trialEndTime;
 @property (nonatomic, strong) NSString *trialEnd;
 @property BOOL accountRemoveExpired;
-@property NSInteger accountRemoveRemainingSec;
-@property NSInteger accountRemoveTime;
+@property double accountRemoveRemainingSec;
+@property double accountRemoveTime;
 @property (nonatomic, strong) NSString *accountRemove;
 
 @end

+ 1 - 0
iOSClient/Networking/NCService.swift

@@ -341,6 +341,7 @@ class NCService: NSObject {
         
         OCNetworking.sharedManager()?.getHCFeatures(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, completion: { (account, features, message, errorCode) in
             if errorCode == 0 && account == self.appDelegate.activeAccount {
+                _ = NCManageDatabase.sharedInstance.setAccountHCFeatures(features!)
             }
         })