Browse Source

update fix bugs

alqindiirsyam 7 months ago
parent
commit
92b9c3de94

BIN
AppBuilder/.DS_Store


+ 11 - 5
AppBuilder/AppBuilder/FirstTabViewController.swift

@@ -69,6 +69,7 @@ class FirstTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
         contentController.add(self, name: "showAlert")
         contentController.add(self, name: "closeProfile")
         contentController.add(self, name: "tabShowHide")
+        contentController.add(self, name: "shareText")
         
         let source: String = "var meta = document.createElement('meta');" +
             "meta.name = 'viewport';" +
@@ -94,16 +95,13 @@ class FirstTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
     
     func loadURLWithCookie(url: URL) {
         var urlRequest = URLRequest(url: url)
-        let cookieHeader = Utils.getCookiesMobile()
-        urlRequest.addValue(cookieHeader, forHTTPHeaderField: "Cookie")
         let customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1 \(Utils.getUserAgent())"
         urlRequest.setValue(customUserAgent, forHTTPHeaderField: "User-Agent")
-        webView.load(urlRequest)
-        
-        if let cookies = HTTPCookieStorage.shared.cookies {
+        if let cookies = HTTPCookieStorage.shared.cookies(for: url) {
             for cookie in cookies {
                 webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie)
             }
+            webView.load(urlRequest)
         }
     }
     
@@ -437,6 +435,14 @@ class FirstTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
                     hideTabBar()
                 }
             }
+        } else if message.name == "shareText" {
+            print("HMM masuk share text")
+            guard let dict = message.body as? [String: AnyObject],
+                  let param1 = dict["param1"] as? String else {
+                return
+            }
+            let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
+            self.present(activityViewController, animated: true, completion: nil)
         }
     }
     

+ 2 - 2
AppBuilder/AppBuilder/FourthTabViewController.swift

@@ -172,7 +172,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                         Item.menus["Personal"] = [
                             Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
                             Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
-                            Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
+//                            Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
                         ]
                     }
                     if !isChangeProfile {
@@ -225,7 +225,7 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
                     Item.menus["Personal"] = [
                         Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
                         Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
-                        Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
+//                        Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
                     ]
                     if Nexilis.showButtonFB {
                         Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))

+ 36 - 18
AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -73,8 +73,9 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
         return searchController.searchBar.text!.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
     }
     
-    var isFilltering: Bool {
-        return !isSearchBarEmpty
+    var isFiltering: Bool {
+        return !textViewSearch.text!.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+//        return !isSearchBarEmpty
     }
     @IBOutlet var tableView: UITableView!
     
@@ -275,8 +276,11 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
 
             if error != nil || isFinal {
                 if error == nil {
-                    self.searchController.searchBar.searchTextField.text = result!.bestTranscription.formattedString
-                    self.updateSearchResults(for: self.searchController)
+                    let textRes = result!.bestTranscription.formattedString
+                    self.textViewSearch.text = textRes
+                    self.filterContentForSearchText(textRes)
+//                    self.searchController.searchBar.searchTextField.text = result!.bestTranscription.formattedString
+//                    self.updateSearchResults(for: self.searchController)
                 } else {
                     self.audioEngine.stop()
                     self.recognitionRequest?.endAudio()
@@ -400,13 +404,13 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
         let imageViewSearch = UIImageView(image: UIImage(named: self.traitCollection.userInterfaceStyle == .dark ? "nx_search_bar_dark" : "nx_search_bar", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
         imageViewSearch.contentMode = .scaleToFill
         customView.addSubview(imageViewSearch)
-        imageViewSearch.anchor(top: customView.topAnchor, left: customView.leftAnchor, bottom: customView.bottomAnchor, right: customView.rightAnchor, height: 30)
+        imageViewSearch.anchor(top: customView.topAnchor, left: customView.leftAnchor, bottom: customView.bottomAnchor, right: customView.rightAnchor, height: 35)
         imageViewSearch.isUserInteractionEnabled = true
         
         let imageSetting = UIImageView(image: UIImage(named: "nx_setting_sb", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
         imageSetting.contentMode = .scaleToFill
         imageViewSearch.addSubview(imageSetting)
-        imageSetting.anchor(top: imageViewSearch.topAnchor, right: customView.rightAnchor, paddingTop: 5, paddingRight: 18, width: 20, height: 20)
+        imageSetting.anchor(right: customView.rightAnchor, paddingRight: 18, centerY: customView.centerYAnchor, width: 20, height: 20)
         imageSetting.isUserInteractionEnabled = true
         imageSetting.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(settingTapped)))
         
@@ -490,6 +494,13 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
 //        tableView.reloadData()
 //    }
     
+    func textFieldDidChangeSelection(_ textField: UITextField) {
+        if textField == textViewSearch {
+            let textSerch = textField.text ?? ""
+            filterContentForSearchText(textSerch)
+        }
+    }
+    
     override func viewWillDisappear(_ animated: Bool) {
         tabBarController?.navigationItem.leftBarButtonItem = nil
         tabBarController?.navigationItem.searchController = nil
@@ -594,7 +605,8 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
 //            searchController.searchBar.placeholder = "Search chats & messages".localized()
 //            searchController.searchBar.searchTextField.attributedPlaceholder = NSAttributedString(string: "Search chats & messages".localized(), attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)])
         }
-        filterContentForSearchText(searchController.searchBar.text!)
+//        filterContentForSearchText(searchController.searchBar.text!)
+        filterContentForSearchText(self.textViewSearch.text ?? "")
     }
     
     // MARK: - Data source
@@ -783,7 +795,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
         switch segment.selectedSegmentIndex {
         case 0:
             let data: Chat
-            if isFilltering {
+            if isFiltering {
                 data = fillteredData[indexPath.row] as! Chat
             } else {
                 data = chats[indexPath.row]
@@ -816,7 +828,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
     
     func expandCollapseGroup(tableView: UITableView, indexPath: IndexPath) {
         let group: Group
-        if isFilltering {
+        if isFiltering {
             if indexPath.row == 0 {
                 group = fillteredData[indexPath.section] as! Group
             } else {
@@ -845,7 +857,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                 var loooop = true
                 repeat {
                     let c = sect + 1
-                    if isFilltering {
+                    if isFiltering {
                         if let o = self.fillteredData[c] as? Group {
                             if o.parent == id {
                                 sects = sects + 1
@@ -874,7 +886,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                 } while(loooop)
             }
             for i in stride(from: sects, to: 0, by: -1){
-                if isFilltering {
+                if isFiltering {
                     self.fillteredData.remove(at: indexPath.section + i)
                 }
                 else {
@@ -937,7 +949,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                         //print("index path section: \(indexPath.section)")
                         //print("index path row: \(indexPath.row)")
                         //print("index path item: \(indexPath.item)")
-                        if self.isFilltering {
+                        if self.isFiltering {
 //                                self.fillteredData.remove(at: indexPath.section)
                             if self.fillteredData[indexPath.section] is Group {
                                 self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
@@ -1013,7 +1025,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
     }
     
     func numberOfSections(in tableView: UITableView) -> Int {
-        if isFilltering {
+        if isFiltering {
             if segment.selectedSegmentIndex == 1 {
                 return fillteredData.count
             }
@@ -1028,7 +1040,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         var value = 0
-        if isFilltering {
+        if isFiltering {
             if segment.selectedSegmentIndex == 1, let groups = fillteredData as? [Group] {
                 let group = groups[section]
                 if group.isSelected {
@@ -1044,6 +1056,12 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
             } else {
                 value = fillteredData.count
             }
+            if value == 0 {
+                value = 1
+                tableView.separatorStyle = .none
+            } else {
+                tableView.separatorStyle = .singleLine
+            }
             return value
         }
         switch segment.selectedSegmentIndex {
@@ -1084,9 +1102,9 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
             if content.subviews.count > 0 {
                 content.subviews.forEach { $0.removeFromSuperview() }
             }
-            if noData {
+            if noData || (isFiltering && fillteredData.count == 0) {
                 let labelNochat = UILabel()
-                labelNochat.text = "There are no conversations".localized()
+                labelNochat.text = isFiltering ? "No Result".localized() : "There are no conversations".localized()
                 labelNochat.font = .systemFont(ofSize: 13)
                 labelNochat.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
                 content.addSubview(labelNochat)
@@ -1096,7 +1114,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                 return cell
             }
             let data: Chat
-            if isFilltering {
+            if isFiltering {
                 data = fillteredData[indexPath.row] as! Chat
             } else {
                 if chats.count == 0 {
@@ -1289,7 +1307,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
             var content = cell.defaultContentConfiguration()
             content.textProperties.font = UIFont.systemFont(ofSize: 14)
             let group: Group
-            if isFilltering {
+            if isFiltering {
                 if indexPath.row == 0 {
                     group = fillteredData[indexPath.section] as! Group
                 } else {

+ 15 - 6
AppBuilder/AppBuilder/ThirdTabViewController.swift

@@ -70,6 +70,7 @@ class ThirdTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
         contentController.add(self, name: "showAlert")
         contentController.add(self, name: "closeProfile")
         contentController.add(self, name: "tabShowHide")
+        contentController.add(self, name: "shareText")
         
         let source: String = "var meta = document.createElement('meta');" +
             "meta.name = 'viewport';" +
@@ -95,14 +96,14 @@ class ThirdTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
     
     func loadURLWithCookie(url: URL) {
         var urlRequest = URLRequest(url: url)
-        // Setting cookies
-        let cookieHeader = Utils.getCookiesMobile()
-        urlRequest.addValue(cookieHeader, forHTTPHeaderField: "Cookie")
-        
-        // Setting user agent
         let customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1 \(Utils.getUserAgent())"
         urlRequest.setValue(customUserAgent, forHTTPHeaderField: "User-Agent")
-        webView.load(urlRequest)
+        if let cookies = HTTPCookieStorage.shared.cookies(for: url) {
+            for cookie in cookies {
+                webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie)
+            }
+            webView.load(urlRequest)
+        }
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -447,6 +448,14 @@ class ThirdTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
                     hideTabBar()
                 }
             }
+        } else if message.name == "shareText" {
+            print("HMM masuk share text")
+            guard let dict = message.body as? [String: AnyObject],
+                  let param1 = dict["param1"] as? String else {
+                return
+            }
+            let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
+            self.present(activityViewController, animated: true, completion: nil)
         }
     }
     

+ 1 - 1
AppBuilder/AppBuilder/ViewController.swift

@@ -59,7 +59,7 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
     override func viewDidLoad() {
         super.viewDidLoad()
         DispatchQueue.main.async { [self] in
-            while !Utils.getFinishInitPrefsr() {
+            while !Utils.getFinishInitPrefsr() || HTTPCookieStorage.shared.cookies?.count == 0 {
                
             }
             startView()

+ 41 - 0
NexilisLite/NexilisLite/Source/Extension.swift

@@ -315,6 +315,47 @@ extension UIImage {
         UIGraphicsEndImageContext()
         return image
     }
+    
+    func mimeType() -> String? {
+        guard let imageData = self.pngData() else {
+            return nil
+        }
+
+        let byteArray = [UInt8](imageData)
+        
+        if byteArray.starts(with: [0xFF, 0xD8, 0xFF]) {
+            return "image/jpeg"
+        } else if byteArray.starts(with: [0x89, 0x50, 0x4E, 0x47]) {
+            return "image/png"
+        } else if byteArray.starts(with: [0x47, 0x49, 0x46, 0x38]) {
+            return "image/gif"
+        } else if byteArray.starts(with: [0x49, 0x49, 0x2A, 0x00]) || byteArray.starts(with: [0x4D, 0x4D, 0x00, 0x2A]) {
+            return "image/tiff"
+        }
+        return nil
+    }
+
+}
+
+extension Data {
+    func mimeType() -> String? {
+        let byteArray = [UInt8](self)
+        
+        if byteArray.starts(with: [0xFF, 0xD8, 0xFF]) {
+            return "image/jpeg"
+        } else if byteArray.starts(with: [0x89, 0x50, 0x4E, 0x47]) {
+            return "image/png"
+        } else if byteArray.starts(with: [0x47, 0x49, 0x46, 0x38]) {
+            return "image/gif"
+        } else if byteArray.starts(with: [0x49, 0x49, 0x2A, 0x00]) || byteArray.starts(with: [0x4D, 0x4D, 0x00, 0x2A]) {
+            return "image/tiff"
+        } else if byteArray.starts(with: [0x25, 0x50, 0x44, 0x46]) {
+            return "application/pdf"
+        } else if byteArray.starts(with: [0x50, 0x4B, 0x03, 0x04]) {
+            return "application/zip"
+        }
+        return nil
+    }
 }
 
 extension UIImage {

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

@@ -107,7 +107,7 @@ public class FileEncryption {
     func encryptFile(_ inputURL: URL, _ outputURL: URL, _ key: SymmetricKey) throws {
         let keyData = key.withUnsafeBytes { Data($0) }
         
-        let iv = generateIV()
+        let iv = MasterKeyUtil.shared.getServerKeyIV()
         let data = try Data(contentsOf: inputURL)
         let encryptedData = Data(count: data.count + kCCBlockSizeAES128)
         var finalData = encryptedData

+ 5 - 0
NexilisLite/NexilisLite/Source/MasterKeyUtil.swift

@@ -88,6 +88,11 @@ public class MasterKeyUtil {
         }
     }
     
+    func getServerKeyIV() -> Data {
+        let keyData = base64toData(Utils.getSecureFolderEncryptIv()) ?? Data()
+        return keyData
+    }
+    
     func getMasterKey() throws -> SymmetricKey {
         if (Nexilis.checkingAccess(key: "authentication") && isDeviceNotSecure()) {
             var result = false

+ 2 - 2
NexilisLite/NexilisLite/Source/Network.swift

@@ -252,8 +252,8 @@ public class Network {
                 //print(multipartFormData)
             }
             
-            for i in 0..<filesTempServer.count {
-                multipartFormData.append(filesTempServer[i], withName: "file\(i+1)", fileName: filesTempServer[i].lastPathComponent, mimeType: "application/octet-stream")
+            for i in 0..<filesIn.count {
+                multipartFormData.append(filesIn[i], withName: "file\(i+1)", fileName: filesIn[i].lastPathComponent, mimeType: "application/octet-stream")
                 Nexilis.putUploadFile(forKey: filesIn[i].lastPathComponent, uploader: self)
                 //print(multipartFormData)
             }

+ 3 - 0
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -459,6 +459,9 @@ public class Nexilis: NSObject {
                                         
                                     }
                                 }
+                                if jsonData["secure_folder_encrypt_key_iv"]! != nil {
+                                    Utils.setSecureFolderEncryptIv(value: jsonData["secure_folder_encrypt_key_iv"] as! String)
+                                }
                                 if jsonData["chatbot_greetings"]! != nil {
                                     if let greeting = jsonData["chatbot_greetings"] as? String {
                                         print("Chatbot greeting: \(greeting)")

+ 11 - 0
NexilisLite/NexilisLite/Source/Utils.swift

@@ -561,6 +561,17 @@ public final class Utils {
         return "easySoftIndonesia"
     }
     
+    public static func setSecureFolderEncryptIv(value: String){
+        SecureUserDefaults.shared.set(value, forKey: "secure_folder_encrypt_key_iv")
+    }
+    
+    public static func getSecureFolderEncryptIv() -> String {
+        if let value: String = SecureUserDefaults.shared.value(forKey: "secure_folder_encrypt_key_iv") {
+            return value
+        }
+        return "easySoftIndonesia"
+    }
+    
     public static func fetchDataWithCookiesAndUserAgent(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
         var request = URLRequest(url: url)
         request.httpMethod = "GET"

+ 26 - 20
NexilisLite/NexilisLite/Source/View/BNIView/BNIBookingWebView.swift

@@ -60,6 +60,7 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
         contentController.add(self, name: "closeProfile")
         contentController.add(self, name: "successChangeTheme")
         contentController.add(self, name: "finishForm")
+        contentController.add(self, name: "shareText")
         
         let source: String = "var meta = document.createElement('meta');" +
             "meta.name = 'viewport';" +
@@ -113,17 +114,14 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
     
     func loadURLWithCookie(url: URL) {
         var urlRequest = URLRequest(url: url)
-        let cookieHeader = Utils.getCookiesMobile()
-        urlRequest.addValue(cookieHeader, forHTTPHeaderField: "Cookie")
         let customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1 \(Utils.getUserAgent())"
         urlRequest.setValue(customUserAgent, forHTTPHeaderField: "User-Agent")
-        
-        if let cookies = HTTPCookieStorage.shared.cookies {
+        if let cookies = HTTPCookieStorage.shared.cookies(for: url) {
             for cookie in cookies {
                 webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie)
             }
+            webView.load(urlRequest)
         }
-        webView.load(urlRequest)
     }
     
     public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
@@ -406,12 +404,20 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
                 exit(0)
             }))
             self.present(alert, animated: true, completion: nil)
-        }  else if message.name == "finishForm" {
+        } else if message.name == "finishForm" {
             if self.webView.canGoBack {
                 self.webView.goBack()
             } else {
                 self.dismiss(animated: true)
             }
+        } else if message.name == "shareText" {
+            print("HMM masuk share text")
+            guard let dict = message.body as? [String: AnyObject],
+                  let param1 = dict["param1"] as? String else {
+                return
+            }
+            let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
+            self.present(activityViewController, animated: true, completion: nil)
         }
     }
     
@@ -580,20 +586,20 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
         sender.endRefreshing()
     }
     
-    public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
-        guard let serverTrust = challenge.protectionSpace.serverTrust else {
-            completionHandler(.cancelAuthenticationChallenge, nil)
-            return
-        }
-        if let serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0),
-           let pinnedCertificateHash = getCertificateHash(from: serverCertificate),
-           pinnedCertificateHash == Utils.getCertificatePinningWebview() {
-            let credential = URLCredential(trust: serverTrust)
-            completionHandler(.useCredential, credential) // Certificate matches, proceed
-        } else {
-            completionHandler(.cancelAuthenticationChallenge, nil) // Certificate doesn't match, cancel
-        }
-    }
+//    public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
+//        guard let serverTrust = challenge.protectionSpace.serverTrust else {
+//            completionHandler(.cancelAuthenticationChallenge, nil)
+//            return
+//        }
+//        if let serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0),
+//           let pinnedCertificateHash = getCertificateHash(from: serverCertificate),
+//           pinnedCertificateHash == Utils.getCertificatePinningWebview() {
+//            let credential = URLCredential(trust: serverTrust)
+//            completionHandler(.useCredential, credential) // Certificate matches, proceed
+//        } else {
+//            completionHandler(.cancelAuthenticationChallenge, nil) // Certificate doesn't match, cancel
+//        }
+//    }
     
     private func getCertificateHash(from certificate: SecCertificate) -> String? {
         guard let publicKey = getPublicKey(from: certificate) else { return nil }

+ 1 - 0
NexilisLite/NexilisLite/Source/View/Control/GroupDetailViewController.swift

@@ -1025,6 +1025,7 @@ extension GroupDetailViewController: ImageVideoPickerDelegate {
                                     print("Access database error: \(error.localizedDescription)")
                                 }
                             })
+                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
                         } else {
                             DispatchQueue.main.async {
                                 let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))

+ 3 - 2
NexilisLite/NexilisLite/Source/View/Control/ImageVideoPicker.swift

@@ -75,8 +75,9 @@ open class ImageVideoPicker: NSObject {
             let cancelButtonAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
             UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes , for: .normal)
         }
-        controller.dismiss(animated: false, completion: nil)
-        self.delegate?.didSelect(imagevideo: imagevideo)
+        controller.dismiss(animated: false, completion: {
+            self.delegate?.didSelect(imagevideo: imagevideo)
+        })
     }
 }
 

+ 52 - 51
NexilisLite/NexilisLite/Source/View/Control/ProfileViewController.swift

@@ -639,6 +639,7 @@ public class ProfileViewController: UITableViewController {
                                         } else if let editor = self.previousViewController as? EditorGroup {
                                             editor.afterUnfriend()
                                         }
+                                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
                                         self.navigationController?.popToRootViewController(animated: true)
                                     }
                                     Nexilis.shared.stateUnfriend = ""
@@ -741,63 +742,63 @@ extension ProfileViewController: ImageVideoPickerDelegate {
             guard let me = User.getMyPin() else {
                 return
             }
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
-                Nexilis.showLoader()
-                DispatchQueue.global().async {
-                    let resize = image.resize(target: CGSize(width: 800, height: 600))
-                    let documentDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
-                    let fileDir = documentDir.appendingPathComponent("THUMB_\(me)\(Date().currentTimeMillis().toHex())")
-                    if !FileManager.default.fileExists(atPath: fileDir.path), let data = resize.jpegData(compressionQuality: 0.8) {
-                        try! data.write(to: fileDir)
-                        Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress , response in
-                            guard result else {
-                                DispatchQueue.main.async {
-                                    Nexilis.hideLoader(completion: { [self] in
-                                        let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
-                                        imageView.tintColor = .white
-                                        publicBanner.dismiss()
-                                        publicBanner = FloatingNotificationBanner(title: "Can't change profile picture, try again later".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)
-                                        publicBanner.show()
-                                        self.dismissImage?(image, fileDir.lastPathComponent)
-                                    })
-                                }
-                                return
-                            }
-                            guard progress == 100 else {
-                                return
-                            }
-                            if let response = Nexilis.writeAndWait(message: CoreMessage_TMessageBank.getChangePersonImage(thumb_id: fileDir.lastPathComponent)), response.isOk() {
-                                Database.shared.database?.inTransaction({ fmdb, rollback in
-                                    do {
-                                        _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["image_id": fileDir.lastPathComponent], _where: "f_pin = '\(me)'")
-                                    } catch {
-                                        rollback.pointee = true
-                                        print("Access database error: \(error.localizedDescription)")
-                                    }
+            Nexilis.showLoader()
+            DispatchQueue.global().async {
+                let resize = image.resize(target: CGSize(width: 800, height: 600))
+                let documentDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
+                let data = resize.jpegData(compressionQuality: 0.8)
+                guard let data = data else { return }
+                let fileDir = documentDir.appendingPathComponent("THUMB_\(me)\(Date().currentTimeMillis().toHex()).jpg")
+                if !FileManager.default.fileExists(atPath: fileDir.path) {
+                    try! data.write(to: fileDir)
+                    Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress , response in
+                        guard result else {
+                            DispatchQueue.main.async {
+                                Nexilis.hideLoader(completion: { [self] in
+                                    let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
+                                    imageView.tintColor = .white
+                                    publicBanner.dismiss()
+                                    publicBanner = FloatingNotificationBanner(title: "Can't change profile picture, try again later".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)
+                                    publicBanner.show()
+                                    self.dismissImage?(image, fileDir.lastPathComponent)
                                 })
-                                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
-                                
-                                DispatchQueue.main.async {
-                                    Nexilis.hideLoader(completion: { [self] in
-                                        self.profile.image = image
-                                        let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
-                                        self.user?.thumb = fileDir.lastPathComponent
-                                        imageView.tintColor = .white
-                                        publicBanner.dismiss()
-                                        publicBanner = FloatingNotificationBanner(title: "Successfully changed profile picture".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
-                                        publicBanner.show()
-                                        self.dismissImage?(image, fileDir.lastPathComponent)
-                                    })
+                            }
+                            return
+                        }
+                        guard progress == 100 else {
+                            return
+                        }
+                        if let response = Nexilis.writeAndWait(message: CoreMessage_TMessageBank.getChangePersonImage(thumb_id: fileDir.lastPathComponent)), response.isOk() {
+                            Database.shared.database?.inTransaction({ fmdb, rollback in
+                                do {
+                                    _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["image_id": fileDir.lastPathComponent], _where: "f_pin = '\(me)'")
+                                } catch {
+                                    rollback.pointee = true
+                                    print("Access database error: \(error.localizedDescription)")
                                 }
-                            } else {
-                                Nexilis.hideLoader(completion: {})
+                            })
+                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
+                            
+                            DispatchQueue.main.async {
+                                Nexilis.hideLoader(completion: { [self] in
+                                    self.profile.image = image
+                                    let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
+                                    self.user?.thumb = fileDir.lastPathComponent
+                                    imageView.tintColor = .white
+                                    publicBanner.dismiss()
+                                    publicBanner = FloatingNotificationBanner(title: "Successfully changed profile picture".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
+                                    publicBanner.show()
+                                    self.dismissImage?(image, fileDir.lastPathComponent)
+                                })
                             }
+                        } else {
+                            Nexilis.hideLoader(completion: {})
                         }
-                    } else {
-                        Nexilis.hideLoader(completion: {})
                     }
+                } else {
+                    Nexilis.hideLoader(completion: {})
                 }
-            })
+            }
         }
     }
     

+ 2 - 2
NexilisLite/NexilisLite/Source/View/Control/SettingTableViewController.swift

@@ -132,7 +132,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
                                 Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
                                     Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
                                 Item(icon: UIImage(systemName: "lock"), title: "Secure Folder"),
-                                Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
+//                                Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
                             ]
                         }
                         if !isChangeProfile {
@@ -186,7 +186,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
                             Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
                                 Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
                             Item(icon: UIImage(systemName: "lock"), title: "Secure Folder"),
-                            Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
+//                            Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
                         ]
                         if Nexilis.showButtonFB {
                             Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))