Pārlūkot izejas kodu

update fix bugs

alqindiirsyam 6 mēneši atpakaļ
vecāks
revīzija
70c6d6f5ae

+ 2 - 2
AppBuilder/AppBuilder.xcodeproj/project.pbxproj

@@ -463,7 +463,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 5.0.3;
+				MARKETING_VERSION = 5.0.3f;
 				PRODUCT_BUNDLE_IDENTIFIER = io.newuniverse.AppBuilder;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
@@ -499,7 +499,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 5.0.3;
+				MARKETING_VERSION = 5.0.3f;
 				PRODUCT_BUNDLE_IDENTIFIER = io.newuniverse.AppBuilder;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";

+ 1 - 0
AppBuilder/AppBuilder/SceneDelegate.swift

@@ -84,6 +84,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
     func sceneDidBecomeActive(_ scene: UIScene) {
         // Called when the scene has moved from an inactive state to an active state.
         // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
+        APIS.enterForeground()
     }
 
     func sceneWillResignActive(_ scene: UIScene) {

+ 0 - 1
AppBuilder/AppBuilder/ViewController.swift

@@ -369,7 +369,6 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
                 cursor.close()
             }
         })
-        UIApplication.shared.applicationIconBadgeNumber = Int(counter ?? 0)
         return counter ?? 0
     }
 

+ 141 - 114
NexilisLite/NexilisLite/Source/APIS.swift

@@ -833,120 +833,37 @@ public class APIS: NSObject {
 //            }
 //        }
         if checkAppStateisBackground() {
-            do {
-                let id = Utils.getConnectionID()
-                try API.initConnection(bSwitchIP: false, sAPIK: Nexilis.sAPIKey, aAppMain: nil, cbiI: Callback(), sTCPAddr: Nexilis.ADDRESS, nTCPPort: Nexilis.PORT, sUserID: id, sStartWH: "09:00")
-            } catch {
-                
-            }
             DispatchQueue.main.async {
-                while (!API.bnuSDKServiceReady() || API.nGetCLXConnState() == 0) {
-                    Thread.sleep(forTimeInterval: 1)
-                }
                 if let payload = userInfo["payload"] as? [String: Any] {
                     if let messagePayload = payload["message"] as? [String: Any] {
                         if let data = messagePayload["data"] as? [String: Any] {
                             let code = data["nx_code"] as? String ?? ""
+//                            if API.nGetCLXConnState() == 0 {
+//                                do {
+//                                    let id = Utils.getConnectionID()
+//                                    try API.initConnection(bSwitchIP: false, sAPIK: Nexilis.sAPIKey, aAppMain: nil, cbiI: Callback(), sTCPAddr: Nexilis.ADDRESS, nTCPPort: Nexilis.PORT, sUserID: id, sStartWH: "09:00")
+//                                } catch {
+//
+//                                }
+//                                while (!API.bnuSDKServiceReady() || API.nGetCLXConnState() == 0) {
+//                                    Thread.sleep(forTimeInterval: 1)
+//                                }
+//                            }
                             if code == "CL01" {
                                 if let message = data["bodies"] as? [String: String] {
                                     let messageToSave = TMessage()
                                     messageToSave.mBodies = message
-                                    Nexilis.saveMessage(message: messageToSave, withStatus: false, fromAPNS: true)
-                                    _ = Nexilis.write(message: CoreMessage_TMessageBank.getAckMessage(messageId: message[CoreMessage_TMessageKey.MESSAGE_ID] ?? ""))
-                                    var text = message[CoreMessage_TMessageKey.MESSAGE_TEXT] ?? ""
-                                    text = text.toNormalString()
-                                    let nameUser = message[CoreMessage_TMessageKey.F_DISPLAY_NAME] ?? ""
-                                    let threadIdentifier = message[CoreMessage_TMessageKey.OPPOSITE_PIN] ?? ""
-                                    var nameSubtitle = ""
-                                    let imageId = CoreMessage_TMessageKey.IMAGE_ID
-                                    let videoId = CoreMessage_TMessageKey.VIDEO_ID
-                                    let fileId = CoreMessage_TMessageKey.FILE_ID
-                                    let audioId = CoreMessage_TMessageKey.AUDIO_ID
-                                    let attachmentFlag = CoreMessage_TMessageKey.ATTACHMENT_FLAG
-                                    let messageScopeId = CoreMessage_TMessageKey.MESSAGE_SCOPE_ID
-                                    let credential = CoreMessage_TMessageKey.CREDENTIAL
-                                    let gif_id = CoreMessage_TMessageKey.GIF_ID
-                                    let is_secret = CoreMessage_TMessageKey.IS_SECRET
-                                    if (message[is_secret] ?? "") == "1" {
-                                      text = "You got messages..."
-                                    } else if (message[gif_id] ?? "") != "" {
-                                      text = "Sent GIF 🎬"
-                                    } else if !(message[imageId] ?? "").isEmpty {
-                                        text = "Sent Image 📷"
-                                    } else if (message[attachmentFlag] ?? "") == "11" {
-                                        text = "Sent Sticker ❤️"
-                                    } else if !(message[videoId] ?? "").isEmpty {
-                                        text = "Sent Video 📹"
-                                    } else if !(message[fileId] ?? "").isEmpty {
-                                        if (message[messageScopeId] ?? "") == "18" {
-                                            text = "Sent Form 📄"
-                                        } else {
-                                            text = "Sent File 📄"
-                                        }
-                                    } else if !(message[audioId] ?? "").isEmpty {
-                                        text = "Sent Audio ♫"
-                                    } else if text.contains("Share%20location%20") {
-                                        text = "Sent Location 📌"
-                                    } else if (message[attachmentFlag] ?? "") == "27" {
-                                        text = "Sent Live Streaming"
-                                    } else if (message[attachmentFlag] ?? "") == "26" {
-                                        text = "Sent Seminar"
-                                    } else if (message[attachmentFlag] ?? "") == "25" {
-                                        text = "Sent Video Conference Room"
-                                    } else if (message[attachmentFlag] ?? "") == "24" {
-                                        text = "Sent Quiz"
-                                    } else if (message[credential] ?? "") == "1" {
-                                        text = "Sent Confidential Message"
-                                    }
-                                    let center = UNUserNotificationCenter.current()
-                                    let content = UNMutableNotificationContent()
-                                    content.title = nameUser
-                                    content.body = text
-                                    content.sound = .default
-                                    var type = "1"
-                                    if (message[messageScopeId] ?? "") == "3" || (message[messageScopeId] ?? "") == "18" || (message[messageScopeId] ?? "") == "5"{
-                                        type = "0"
-                                    }
-                                    var nameTopic = "Lounge".localized()
-                                    var idGroup = ""
-                                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
-                                        do {
-                                            if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT title, group_id FROM DISCUSSION_FORUM WHERE chat_id='\(threadIdentifier)'"), cursor.next() {
-                                                nameTopic = cursor.string(forColumnIndex: 0) ?? ""
-                                                idGroup = cursor.string(forColumnIndex: 1) ?? ""
-                                                cursor.close()
-                                            }
-                                            if idGroup.isEmpty {
-                                                idGroup = threadIdentifier
-                                            }
-                                            if let cursorGroup = Database.shared.getRecords(fmdb: fmdb, query: "SELECT f_name, image_id FROM GROUPZ WHERE group_id='\(idGroup)'"), cursorGroup.next() {
-                                                let nameGroup = cursorGroup.string(forColumnIndex: 0) ?? ""
-                                                nameSubtitle = "\(nameGroup)(\(nameTopic))"
-                                                cursorGroup.close()
-                                            }
-                                        } catch {
-                                            rollback.pointee = true
-                                            print("Access database error: \(error.localizedDescription)")
-                                        }
-                                    })
-                                    if type == "1" {
-                                        content.subtitle = nameSubtitle
-                                    }
-                                    content.userInfo = ["id" : threadIdentifier, "type" : type]
-                                    content.sound = UNNotificationSound(named: UNNotificationSoundName("pb_call_in.mp3"))
-                                    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
-                                    let request = UNNotificationRequest(identifier: threadIdentifier, content: content, trigger: trigger)
-                                    center.add(request) { error in
-                                        if let error = error {
-                                            print("Error scheduling notification: \(error.localizedDescription)")
-                                        }
-                                    }
+//                                    Nexilis.saveMessage(message: messageToSave, withStatus: false, fromAPNS: true)
+//                                    DispatchQueue.global().async {
+//                                        _ = Nexilis.write(message: CoreMessage_TMessageBank.getAckMessage(messageId: message[CoreMessage_TMessageKey.MESSAGE_ID] ?? ""))
+//                                    }
+                                    addNotificationNexilis(messageToSave)
                                 }
                             } else if code == "CL03" {
                                 let callFromName = data["call-from-name"] as? String ?? ""
                                 let callFrom = data["call-from"] as? String ?? ""
                                 let callType = data["call-type"] as? String ?? ""
-                                uuidCall = UUID()
+//                                uuidCall = UUID()
                                 fpinCall = callFrom
                                 Nexilis.callAPNActivated = true
     //                                    CallManager.shared.reportIncomingCall(uuid: uuidCall!, callerName: callFromName, callerId: callFrom, isVideo: callType != "1") { error in
@@ -968,20 +885,20 @@ public class APIS: NSObject {
                                 content.userInfo = ["id" : callFrom, "type" : code, "callType": callType]
                                 content.sound = UNNotificationSound(named: UNNotificationSoundName("pb_call_in.mp3"))
                                 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
-                                let request = UNNotificationRequest(identifier: "\(uuidCall!)", content: content, trigger: trigger)
+                                let request = UNNotificationRequest(identifier: callFrom, content: content, trigger: trigger)
                                 center.add(request) { error in
                                     if let error = error {
                                         print("Error scheduling notification: \(error.localizedDescription)")
                                     }
                                 }
                             } else if code == "CL02" {
-                                if let uuidCall = uuidCall {
+                                let callFrom = data["call-from"] as? String ?? ""
+//                                if let uuidCall = uuidCall {
                                     Nexilis.callAPNActivated = false
                                     let center = UNUserNotificationCenter.current()
-                                    center.removePendingNotificationRequests(withIdentifiers: ["\(uuidCall)"])
-                                    center.removeDeliveredNotifications(withIdentifiers: ["\(uuidCall)"])
+                                    center.removeDeliveredNotifications(withIdentifiers: [callFrom])
     //                                    CallManager.shared.endCall(with: uuidCall)
-                                }
+//                                }
                             }
                         }
                     }
@@ -990,6 +907,114 @@ public class APIS: NSObject {
         }
     }
     
+    public static func addNotificationNexilis(_ message: TMessage) {
+        var text = message.getBody(key: CoreMessage_TMessageKey.MESSAGE_TEXT)
+        text = text.toNormalString()
+        let nameUser = message.getBody(key: CoreMessage_TMessageKey.F_DISPLAY_NAME)
+        var threadIdentifier = message.getBody(key: CoreMessage_TMessageKey.OPPOSITE_PIN)
+        let scope = message.getBody(key: CoreMessage_TMessageKey.MESSAGE_SCOPE_ID)
+        if threadIdentifier.isEmpty {
+            if scope == "4" {
+                threadIdentifier = message.getBody(key: CoreMessage_TMessageKey.CHAT_ID).isEmpty ? message.getBody(key: CoreMessage_TMessageKey.L_PIN) : message.getBody(key: CoreMessage_TMessageKey.CHAT_ID)
+            } else {
+                threadIdentifier = message.getBody(key: CoreMessage_TMessageKey.F_PIN)
+            }
+        }
+        let messageId = message.getBody(key: CoreMessage_TMessageKey.MESSAGE_ID)
+        var nameSubtitle = ""
+        let imageId = CoreMessage_TMessageKey.IMAGE_ID
+        let videoId = CoreMessage_TMessageKey.VIDEO_ID
+        let fileId = CoreMessage_TMessageKey.FILE_ID
+        let audioId = CoreMessage_TMessageKey.AUDIO_ID
+        let attachmentFlag = CoreMessage_TMessageKey.ATTACHMENT_FLAG
+        let messageScopeId = CoreMessage_TMessageKey.MESSAGE_SCOPE_ID
+        let credential = CoreMessage_TMessageKey.CREDENTIAL
+        let gif_id = CoreMessage_TMessageKey.GIF_ID
+        let is_secret = CoreMessage_TMessageKey.IS_SECRET
+        if message.getBody(key: is_secret) == "1" {
+          text = "You got messages..."
+        } else if message.getBody(key: gif_id) != "" {
+          text = "Sent GIF 🎬"
+        } else if !message.getBody(key: imageId).isEmpty {
+            text = "Sent Image 📷"
+        } else if message.getBody(key: attachmentFlag) == "11" {
+            text = "Sent Sticker ❤️"
+        } else if !message.getBody(key: videoId).isEmpty {
+            text = "Sent Video 📹"
+        } else if !message.getBody(key: fileId).isEmpty {
+            if message.getBody(key: messageScopeId) == "18" {
+                text = "Sent Form 📄"
+            } else {
+                text = "Sent File 📄"
+            }
+        } else if !message.getBody(key: audioId).isEmpty {
+            text = "Sent Audio ♫"
+        } else if text.contains("Share%20location%20") {
+            text = "Sent Location 📌"
+        } else if message.getBody(key: attachmentFlag) == "27" {
+            text = "Sent Live Streaming"
+        } else if message.getBody(key: attachmentFlag) == "26" {
+            text = "Sent Seminar"
+        } else if message.getBody(key: attachmentFlag) == "25" {
+            text = "Sent Video Conference Room"
+        } else if message.getBody(key: attachmentFlag) == "24" {
+            text = "Sent Quiz"
+        } else if message.getBody(key: credential) == "1" {
+            text = "Sent Confidential Message"
+        }
+        var type = "1"
+        var nameTopic = "Lounge".localized()
+        var idGroup = ""
+        if scope == "3" || scope == "18" || scope == "5"{
+            type = "0"
+        }
+        if type == "1" {
+            Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                do {
+                    if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT title, group_id FROM DISCUSSION_FORUM WHERE chat_id='\(threadIdentifier)'"), cursor.next() {
+                        nameTopic = cursor.string(forColumnIndex: 0) ?? ""
+                        idGroup = cursor.string(forColumnIndex: 1) ?? ""
+                        cursor.close()
+                    }
+                    if idGroup.isEmpty {
+                        idGroup = threadIdentifier
+                    }
+                    if let cursorGroup = Database.shared.getRecords(fmdb: fmdb, query: "SELECT f_name, image_id FROM GROUPZ WHERE group_id='\(idGroup)'"), cursorGroup.next() {
+                        let nameGroup = cursorGroup.string(forColumnIndex: 0) ?? ""
+                        nameSubtitle = "\(nameGroup)(\(nameTopic))"
+                        cursorGroup.close()
+                    }
+                } catch {
+                    rollback.pointee = true
+                    print("Access database error: \(error.localizedDescription)")
+                }
+            })
+            if idGroup.isEmpty {
+                return
+            }
+        }
+        let center = UNUserNotificationCenter.current()
+        let content = UNMutableNotificationContent()
+        content.title = nameUser
+        content.sound = .default
+        if type == "1" {
+            content.body = text.richText(group_id: idGroup).string
+            content.subtitle = nameSubtitle
+        } else {
+            content.body = text.richText().string
+        }
+        content.userInfo = ["id" : threadIdentifier, "type" : type]
+        content.sound = UNNotificationSound(named: UNNotificationSoundName("pb_call_in.mp3"))
+        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
+        let request = UNNotificationRequest(identifier: messageId, content: content, trigger: trigger)
+        center.add(request) { error in
+            if let error = error {
+                print("Error scheduling notification: \(error.localizedDescription)")
+            }
+        }
+        UIApplication.shared.applicationIconBadgeNumber += 1
+    }
+    
     private static func copySoundToLocalPath() {
         guard let sourceURL = Bundle.resourceBundle(for: Nexilis.self).url(forResource: "pb_call_in", withExtension: "mp3") else {
             return
@@ -1025,7 +1050,7 @@ public class APIS: NSObject {
                 let id = userInfo["id"] ?? ""
                 let type = userInfo["type"] ?? ""
                 if type == "0" {
-                    if let user = User.getData(pin: id), user.firstName == "User".localized() {
+                    if User.getDataCanNil(pin: id) == nil {
                         return
                     }
                     let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
@@ -1177,17 +1202,19 @@ public class APIS: NSObject {
     }
     
     public static func enterBackground() {
-        do {
-            try API.switchCBI(cbiI: Callback(), bLight: true)
-        } catch {
-        }
+//        do {
+//            try API.switchCBI(cbiI: Callback(), bLight: true)
+//        } catch {
+//        }
     }
     
     public static func enterForeground() {
-        do {
-            try API.switchCBI(cbiI: Callback(), bLight: false)
-        } catch {
-        }
+//        do {
+//            try API.switchCBI(cbiI: Callback(), bLight: false)
+//        } catch {
+//        }
+        UIApplication.shared.applicationIconBadgeNumber = 0
+        UNUserNotificationCenter.current().removeAllDeliveredNotifications()
     }
     
     public static func setCheckEmulator(isActive: Bool) {

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

@@ -668,9 +668,6 @@ public class FloatingButton: UIView, UIGestureRecognizerDelegate {
                 print("Access database error: \(error.localizedDescription)")
             }
         })
-        if !Nexilis.fromMAB {
-            UIApplication.shared.applicationIconBadgeNumber = Int(counter ?? 0)
-        }
         return counter ?? 0
     }
     

+ 22 - 36
NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -1267,7 +1267,6 @@ class IncomingThread {
     }
     
     public func receiveMessage(message: TMessage, withoutACK: Bool = false) -> 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)")
             if !withoutACK {
@@ -1275,42 +1274,21 @@ class IncomingThread {
             }
             return
         }
-        var messageExist = false
-        Database.shared.database?.inTransaction({ (fmdb, rollback) in
-            do {
-                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message_id)'"), cursor.next() {
-                    if !withoutACK {
-                        ack(message: message)
-                    }
-                    cursor.close()
-                    messageExist = true
-                    print("MASUK RETURN MESSAGE EXIST")
-                }
-            } catch {
-                rollback.pointee = true
-                print("Access database error: \(error.localizedDescription)")
-            }
-        })
-        if messageExist {
-            return
-        }
         let media = message.getMedia()
         //print("MEDIA \(media)");
         let thumb_id = message.getBody(key: CoreMessage_TMessageKey.THUMB_ID)
-        if media.count > 0 {
-            do {
-                let data = Data(media)
-                let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
-                let url = documentDir.appendingPathComponent(thumb_id)
-                //print("write thumb \(url.path)")
-                try data.write(to: url, options: .atomic)
+        do {
+            let data = Data(media)
+            let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
+            let url = documentDir.appendingPathComponent(thumb_id)
+            //print("write thumb \(url.path)")
+            try data.write(to: url, options: .atomic)
 //                let image = UIImage(data: data)
 //                if save {
 //                    UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
 //                }
-            } catch {
-                //print(error)
-            }
+        } catch {
+            //print(error)
         }
         if (!thumb_id.isEmpty) {
             Download().startHTTP(forKey: thumb_id) { (file, progress) in
@@ -1320,12 +1298,20 @@ class IncomingThread {
                     //print("save message incoming")
                 }
             }
-            if !withoutACK {
-                ack(message: message)
-            }
-            return
-        }
-        Nexilis.saveMessage(message: message, withStatus: false)
+        } else {
+            Nexilis.saveMessage(message: message, withStatus: false)
+        }
+//        DispatchQueue.main.async {
+//            if APIS.checkAppStateisBackground() {
+//                UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
+//                    let identifier = message.getBody(key : CoreMessage_TMessageKey.MESSAGE_ID, default_value : "")
+//                    let matchingNotifications = notifications.filter { $0.request.identifier == identifier }
+//                    if !matchingNotifications.isEmpty {
+//                        APIS.addNotificationNexilis(message)
+//                    }
+//                }
+//            }
+//        }
         //print("save message incoming")
         if !withoutACK {
             ack(message: message)

+ 14 - 15
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -1299,10 +1299,8 @@ public class Nexilis: NSObject {
         Database.shared.database?.inTransaction({ (fmdb, rollback) in
             do {
                 var messageExist = false
-                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message_id)'") {
-                    if cursor.next() {
-                        messageExist = true
-                    }
+                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(message_id)'"), cursor.next() {
+                    messageExist = true
                     cursor.close()
                 }
                 let l_pin = message.getBody(key : CoreMessage_TMessageKey.L_PIN, default_value : "")
@@ -1385,6 +1383,13 @@ public class Nexilis: NSObject {
                     }
                 }
                 var pin = opposite_pin
+                if pin.isEmpty {
+                    if scope == "4" {
+                        pin = chat_id.isEmpty ? l_pin : chat_id
+                    } else {
+                        pin = f_pin
+                    }
+                }
                 if pin == me {
                     pin = l_pin
                 }
@@ -1392,7 +1397,7 @@ public class Nexilis: NSObject {
                 if !withStatus {
                     if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select counter from MESSAGE_SUMMARY where l_pin = '\(pin)'"), cursor.next() {
                         counter = Int(cursor.int(forColumnIndex: 0))
-                        if last_edited == 0 {
+                        if last_edited == 0 && !messageExist {
                             counter! += 1
                         }
                         cursor.close()
@@ -1403,28 +1408,22 @@ public class Nexilis: NSObject {
                         //print("set counter message summary")
                     }
                 }
-                if counter == nil {
-                    counter = 0
-                }
                 if is_call_center == "0" {
                     do {
-                        var queryGetLastMessageId = "SELECT message_id FROM MESSAGE where f_pin = '\(pin)' OR l_pin = '\(pin)' order by server_date desc LIMIT 1"
+                        var queryGetLastMessageId = "SELECT message_id FROM MESSAGE where (f_pin = '\(pin)' OR l_pin = '\(pin)') AND message_scope_id = '3' order by server_date desc LIMIT 1"
                         if scope == "4" {
-                            queryGetLastMessageId = "SELECT message_id FROM MESSAGE where l_pin = '\(pin)' AND chat_id = '' order by server_date desc LIMIT 1"
-                            if !chat_id.isEmpty {
-                                queryGetLastMessageId = "SELECT message_id FROM MESSAGE where chat_id = '\(pin)' order by server_date desc LIMIT 1"
-                            }
+                            queryGetLastMessageId = "SELECT message_id FROM MESSAGE where l_pin = '\(chat_id.isEmpty ? pin : l_pin)' AND chat_id = '\(chat_id)' AND message_scope_id = '4' order by server_date desc LIMIT 1"
                         }
                         var messageId = ""
                         if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: queryGetLastMessageId), cursorData.next() {
                             messageId = cursorData.string(forColumnIndex: 0) ?? ""
                             cursorData.close()
                         }
-                        if !messageId.isEmpty && !messageExist {
+                        if !messageId.isEmpty {
                             _ = try Database.shared.insertRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
                                 "l_pin" : pin,
                                 "message_id" : messageId,
-                                "counter" : counter!
+                                "counter" : counter ?? 0
                             ], replace: true)
                         }
                     } catch {

+ 8 - 10
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -399,9 +399,9 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
         }
         
         if fromNotification {
-            let imageButton = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 44))
-            imageButton.image = UIImage(systemName: "chevron.backward")?.withTintColor(.white)
-            imageButton.contentMode = .right
+            let imageButton = UIImageView(frame: CGRect(x: -16, y: 0, width: 20, height: 44))
+            imageButton.image = UIImage(systemName: "chevron.backward", withConfiguration: UIImage.SymbolConfiguration(pointSize: 20, weight: .regular, scale: .default))?.withTintColor(.white)
+            imageButton.contentMode = .left
             let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapExit))
             imageButton.isUserInteractionEnabled = true
             imageButton.addGestureRecognizer(tapGestureRecognizer)
@@ -834,7 +834,7 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
             imageProfile.circle()
             imageProfile.clipsToBounds = true
             viewAppBar.addSubview(imageProfile)
-            let pictureImage = dataGroup["image_id"]!
+            let pictureImage = dataGroup["image_id"] ?? ""
             if (pictureImage  as? String ?? "" != "" && pictureImage != nil) {
                 imageProfile.setImage(name: pictureImage!  as? String ?? "")
                 imageProfile.contentMode = .scaleAspectFill
@@ -856,7 +856,7 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
                     titleNavigation.text = (dataGroup["f_name"] as? String)! + " " + "Contact Center".localized()
                 }
             } else {
-                titleNavigation.text = (dataGroup["f_name"] as? String)! + " (\(dataTopic["title"]!!))"
+                titleNavigation.text = (dataGroup["f_name"] as? String ?? "") + " (\(dataTopic["title"] as? String ?? ""))"
             }
             titleNavigation.textColor = .white
             titleNavigation.font = UIFont.systemFont(ofSize: 12).bold
@@ -1905,7 +1905,7 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
     
     private func getCounter() {
         Database().database?.inTransaction({ fmdb, rollback in
-            var l_pin = self.dataGroup["group_id"]!!
+            var l_pin = self.dataGroup["group_id"] as? String ?? ""
             if (self.dataTopic["chat_id"]  as? String ?? "" != "") {
                 l_pin = self.dataTopic["chat_id"]  as? String ?? ""
             }
@@ -2047,9 +2047,7 @@ public class EditorGroup: UIViewController, CLLocationManagerDelegate {
             message.mStatus = CoreMessage_TMessageUtil.getTID()
             message.mBodies[CoreMessage_TMessageKey.L_PIN] = f_pin
             message.mBodies[CoreMessage_TMessageKey.MESSAGE_ID] = "-2,\(message_id)"
-            DispatchQueue.global().async {
-                _ = Nexilis.write(message: message)
-            }
+            _ = Nexilis.write(message: message)
         }
         if let index = dataMessages.firstIndex(where: {$0["message_id"] as? String == message_id}) {
             dataMessages[index]["status"] = "4"
@@ -4296,7 +4294,7 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource {
             
             timeMessage.trailingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: -8).isActive = true
             
-            if dataMessages[indexPath.row]["lock"] == nil || dataMessages[indexPath.row]["lock"]  as? String ?? "" == "0" {
+            if (dataMessages[indexPath.row]["lock"] as? String != "2") {
                 cellMessage.contentView.addSubview(statusMessage)
                 statusMessage.translatesAutoresizingMaskIntoConstraints = false
                 statusMessage.bottomAnchor.constraint(equalTo: timeMessage.topAnchor).isActive = true

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

@@ -3085,9 +3085,6 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                     message.mStatus = CoreMessage_TMessageUtil.getTID()
                     message.mBodies[CoreMessage_TMessageKey.L_PIN] = f_pin
                     message.mBodies[CoreMessage_TMessageKey.MESSAGE_ID] = "-2,\(valueListGroupImages[i].messageId)"
-                    DispatchQueue.global().async {
-                        _ = Nexilis.write(message: message)
-                    }
                 }
             } else {
                 Database.shared.database?.inTransaction({ (fmdb, rollback) in
@@ -3103,10 +3100,8 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                 message.mStatus = CoreMessage_TMessageUtil.getTID()
                 message.mBodies[CoreMessage_TMessageKey.L_PIN] = f_pin
                 message.mBodies[CoreMessage_TMessageKey.MESSAGE_ID] = "-2,\(message_id)"
-                DispatchQueue.global().async {
-                    _ = Nexilis.write(message: message)
-                }
             }
+            _ = Nexilis.write(message: message)
         }
         if let index = dataMessages.firstIndex(where: {$0["message_id"] as? String == message_id}) {
             dataMessages[index]["status"] = "4"
@@ -5530,7 +5525,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
             
             timeMessage.trailingAnchor.constraint(equalTo: containerMessage.leadingAnchor, constant: -8).isActive = true
             
-            if (dataMessages[indexPath.row]["lock"] == nil || dataMessages[indexPath.row]["lock"]  as? String ?? "" == "0") && (dataMessages[indexPath.row]["lock"] as? String != "2") {
+            if (dataMessages[indexPath.row]["lock"] as? String != "2") {
                 cell.contentView.addSubview(statusMessage)
                 statusMessage.translatesAutoresizingMaskIntoConstraints = false
                 statusMessage.bottomAnchor.constraint(equalTo: timeMessage.topAnchor).isActive = true

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

@@ -632,9 +632,9 @@ public class BackupRestoreView: UIViewController, UITableViewDataSource, UITable
             } else {
                 labelRestoring.text = "Successfully Restored Data".localized()
             }
-            DispatchQueue.global().async { [self] in
-                _ = Nexilis.write(message: CoreMessage_TMessageBank.getBackupRestored(option: optionBackup, fileid: fileIdBackup))
-            }
+//            DispatchQueue.global().async { [self] in
+//                _ = Nexilis.write(message: CoreMessage_TMessageBank.getBackupRestored(option: optionBackup, fileid: fileIdBackup))
+//            }
             DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { [self] in
                 isRestoreStart = false
                 valueLastBackup = "-"
@@ -647,9 +647,9 @@ public class BackupRestoreView: UIViewController, UITableViewDataSource, UITable
         } catch {
             //print(error)
             self.view.makeToast("Backup files are corrupted".localized(), duration: 3)
-            DispatchQueue.global().async { [self] in
-                _ = Nexilis.write(message: CoreMessage_TMessageBank.getBackupRestored(option: optionBackup, fileid: fileIdBackup))
-            }
+//            DispatchQueue.global().async { [self] in
+//                _ = Nexilis.write(message: CoreMessage_TMessageBank.getBackupRestored(option: optionBackup, fileid: fileIdBackup))
+//            }
             DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { [self] in
                 isRestoreStart = false
                 valueLastBackup = "-"