Parcourir la source

update and fix bugs

alqindiirsyam il y a 5 mois
Parent
commit
d501ebded8

+ 5 - 1
AppBuilder/AppBuilder/FirstTabViewController.swift

@@ -237,7 +237,8 @@ class FirstTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
     }
 
     @objc func reloadWebView(_ sender: UIRefreshControl) {
-        webView.reload()
+        FirstTabViewController.forceRefresh = true
+        viewWillAppear(false)
         ViewController.alwaysHideButton = false
         showTabBar()
         sender.endRefreshing()
@@ -440,6 +441,9 @@ class FirstTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
                   let param1 = dict["param1"] as? String else {
                 return
             }
+            if loadingURL {
+                return
+            }
             let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
             self.present(activityViewController, animated: true, completion: nil)
         } else if message.name == "openGalleryiOS" {

+ 5 - 1
AppBuilder/AppBuilder/ThirdTabViewController.swift

@@ -256,7 +256,8 @@ class ThirdTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
     }
     
     @objc func reloadWebView(_ sender: UIRefreshControl) {
-        webView.reload()
+        ThirdTabViewController.forceRefresh = true
+        viewWillAppear(false)
         ViewController.alwaysHideButton = false
         showTabBar()
         sender.endRefreshing()
@@ -460,6 +461,9 @@ class ThirdTabViewController: UIViewController, UIScrollViewDelegate, UIGestureR
                   let param1 = dict["param1"] as? String else {
                 return
             }
+            if loadingURL {
+                return
+            }
             let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
             self.present(activityViewController, animated: true, completion: nil)
         } else if message.name == "openGalleryiOS" {

+ 12 - 0
AppBuilder/AppBuilder/ViewController.swift

@@ -267,6 +267,18 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
             checkCounter()
         })
         willappear()
+        let notificationName = "realtimeShareExtensionNexilis" as CFString
+
+        CFNotificationCenterAddObserver(
+            CFNotificationCenterGetDarwinNotifyCenter(),
+            nil,
+            { _, _, _, _, _ in
+                APIS.checkDataForShareExtension()
+            },
+            notificationName,
+            nil,
+            .deliverImmediately
+        )
 //        Nexilis.debugBroadcast()
     }
     

+ 32 - 0
AppBuilder/AppBuilderShare/ShareViewController.swift

@@ -161,6 +161,14 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
                     if let jsonString = String(data: jsonData, encoding: .utf8) {
                         userDefaults.set(jsonString, forKey: "sharedItem")
                         userDefaults.synchronize()
+                        let notificationName = "realtimeShareExtensionNexilis" as CFString
+                        CFNotificationCenterPostNotification(
+                            CFNotificationCenterGetDarwinNotifyCenter(),
+                            CFNotificationName(notificationName),
+                            nil,
+                            nil,
+                            true
+                        )
                     }
                 } else if typeShareNum == TypeShare.video {
                     let dataVideo = try? Data(contentsOf: selectedVideo)
@@ -211,12 +219,28 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
                     if let jsonString = String(data: jsonData, encoding: .utf8) {
                         userDefaults.set(jsonString, forKey: "sharedItem")
                         userDefaults.synchronize()
+                        let notificationName = "realtimeShareExtensionNexilis" as CFString
+                        CFNotificationCenterPostNotification(
+                            CFNotificationCenterGetDarwinNotifyCenter(),
+                            CFNotificationName(notificationName),
+                            nil,
+                            nil,
+                            true
+                        )
                     }
                 } else {
                     let jsonData = try JSONSerialization.data(withJSONObject: dataShared, options: .prettyPrinted)
                     if let jsonString = String(data: jsonData, encoding: .utf8) {
                         userDefaults.set(jsonString, forKey: "sharedItem")
                         userDefaults.synchronize()
+                        let notificationName = "realtimeShareExtensionNexilis" as CFString
+                        CFNotificationCenterPostNotification(
+                            CFNotificationCenterGetDarwinNotifyCenter(),
+                            CFNotificationName(notificationName),
+                            nil,
+                            nil,
+                            true
+                        )
                     }
                 }
             } catch {
@@ -249,6 +273,14 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
                     let userDefaults = UserDefaults(suiteName: "group.nexilis.share")
                     userDefaults!.set(jsonString, forKey: "sharedItem")
                     userDefaults!.synchronize()
+                    let notificationName = "realtimeShareExtensionNexilis" as CFString
+                    CFNotificationCenterPostNotification(
+                        CFNotificationCenterGetDarwinNotifyCenter(),
+                        CFNotificationName(notificationName),
+                        nil,
+                        nil,
+                        true
+                    )
                 }
             }
         } catch {

+ 18 - 14
NexilisLite/NexilisLite/Source/APIS.swift

@@ -876,21 +876,25 @@ public class APIS: NSObject {
                             }
                             if code == "CL01" {
                                 if let message = data["bodies"] as? [String: String] {
-                                    var messageExist = false
-                                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
-                                        if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message[CoreMessage_TMessageKey.MESSAGE_ID] ?? "")'"), cursor.next() {
-                                            messageExist = true
-                                            cursor.close()
-                                        }
-                                    })
-                                    if messageExist {
-                                        return
-                                    }
                                     let messageToSave = TMessage()
                                     messageToSave.mBodies = message
-                                    Nexilis.saveMessage(message: messageToSave, withStatus: false, fromAPNS: true)
-                                    DispatchQueue.global().async {
-                                        _ = Nexilis.write(message: CoreMessage_TMessageBank.getAckMessage(messageId: message[CoreMessage_TMessageKey.MESSAGE_ID] ?? ""))
+                                    do {
+                                        var messageExist = false
+                                        Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                                            if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message[CoreMessage_TMessageKey.MESSAGE_ID] ?? "")'"), cursor.next() {
+                                                messageExist = true
+                                                cursor.close()
+                                            }
+                                        })
+                                        if messageExist {
+                                            return
+                                        }
+                                        Nexilis.saveMessage(message: messageToSave, withStatus: false, fromAPNS: true)
+                                        DispatchQueue.global().async {
+                                            _ = Nexilis.write(message: CoreMessage_TMessageBank.getAckMessage(messageId: message[CoreMessage_TMessageKey.MESSAGE_ID] ?? ""))
+                                        }
+                                    } catch {
+                                        print("error saving message: \(error)")
                                     }
                                     APIS.addNotificationNexilis(messageToSave)
                                 }
@@ -1257,7 +1261,7 @@ public class APIS: NSObject {
         Nexilis.destroyAll()
     }
     
-    private static func checkDataForShareExtension() {
+    public static func checkDataForShareExtension() {
         DispatchQueue.global().async {
             if let userDefaults = UserDefaults(suiteName: "group.nexilis.share") {
                 if let value = userDefaults.string(forKey: "sharedItem") {

+ 15 - 12
NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -379,14 +379,14 @@ class IncomingThread {
         DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
             let onGoingCC: String = SecureUserDefaults.shared.value(forKey: "onGoingCC") ?? ""
             let channelCC: String = SecureUserDefaults.shared.value(forKey: "channelCC") ?? ""
-            if !onGoingCC.isEmpty && onGoingCC.components(separatedBy: ",").count < 3 {
+            if onGoingCC.isEmpty || channelCC.isEmpty || (!onGoingCC.isEmpty && onGoingCC.components(separatedBy: ",").count < 3) {
                 SecureUserDefaults.shared.removeValue(forKey: "onGoingCC")
                 SecureUserDefaults.shared.removeValue(forKey: "channelCC")
                 return
             }
-            let complaintId = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[2]
-            let fPinCC = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[1]
-            if fPinCC == User.getMyPin() || fPinCC.isEmpty || complaintId.isEmpty {
+            let complaintId = onGoingCC.components(separatedBy: ",")[2]
+            let fPinCC = onGoingCC.components(separatedBy: ",")[1]
+            if fPinCC == User.getMyPin() {
                 return
             }
             if channelCC == "1" {
@@ -1284,6 +1284,17 @@ class IncomingThread {
                 cursor.close()
             }
         })
+        DispatchQueue.main.async {
+            if APIS.checkAppStateisBackground() {
+                if !messageExist {
+                    let message_id = message.getBody(key: CoreMessage_TMessageKey.MESSAGE_ID)
+                    DispatchQueue.global().async {
+                        _ = Nexilis.write(message: CoreMessage_TMessageBank.getAckMessage(messageId: message_id))
+                    }
+                    APIS.addNotificationNexilis(message)
+                }
+            }
+        }
         let media = message.getMedia()
         //print("MEDIA \(media)");
         let thumb_id = message.getBody(key: CoreMessage_TMessageKey.THUMB_ID)
@@ -1306,19 +1317,11 @@ class IncomingThread {
         } else {
             Nexilis.saveMessage(message: message, withStatus: false)
         }
-        DispatchQueue.main.async {
-            if APIS.checkAppStateisBackground() {
-                if !messageExist {
-                    APIS.addNotificationNexilis(message)
-                }
-            }
-        }
         //print("save message incoming")
         ack(message: message)
     }
     
     private func receiveMessageStatus(message: TMessage) -> Void {
-        let message_id = message.getBody(key: CoreMessage_TMessageKey.MESSAGE_ID)
         guard let _: String = SecureUserDefaults.shared.value(forKey: "status") else {
             //print("App not ready!!! skip receive message \(message_id)")
             return

+ 9 - 8
NexilisLite/NexilisLite/Source/Network.swift

@@ -184,15 +184,15 @@ public class Network {
         }
     }
     
-    public func uploadHTTP(name: String, completion: @escaping (Bool, Double, [String:Any]?)->()) {
+    public func uploadHTTP(name: String, completion: @escaping (Bool, Double)->()) {
         _ = uploadHTTP(UPLOAD_URL, filename: [name], completion: completion)
     }
     
-    public func uploadHTTP(fileUrl: URL, completion: @escaping (Bool, Double, [String:Any]?)->()) {
+    public func uploadHTTP(fileUrl: URL, completion: @escaping (Bool, Double)->()) {
         _ = uploadHTTP(UPLOAD_URL, files: [fileUrl], completion: completion)
     }
     
-    public func uploadHTTP(_ endUrl: String, files: [URL] = [], filename: [String] = [], parameters: [String : Any] = [:], completion: @escaping (Bool, Double, [String:Any]?)->()) -> UploadRequest {
+    public func uploadHTTP(_ endUrl: String, files: [URL] = [], filename: [String] = [], parameters: [String : Any] = [:], completion: @escaping (Bool, Double)->()) -> UploadRequest {
         
         var filesIn = [URL]()
         var filesTempServer = [URL]()
@@ -218,6 +218,7 @@ public class Network {
                         let fileDirServer = tempDir.appendingPathComponent(filenameServer)
                         let fileURLServer = URL(fileURLWithPath: fileDirServer.path)
                         try FileEncryption.shared.encryptFile(fileURL, fileURLServer, MasterKeyUtil.shared.getServerKey())
+                        print("ADA KAN? \(fileURL) <><> \(fileURLServer)")
 //                        let dataSecure = try FileEncryption.shared.encryptFile(fileURL)
 //                        dataSecure?.write(to: fileURLSecure)
                         filesIn.append(fileURL)
@@ -260,25 +261,25 @@ public class Network {
             
         }, to: endUrl, headers: headers)
         .responseJSON { result in
-            if let response = result.response, response.statusCode == 200, let successResponse = result.value as? [String:Any] {
+            if let response = result.response, response.statusCode == 200 {
                 //print("Response success")
                 for url in filesTempServer {
                     Nexilis.removeUploadFile(forKey: url.lastPathComponent)
                 }
-                completion(true,100,successResponse)
+                completion(true,100)
                 
             }
             else {
                 let statusCode = result.response?.statusCode
-                //print("Response fail: \(statusCode)")
-                completion(false,0,nil)
+                print("Response fail: \(statusCode) <><> \(result)")
+                completion(false,0)
             }
         }
         .uploadProgress { progress in
             //print("Response progress: \(progress.fractionCompleted*100)")
             let frac = progress.fractionCompleted*100
             if frac != 100.0 {
-                completion(!progress.isCancelled,frac,nil)
+                completion(!progress.isCancelled,frac)
             }
         }
         

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

@@ -3704,9 +3704,9 @@ extension Nexilis: MessageDelegate {
                 if !onGoingCC.isEmpty {
                     return
                 }
-                if Utils.inTabChats{
-                    return
-                }
+//                if Utils.inTabChats{
+//                    return
+//                }
                 if message.getBody(key: messageScopeId) == "3" || message.getBody(key: messageScopeId) == "18" || message.getBody(key: messageScopeId) == "5" {
                     if inEditorPersonal == sender || (inEditorPersonal != nil && inEditorPersonal!.contains(",")) {
                         return
@@ -3917,7 +3917,6 @@ extension Nexilis: MessageDelegate {
                             profileImage.tintColor = .white
                         }
                         
-                        print("SHOW KAH?0")
                         floating.show(queuePosition: .front, bannerPosition: .top, queue: NotificationBannerQueue(maxBannersOnScreenSimultaneously: 1), on: nil, edgeInsets: UIEdgeInsets(top: 8.0, left: 8.0, bottom: 0, right: 8.0), cornerRadius: 8.0, shadowColor: .clear, shadowOpacity: .zero, shadowBlurRadius: .zero, shadowCornerRadius: .zero, shadowOffset: .zero, shadowEdgeInsets: nil)
     //                    let vibrateMode: Bool = SecureUserDefaults.shared.value(forKey: "vibrateMode") ?? false
                         var soundId: String = SecureUserDefaults.shared.value(forKey: "newNotifSoundPersonal") ?? "001:Nexilis Message (Default)"

+ 16 - 5
NexilisLite/NexilisLite/Source/OutgoingThread.swift

@@ -163,7 +163,7 @@ class OutgoingThread {
                 maxRetryUploadTime[message.getBody(key: CoreMessage_TMessageKey.MESSAGE_ID)] = Date().currentTimeMillis()
             }
             if (!message.getBody(key: CoreMessage_TMessageKey.THUMB_ID).isEmpty) {
-                Network().uploadHTTP(name: message.getBody(key: CoreMessage_TMessageKey.THUMB_ID)) { (result, progress, response) in
+                Network().uploadHTTP(name: message.getBody(key: CoreMessage_TMessageKey.THUMB_ID)) { (result, progress) in
                     if result, progress == 100 {
                         do {
                             let fileManager = FileManager.default
@@ -175,12 +175,11 @@ class OutgoingThread {
                                 message.setMedia(media: [UInt8] (data))
                             }
                         } catch {}
-                        Network().uploadHTTP(name: fileName) { (result, progress, response) in
+                        Network().uploadHTTP(name: fileName) { (result, progress) in
                             if result {
                                 if let delegate = Nexilis.shared.messageDelegate {
                                     delegate.onUpload(name: fileName, progress: progress)
                                 }
-                                print("progress upload", progress)
                                 if progress == 100 {
                                     if let response = Nexilis.writeSync(message: message) {
                                         print("sendChat", response.toLogString())
@@ -202,21 +201,24 @@ class OutgoingThread {
                                             
                                         }
                                     } else {
+                                        print("masuk 1")
                                         self.retryUpload(message: message, fileName: fileName)
                                     }
                                 }
                             } else {
+                                print("masuk 2")
                                 self.retryUpload(message: message, fileName: fileName)
                             }
                         }
                     } else {
+                        print("masuk 3")
                         if !result {
                             self.retryUpload(message: message, fileName: fileName)
                         }
                     }
                 }
             } else {
-                Network().uploadHTTP(name: fileName) { (result, progress, response) in
+                Network().uploadHTTP(name: fileName) { (result, progress) in
                     if result {
                         if let delegate = Nexilis.shared.messageDelegate {
                             delegate.onUpload(name: fileName, progress: progress)
@@ -346,7 +348,16 @@ class OutgoingThread {
                     }
                 }
                 //print("retry sukses")
-                sendChat(message: message)
+                var messageExist = false
+                Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                    if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message.getBody(key: CoreMessage_TMessageKey.MESSAGE_ID))'"), cursor.next() {
+                        messageExist = true
+                        cursor.close()
+                    }
+                })
+                if messageExist {
+                    sendChat(message: message)
+                }
             })
         }
     }

+ 9 - 0
NexilisLite/NexilisLite/Source/View/BNIView/BNIBookingWebView.swift

@@ -31,6 +31,7 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
     var imageVideoPicker: ImageVideoPicker!
     var blockedCertificate = ""
     var allowedURLs = Set<String>()
+    var loadingURL = false
     
     public override var preferredStatusBarStyle: UIStatusBarStyle {
         return .default
@@ -473,6 +474,9 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
                   let param1 = dict["param1"] as? String else {
                 return
             }
+            if loadingURL {
+                return
+            }
             let activityViewController = UIActivityViewController(activityItems: [param1], applicationActivities: nil)
             self.present(activityViewController, animated: true, completion: nil)
         }  else if message.name == "openGalleryiOS" {
@@ -752,6 +756,11 @@ public class BNIBookingWebView: UIViewController, WKNavigationDelegate, UIScroll
             decisionHandler(.cancel)
             return
         }
+        if loadingURL {
+            decisionHandler(.cancel)
+            return
+        }
+        loadingURL = true
         if allowedURLs.contains(url.absoluteString) {
             print("✅ URL already allowed: \(url)")
             decisionHandler(.allow)

+ 71 - 75
NexilisLite/NexilisLite/Source/View/Call/QmeraVideoViewController.swift

@@ -1004,12 +1004,14 @@ class QmeraVideoViewController: UIViewController {
     }
     
     @objc func camera(sender: Any?) {
-        if frontCamera {
-            API.changeCameraParam(nCameraIdx: 0, nResolutionIndex: 2, nQuality: 4)
-            frontCamera = false
-        } else {
-            API.changeCameraParam(nCameraIdx: 1, nResolutionIndex: 2, nQuality: 4)
-            frontCamera = true
+        DispatchQueue.global().async { [self] in
+            if frontCamera {
+                API.changeCameraParam(nCameraIdx: 0, nResolutionIndex: 2, nQuality: 4)
+                frontCamera = false
+            } else {
+                API.changeCameraParam(nCameraIdx: 1, nResolutionIndex: 2, nQuality: 4)
+                frontCamera = true
+            }
         }
     }
     
@@ -1066,21 +1068,11 @@ class QmeraVideoViewController: UIViewController {
                 }
             }
         }
-        else if(state == Nexilis.VIDEO_CALL_ZOOM){
-            DispatchQueue.main.async {
-                if self.dataPerson.count > 1 {
-                    if !self.transformZoomAfterNewUserMore2 {
-                        self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (CGFloat.pi * 3)/2)
-                        self.transformZoomAfterNewUserMore2 = true
-                    }
-                }
-            }
-        }
         else if (state == Nexilis.VIDEO_CAMERA_PARAMS_CHANED){
             if(arrayMessage[3] == "0"){
                 DispatchQueue.main.async {
                     if self.dataPerson.count == 1 && arrayMessage[2] == "1" && arrayMessage[4] == "1" {
-                        self.zoomView.transform = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (CGFloat.pi * 3)/2)
+                        self.zoomView.transform = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
                     } else {
                         self.zoomView.transform = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (CGFloat.pi)/2)
                     }
@@ -1106,13 +1098,13 @@ class QmeraVideoViewController: UIViewController {
                             if self.dataPerson[0]["user_type"] == "2" {
                                 self.listRemoteViewFix[0].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
                             } else {
-                                self.listRemoteViewFix[0].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi * 3 )/2)
+                                self.listRemoteViewFix[0].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (-CGFloat.pi)/2)
                             }
                         } else {
                             if arrayMessage[5] == "2" {
                                 self.listRemoteViewFix[1].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
                             } else {
-                                self.listRemoteViewFix[1].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi * 3 )/2)
+                                self.listRemoteViewFix[1].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (-CGFloat.pi)/2)
                             }
                         }
                         let pictureImage = self.dataPerson[i]["picture"] ?? ""
@@ -1148,66 +1140,70 @@ class QmeraVideoViewController: UIViewController {
                         }
                     }
                 } else if self.dataPerson.count > 1 {
-                    if self.dataPerson.firstIndex(where: {$0["f_pin"]!! == arrayMessage[1]}) != nil {
-                        return
-                    }
-                    self.getDataProfile(fPin: String(arrayMessage[1]))
-                    let i = self.dataPerson.count - 1
-                    self.scrollRemoteView.addSubview(self.listRemoteViewFix[i])
-                    self.listRemoteViewFix[i].frame = CGRect(x: 0, y: 170 * i, width: 120, height: 160)
-                    self.listRemoteViewFix[i].backgroundColor = .clear
-                    self.listRemoteViewFix[i].makeRoundedView(radius: 8.0)
-                    self.scrollRemoteView.addSubview(self.containerLabelName[i])
-                    self.containerLabelName[i].frame = CGRect(x: 0, y: 170 * i, width: 120, height: 30)
-                    self.containerLabelName[i].backgroundColor = .orangeBNI.withAlphaComponent(0.5)
-                    self.containerLabelName[i].makeRoundedView(radius: 8.0)
-                    if arrayMessage[5] == "2" {
-                        self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
-                    } else {
-                        self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi * 3 )/2)
-                    }
-                    let pictureImage = self.dataPerson[self.dataPerson.count - 1]["picture"] ?? ""
-                    let namePerson = self.dataPerson[self.dataPerson.count - 1]["name"] ?? ""
-                    if (!pictureImage!.isEmpty) {
-                        self.listRemoteViewFix[i].setImage(name: pictureImage!)
-                        self.listRemoteViewFix[i].contentMode = .scaleAspectFill
-                    } else {
-                        self.listRemoteViewFix[i].image = UIImage(systemName: "person")
-                        self.listRemoteViewFix[i].backgroundColor = UIColor.systemGray6
-                        self.listRemoteViewFix[i].contentMode = .scaleAspectFit
+                    if self.dataPerson.firstIndex(where: {$0["f_pin"]!! == arrayMessage[1]}) == nil {
+                        self.getDataProfile(fPin: String(arrayMessage[1]))
+                        let i = self.dataPerson.count - 1
+                        self.scrollRemoteView.addSubview(self.listRemoteViewFix[i])
+                        self.listRemoteViewFix[i].frame = CGRect(x: 0, y: 170 * i, width: 120, height: 160)
+                        self.listRemoteViewFix[i].backgroundColor = .clear
+                        self.listRemoteViewFix[i].makeRoundedView(radius: 8.0)
+                        self.scrollRemoteView.addSubview(self.containerLabelName[i])
+                        self.containerLabelName[i].frame = CGRect(x: 0, y: 170 * i, width: 120, height: 30)
+                        self.containerLabelName[i].backgroundColor = .orangeBNI.withAlphaComponent(0.5)
+                        self.containerLabelName[i].makeRoundedView(radius: 8.0)
+                        if arrayMessage[5] == "2" {
+                            self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
+                        } else {
+                            self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (-CGFloat.pi)/2)
+                        }
+                        let pictureImage = self.dataPerson[self.dataPerson.count - 1]["picture"] ?? ""
+                        let namePerson = self.dataPerson[self.dataPerson.count - 1]["name"] ?? ""
+                        if (!pictureImage!.isEmpty) {
+                            self.listRemoteViewFix[i].setImage(name: pictureImage!)
+                            self.listRemoteViewFix[i].contentMode = .scaleAspectFill
+                        } else {
+                            self.listRemoteViewFix[i].image = UIImage(systemName: "person")
+                            self.listRemoteViewFix[i].backgroundColor = UIColor.systemGray6
+                            self.listRemoteViewFix[i].contentMode = .scaleAspectFit
+                        }
+                        self.scrollRemoteView.contentSize.height = CGFloat(170 * (i + 1))
+                        let labelName = UILabel()
+                        self.containerLabelName[i].addSubview(labelName)
+                        labelName.anchor(left: self.containerLabelName[i].leftAnchor, right: self.containerLabelName[i].rightAnchor, paddingLeft: 5, paddingRight: 5, centerX: self.containerLabelName[i].centerXAnchor, centerY: self.containerLabelName[i].centerYAnchor)
+                        labelName.text = namePerson
+                        labelName.textAlignment = .center
+                        labelName.textColor = .white
                     }
-                    self.scrollRemoteView.contentSize.height = CGFloat(170 * (i + 1))
-                    let labelName = UILabel()
-                    self.containerLabelName[i].addSubview(labelName)
-                    labelName.anchor(left: self.containerLabelName[i].leftAnchor, right: self.containerLabelName[i].rightAnchor, paddingLeft: 5, paddingRight: 5, centerX: self.containerLabelName[i].centerXAnchor, centerY: self.containerLabelName[i].centerYAnchor)
-                    labelName.text = namePerson
-                    labelName.textAlignment = .center
-                    labelName.textColor = .white
                 }
-            }
-            if users.count >= 1, let user = User.getData(pin: String(arrayMessage[1])), !users.contains(user) {
-                self.users.append(user)
-            }
-            if arrayMessage[5] == "2" && self.dataPerson.count == 1 {
-                DispatchQueue.main.async {
-                    self.zoomView.transform   = CGAffineTransform.init(scaleX: -1.9, y: 2.2).rotated(by: (CGFloat.pi)/2)
-                    self.zoomView.contentMode = .scaleAspectFit
+                
+                if self.users.count >= 1, let user = User.getData(pin: String(arrayMessage[1])), !self.users.contains(user) {
+                    self.users.append(user)
                 }
-            }
-            else if self.dataPerson.count == 1 {
-                DispatchQueue.main.async {
-                    self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (CGFloat.pi * 3)/2)
-                    self.zoomView.contentMode = .scaleAspectFit
+                if arrayMessage[5] == "2" && self.dataPerson.count == 1 {
+                    print("masuk 1")
+                    DispatchQueue.main.async {
+                        self.zoomView.transform   = CGAffineTransform.init(scaleX: -1.9, y: 2.2).rotated(by: (CGFloat.pi)/2)
+                        self.zoomView.contentMode = .scaleAspectFit
+                    }
                 }
-            } else if self.dataPerson.count > 1 {
-                DispatchQueue.main.async {
-                    for i in 0..<self.dataPerson.count {
-//                        self.listRemoteViewFix[i].image = self.listRemoteViewFix[i].image?.rotate(radians: (CGFloat.pi * 3 )/2)
-                        self.listRemoteViewFix[i].image = nil
-                        if self.dataPerson[i]["user_type"] == "2" || arrayMessage[5] == "2" {
-                            self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
-                        } else {
-                            self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi * 3 )/2)
+                else if self.dataPerson.count == 1 {
+                    print("masuk 2")
+                    DispatchQueue.main.async {
+                        self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
+                        self.zoomView.contentMode = .scaleAspectFit
+                    }
+                } else if self.dataPerson.count > 1 {
+                    print("masuk 3")
+                    DispatchQueue.main.async {
+                        self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
+                        self.zoomView.contentMode = .scaleAspectFit
+                        for i in 0..<self.dataPerson.count {
+                            self.listRemoteViewFix[i].image = nil
+                            if self.dataPerson[i]["user_type"] == "2" || arrayMessage[5] == "2" {
+                                self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (CGFloat.pi)/2)
+                            } else {
+                                self.listRemoteViewFix[i].transform = CGAffineTransform.init(scaleX: 1.4, y: 1.3).rotated(by: (-CGFloat.pi)/2)
+                            }
                         }
                     }
                 }

+ 29 - 22
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -116,19 +116,24 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
     
     public override func viewDidDisappear(_ animated: Bool) {
         if self.isMovingFromParent {
-            SecureUserDefaults.shared.removeValue(forKey: "inEditorGroup")
-            NotificationCenter.default.removeObserver(self)
-            super.viewDidDisappear(true)
-            self.removeFromParent()
-            self.dismiss(animated: true, completion: nil)
-            var l_pin = self.dataGroup["group_id"]  as? String ?? ""
-            if (self.dataTopic["chat_id"]  as? String ?? "" != "") {
-                l_pin = self.dataTopic["chat_id"]  as? String ?? ""
-            }
-            SecureUserDefaults.shared.set("\(textFieldSend.textColor != UIColor.lightGray ? textFieldSend.text! : ""),\(reffId ?? "")", forKey: "saved_\(l_pin)")
+            removeAllObjectBeforeDismissVC()
         }
     }
     
+    private func removeAllObjectBeforeDismissVC() {
+        for timer in self.timerCredential.values {
+            timer.invalidate()
+        }
+        SecureUserDefaults.shared.removeValue(forKey: "inEditorGroup")
+        NotificationCenter.default.removeObserver(self)
+        self.removeFromParent()
+        var l_pin = self.dataGroup["group_id"]  as? String ?? ""
+        if (self.dataTopic["chat_id"]  as? String ?? "" != "") {
+            l_pin = self.dataTopic["chat_id"]  as? String ?? ""
+        }
+        SecureUserDefaults.shared.set("\(textFieldSend.textColor != UIColor.lightGray ? textFieldSend.text! : ""),\(reffId ?? "")", forKey: "saved_\(l_pin)")
+    }
+    
     public override func viewDidAppear(_ animated: Bool) {
         let navBarAppearance = UINavigationBarAppearance()
         navBarAppearance.configureWithOpaqueBackground()
@@ -429,21 +434,25 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
                 DispatchQueue.main.async {
                     let section = self.dataDates.firstIndex(of: self.referenceChatDate)
                     let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == self.referenceChatDate}).firstIndex(where: { $0["message_id"] as? String == self.referenceMessageId})
-                    let indexPath = IndexPath(row: row!, section: section!)
-                    self.tableChatView.scrollToRow(at: indexPath, at: .middle, animated: false)
-                    self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .yellow
-                    DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
-                        self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .clear
-                    })
+                    if row != nil && section != nil {
+                        let indexPath = IndexPath(row: row!, section: section!)
+                        self.tableChatView.scrollToRow(at: indexPath, at: .middle, animated: false)
+                        self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .yellow
+                        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
+                            self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .clear
+                        })
+                    }
                 }
             }
         } else if counter != 0 {
             if dataMessages.firstIndex(where: {$0["message_id"] as? String == markerCounter} ) != 0 {
                 DispatchQueue.main.async {
                     let data = self.dataMessages.filter({ $0["message_id"] as? String == self.markerCounter })
-                    let section = self.dataDates.firstIndex(of: data[0]["chat_date"]  as? String ?? "")
-                    let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == data[0]["chat_date"]  as? String ?? ""}).firstIndex(where: { $0["message_id"] as? String == self.markerCounter})
-                    self.tableChatView.scrollToRow(at: IndexPath(row: row!, section: section!), at: .bottom, animated: false)
+                    if data.count > 0 {
+                        let section = self.dataDates.firstIndex(of: data[0]["chat_date"]  as? String ?? "")
+                        let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == data[0]["chat_date"]  as? String ?? ""}).firstIndex(where: { $0["message_id"] as? String == self.markerCounter})
+                        self.tableChatView.scrollToRow(at: IndexPath(row: row!, section: section!), at: .bottom, animated: false)
+                    }
                 }
             } else {
                 tableChatView.scrollToTop()
@@ -1530,9 +1539,7 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
     }
     
     @objc func didTapExit() {
-        SecureUserDefaults.shared.removeValue(forKey: "inEditorGroup")
-        NotificationCenter.default.removeObserver(self)
-        self.dismiss(animated: true, completion: nil)
+        removeAllObjectBeforeDismissVC()
     }
     
     @objc func profilePersonTapped(_ sender: ObjectGesture) {

+ 13 - 9
NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -572,21 +572,25 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                     DispatchQueue.main.async {
                         let section = self.dataDates.firstIndex(of: self.referenceChatDate)
                         let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == self.referenceChatDate}).firstIndex(where: { $0["message_id"] as? String == self.referenceMessageId})
-                        let indexPath = IndexPath(row: row!, section: section!)
-                        self.tableChatView.scrollToRow(at: indexPath, at: .middle, animated: false)
-                        self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .yellow
-                        DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
-                            self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .clear
-                        })
+                        if row != nil && section != nil {
+                            let indexPath = IndexPath(row: row!, section: section!)
+                            self.tableChatView.scrollToRow(at: indexPath, at: .middle, animated: false)
+                            self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .yellow
+                            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
+                                self.tableChatView.cellForRow(at: indexPath)?.contentView.backgroundColor = .clear
+                            })
+                        }
                     }
                 }
             } else if counter != 0 && dataMessages.count >= counter {
                 if dataMessages.firstIndex(where: {$0["message_id"] as? String == markerCounter} ) != 0 {
                     DispatchQueue.main.async {
                         let data = self.dataMessages.filter({ $0["message_id"] as? String == self.markerCounter })
-                        let section = self.dataDates.firstIndex(of: data[0]["chat_date"]  as? String ?? "")
-                        let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == data[0]["chat_date"]  as? String ?? ""}).firstIndex(where: { $0["message_id"] as? String == self.markerCounter})
-                        self.tableChatView.scrollToRow(at: IndexPath(row: row!, section: section!), at: .bottom, animated: false)
+                        if data.count > 0 {
+                            let section = self.dataDates.firstIndex(of: data[0]["chat_date"]  as? String ?? "")
+                            let row = self.dataMessages.filter({$0["chat_date"]  as? String ?? "" == data[0]["chat_date"]  as? String ?? ""}).firstIndex(where: { $0["message_id"] as? String == self.markerCounter})
+                            self.tableChatView.scrollToRow(at: IndexPath(row: row!, section: section!), at: .bottom, animated: false)
+                        }
                     }
                 } else {
                     tableChatView.scrollToTop()

+ 1 - 1
NexilisLite/NexilisLite/Source/View/Control/BackupRestoreView.swift

@@ -886,7 +886,7 @@ public class BackupRestoreView: UIViewController, UITableViewDataSource, UITable
                         //print("Adding entry to ZIP archive failed with error:\(error)")
                     }
                     self.labelPreparing.text = "Uploading...".localized()
-                    Network().uploadHTTP(fileUrl: zipFiles, completion: { result,progress,response in
+                    Network().uploadHTTP(fileUrl: zipFiles, completion: { result,progress in
                         if result {
                             DispatchQueue.main.async { [self] in
                                 labelPreparing.text = "Uploading...".localized() + " \(progress)%"

+ 3 - 3
NexilisLite/NexilisLite/Source/View/Control/BroadcastViewController.swift

@@ -409,10 +409,10 @@ class BroadcastViewController: UITableViewController, UITextFieldDelegate, UITex
             clearAttachment()
         }
         if !thumbId.isEmpty {
-            Network().uploadHTTP(name: String(thumbId)) { (result1, progress, response1) in
+            Network().uploadHTTP(name: String(thumbId)) { (result1, progress) in
                 if result1 {
                     if progress == 100 {
-                        Network().uploadHTTP(name: String(self.fileId)) { (result2, progress, response2) in
+                        Network().uploadHTTP(name: String(self.fileId)) { (result2, progress) in
                             if result2 {
                                 if progress == 100 {
                                     self.sendMsg(startTime: startTime, endTime: endTime)
@@ -428,7 +428,7 @@ class BroadcastViewController: UITableViewController, UITextFieldDelegate, UITex
                 }
             }
         } else if !fileId.isEmpty {
-            Network().uploadHTTP(name: String(fileId)) { (result2, progress, response2) in
+            Network().uploadHTTP(name: String(fileId)) { (result2, progress) in
                 if result2 {
                     if progress == 100 {
                         self.sendMsg(startTime: startTime, endTime: endTime)

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

@@ -1059,7 +1059,7 @@ extension GroupDetailViewController: ImageVideoPickerDelegate {
                     DispatchQueue.main.async {
                         Nexilis.showLoader()
                     }
-                    Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress , response in
+                    Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress in
                         guard result, progress == 100 else {
                             return
                         }

+ 1 - 1
NexilisLite/NexilisLite/Source/View/Control/ProfileViewController.swift

@@ -871,7 +871,7 @@ extension ProfileViewController: ImageVideoPickerDelegate {
                 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
+                    Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress in
                         guard result else {
                             DispatchQueue.main.async {
                                 Nexilis.hideLoader(completion: { [self] in