alqindiirsyam 2 kuukautta sitten
vanhempi
commit
9829e9ca13

+ 7 - 3
AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -769,11 +769,15 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
     
     private func reloadAllData() {
         DispatchQueue.main.async { [weak self] in
-            self?.timerReloadData?.invalidate()
-            self?.timerReloadData = nil
-            self?.timerReloadData = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] _ in
+            if self?.timerReloadData == nil {
                 self?.getData()
+            } else {
+                self?.timerReloadData?.invalidate()
                 self?.timerReloadData = nil
+                self?.timerReloadData = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] _ in
+                    self?.getData()
+                    self?.timerReloadData = nil
+                }
             }
         }
     }

+ 0 - 12
NexilisLite/NexilisLite.xcodeproj/project.pbxproj

@@ -1260,14 +1260,10 @@
 			inputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite/Pods-NexilisLite-resources-${CONFIGURATION}-input-files.xcfilelist",
 			);
-			inputPaths = (
-			);
 			name = "[CP] Copy Pods Resources";
 			outputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite/Pods-NexilisLite-resources-${CONFIGURATION}-output-files.xcfilelist",
 			);
-			outputPaths = (
-			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
 			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NexilisLite/Pods-NexilisLite-resources.sh\"\n";
@@ -1281,14 +1277,10 @@
 			inputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
 			);
-			inputPaths = (
-			);
 			name = "[CP] Embed Pods Frameworks";
 			outputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
 			);
-			outputPaths = (
-			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
 			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-frameworks.sh\"\n";
@@ -1302,14 +1294,10 @@
 			inputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-resources-${CONFIGURATION}-input-files.xcfilelist",
 			);
-			inputPaths = (
-			);
 			name = "[CP] Copy Pods Resources";
 			outputFileListPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-resources-${CONFIGURATION}-output-files.xcfilelist",
 			);
-			outputPaths = (
-			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
 			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NexilisLite-NexilisLiteTests/Pods-NexilisLite-NexilisLiteTests-resources.sh\"\n";

+ 36 - 25
NexilisLite/NexilisLite/Source/APIS.swift

@@ -1148,35 +1148,46 @@ public class APIS: NSObject {
     
     private static func getMessageById(id: String) {
         DispatchQueue.global().async {
-//            Nexilis.sendStateToServer(s: "send ack from apn")
-            DispatchQueue.global().async {
-                let parameter: [String : Any] = [
-                    "pin": User.getMyPin() ?? "",
-                    "message_id": id
-                ]
-                Utils.postDataWithCookiesAndUserAgent(from: URL(string: Utils.getDomainOpr() + "pull_notification")!, parameter: parameter, isFormData: true) { data, response, error in
-                    if let data = data {
-                        do {
-                            if let dataString = String(data: data, encoding: .utf8) {
-                                if let jsonObj = try JSONSerialization.jsonObject(with: dataString.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [String: Any] {
-                                    let dataObj = jsonObj["data"] as? String ?? ""
-                                    let message = TMessage(data: dataObj)
-                                    Nexilis.saveMessage(message: message, withStatus: false, fromAPNS: true)
-                                    ackAPN(id: id)
+            let parameter: [String : Any] = [
+                "pin": User.getMyPin() ?? "",
+                "message_id": id
+            ]
+            Utils.postDataWithCookiesAndUserAgent(from: URL(string: Utils.getDomainOpr() + "pull_notification")!, parameter: parameter, isFormData: true) { data, response, error in
+                if let data = data {
+                    do {
+                        if let dataString = String(data: data, encoding: .utf8) {
+                            if let jsonObj = try JSONSerialization.jsonObject(with: dataString.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [String: Any] {
+                                let dataObj = jsonObj["data"] as? String ?? ""
+                                let message = TMessage(data: dataObj)
+                                if Utils.getSecureFolderOffline() == "0" && IncomingThread.dispatch == nil {
+                                    if API.nGetCLXConnState() == 0 {
+                                        do {
+                                            let id = Utils.getConnectionID()
+                                            try API.initConnection(sAPIK: Nexilis.sAPIKey, cbiI: Callback(), sTCPAddr: Nexilis.ADDRESS, nTCPPort: Nexilis.PORT, sUserID: id, sStartWH: "09:00")
+                                        } catch {}
+                                    }
+                                    if FileEncryption.shared.aesKey == nil {
+                                        IncomingThread.dispatch = DispatchGroup()
+                                        IncomingThread.dispatch?.enter()
+                                        Nexilis.getFeatureAccess()
+                                        IncomingThread.dispatch?.wait()
+                                        IncomingThread.dispatch = nil
+                                    }
+                                }
+                                print("save from APIS")
+                                Nexilis.saveMessage(message: message, withStatus: false, fromAPNS: true)
+                                ackAPN(id: id)
+                                DispatchQueue.main.async {
+                                    UIApplication.shared.applicationIconBadgeNumber = Int(APIS.getTotalCounter())
                                 }
                             }
-                        } catch {
-                            
                         }
-                    }
-                    DispatchQueue.main.async {
-                        UIApplication.shared.applicationIconBadgeNumber = Int(APIS.getTotalCounter())
+                    } catch {
+                        
                     }
                 }
-                DispatchQueue.main.async {
-                    UIApplication.shared.applicationIconBadgeNumber = Int(APIS.getTotalCounter())
-                }
             }
+//            Nexilis.sendStateToServer(s: "send ack from apn")
 //            do {
 //                if API.nGetCLXConnState() == 0 {
 //                    let id = Utils.getConnectionID()
@@ -1201,13 +1212,13 @@ public class APIS: NSObject {
 //                                print("message: \(message.toLogString())")
 //                            }
 //                        } else {
-//                            
+//
 //                        }
 //                    } else {
 //                    }
 //                }
 //            } catch {
-//                
+//
 //            }
         }
     }

+ 1 - 1
NexilisLite/NexilisLite/Source/Database.swift

@@ -16,8 +16,8 @@ public class Database {
     public init() {
         let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/encrypted_db_es.db"
         if FileManager.default.fileExists(atPath: databasePath) && database == nil {
-            _ = FileEncryption.shared.encryptFileToServer(data: Data())
             DispatchQueue.global().async {
+                _ = FileEncryption.shared.encryptFileToServer(data: Data())
                 while FileEncryption.shared.aesKey == nil {
                     Thread.sleep(forTimeInterval: 1)
                 }

+ 1 - 1
NexilisLite/NexilisLite/Source/Download.swift

@@ -77,7 +77,7 @@ public class Download {
                 "User-Agent": Utils.getUserAgent(),
                 "Cookie": Utils.getCookiesMobile()
             ]
-            print("FULL URL: \(fullURL)")
+//            print("FULL URL: \(fullURL)")
             do {
                 _ = SessionManager.shared.session.download(fullURL, headers: headers)
                 .downloadProgress(queue: downloadBufferQueue) { progress in

+ 17 - 0
NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -21,6 +21,8 @@ class IncomingThread {
     
     private var dispatchQueue = DispatchQueue(label: "IncomingThread")
     
+    static var dispatch: DispatchGroup?
+    
     private var queue = [TMessage]()
     
     func addQueue(message: TMessage) {
@@ -1305,6 +1307,21 @@ class IncomingThread {
     }
     
     private func receiveMessage(message: TMessage) -> Void {
+        if Utils.getSecureFolderOffline() == "0" {
+            if API.nGetCLXConnState() == 0 {
+                do {
+                    let id = Utils.getConnectionID()
+                    try API.initConnection(sAPIK: Nexilis.sAPIKey, cbiI: Callback(), sTCPAddr: Nexilis.ADDRESS, nTCPPort: Nexilis.PORT, sUserID: id, sStartWH: "09:00")
+                } catch {}
+            }
+            if FileEncryption.shared.aesKey == nil {
+                IncomingThread.dispatch = DispatchGroup()
+                IncomingThread.dispatch?.enter()
+                Nexilis.getFeatureAccess()
+                IncomingThread.dispatch?.wait()
+                IncomingThread.dispatch = nil
+            }
+        }
         guard let _: String = SecureUserDefaults.shared.value(forKey: "status") else {
             //print("App not ready!!! skip receive message \(message_id)")
             ack(message: message)

+ 22 - 6
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -509,8 +509,14 @@ public class Nexilis: NSObject {
         }
     }
     
+    static var isGettingFeatureAccess: Bool = false
     static func getFeatureAccess() {
-        DispatchQueue.global().async {
+        if isGettingFeatureAccess {
+            return
+        }
+        isGettingFeatureAccess = true
+        print("getFeatureAccess")
+        DispatchQueue.global(qos: .background).async {
 //            Utils.postDataWithCookiesAndUserAgent(from: URL(string: Utils.getDomainOpr() + "get_feature_access_new")!) { data, response, error in
 //                let response = response as? HTTPURLResponse
 //                if response?.statusCode != 200 || error != nil {
@@ -534,22 +540,21 @@ public class Nexilis: NSObject {
                                 tmp.removeValue(forKey: "action")
                                 tmp.removeValue(forKey: "alert_title")
                                 tmp.removeValue(forKey: "alert_message")
-                                jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
+                                if Array(tmp.keys)[0] != "secure_folder_encrypt_key" && Array(tmp.keys)[0] != "secure_folder_encrypt_key_iv" {
+                                    jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
+                                }
                                 if jsonData["upload_max_retry"]! != nil {
                                     let umr = jsonData["upload_max_retry"] as! String
                                     Utils.setMaxRetryUpload(value: umr)
-                                    jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
                                 if jsonData["upload_max_time"]! != nil {
                                     let umt = jsonData["upload_max_time"] as! String
                                     Utils.setMaxRetryTimeUpload(value: umt)
-                                    jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
                                 if jsonData["default_fb"]! != nil {
                                     if !Utils.getAfterConfigFB() {
                                         Utils.setConfigModeFB(value: jsonData["default_fb"] as! String)
                                     }
-                                    jsonFA[Array(tmp.keys)[0]] = Array(tmp.values)[0]
                                 }
                                 if jsonData["authentication_duration"]! != nil {
                                     let ad = jsonData["authentication_duration"] as! String
@@ -565,6 +570,10 @@ public class Nexilis: NSObject {
                                             Utils.setSecureFolderEncrypt(value: keyTemp)
                                         }
                                     }
+                                    if let dispatch = IncomingThread.dispatch {
+                                        Database.recreateInstance()
+                                        dispatch.leave()
+                                    }
                                 }
                                 if jsonData["secure_folder_encrypt_key_iv"]! != nil {
                                     keyIvTemp = jsonData["secure_folder_encrypt_key_iv"] as! String
@@ -602,15 +611,22 @@ public class Nexilis: NSObject {
                                     Utils.setFeatureAccess(value: jsonFAString)
                                 }
                             }
+                            isGettingFeatureAccess = false
                         }
                     }
                 } catch {
                     print("gagal parsing data:")
                 }
             } else {
+                print("gagal getfeatureaccess:")
+                isGettingFeatureAccess = false
                 if Utils.getSecureFolderOffline() == "0" || (Utils.getSecureFolderOffline() == "1" && !Utils.getSetProfile()) {
                     DispatchQueue.main.async {
-                        APIS.showRestartApp()
+                        if !APIS.checkAppStateisBackground() {
+                            APIS.showRestartApp()
+                        } else {
+                            getFeatureAccess()
+                        }
                     }
                 }
             }

+ 1 - 1
NexilisLite/NexilisLite/Source/Utils.swift

@@ -677,7 +677,7 @@ public final class Utils {
         if let value: String = SecureUserDefaults.shared.value(forKey: "secure_folder_offline") {
             return value
         }
-        return "1"
+        return "0"
     }
     
     public static func fetchDataWithCookiesAndUserAgent(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {

+ 4 - 1
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -2109,6 +2109,9 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
             return
         }
         DispatchQueue.global().async {
+            while API.nGetCLXConnState() == 0 || !API.bInetConnAvailable() {
+                Thread.sleep(forTimeInterval: 1)
+            }
             Database.shared.database?.inTransaction({ (fmdb, rollback) in
                 do {
                     _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
@@ -6222,7 +6225,7 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
         if dataMessages[indexPath.row]["status"]  as? String ?? "" == "8" {
             return
         }
-        if !CheckConnection.isConnectedToNetwork()  || API.nGetCLXConnState() == 0 {
+        if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
             let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
             imageView.tintColor = .white
             let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)

+ 10 - 2
NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -574,8 +574,13 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
             chatbot()
         }
         
-        let exblock = User.getData(pin: pinPerson)?.ex_block
-        blocking = exblock == nil ? "0" : exblock!.isEmpty ? "0" : exblock!
+        let dataUser = User.getData(pin: pinPerson)
+        if dataUser == nil {
+            blocking = "0"
+        } else {
+            let exblock = dataUser!.ex_block
+            blocking = exblock!.isEmpty ? "0" : exblock!
+        }
         
         changeAppBar()
         getData()
@@ -3270,6 +3275,9 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
             return
         }
         DispatchQueue.global().async {
+            while API.nGetCLXConnState() == 0 || !API.bInetConnAvailable() {
+                Thread.sleep(forTimeInterval: 1)
+            }
             if let listGroupImages = self.groupImages.first(where: { $0.key == message_id }) {
                 let valueListGroupImages = listGroupImages.value
                 for i in 0..<valueListGroupImages.count {

+ 7 - 3
NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -267,11 +267,15 @@ class ContactChatViewController: UITableViewController {
     
     private func reloadAllData() {
         DispatchQueue.main.async { [weak self] in
-            self?.timerReloadData?.invalidate()
-            self?.timerReloadData = nil
-            self?.timerReloadData = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] _ in
+            if self?.timerReloadData == nil {
                 self?.getData()
+            } else {
+                self?.timerReloadData?.invalidate()
                 self?.timerReloadData = nil
+                self?.timerReloadData = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { [weak self] _ in
+                    self?.getData()
+                    self?.timerReloadData = nil
+                }
             }
         }
     }