alqindiirsyam 2 vuotta sitten
vanhempi
commit
ad53d7a826

+ 16 - 1
appbuilder-ios/AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -390,6 +390,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
             segment.setTitle("Groups".localized(), forSegmentAt: 1)
         }
         if segment.selectedSegmentIndex == 0 {
+            Utils.inTabChats = true
             searchController.searchBar.placeholder = "Search chats & messages".localized()
         } else {
             searchController.searchBar.placeholder = "Search groups name".localized()
@@ -410,6 +411,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
         tabBarController?.navigationItem.searchController = nil
         tabBarController?.navigationItem.rightBarButtonItem = nil
         tabBarController?.navigationItem.rightBarButtonItems = nil
+        Utils.inTabChats = false
         if ViewController.isExpandButton {
             ViewController.expandButton()
         }
@@ -439,8 +441,10 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
     @objc func segmentChanged(sender: Any) {
         switch segment.selectedSegmentIndex {
         case 1:
+            Utils.inTabChats = false
             searchController.searchBar.placeholder = "Search groups name".localized()
         default:
+            Utils.inTabChats = true
             searchController.searchBar.placeholder = "Search chats & messages".localized()
         }
         filterContentForSearchText(searchController.searchBar.text!)
@@ -888,6 +892,17 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
             if isFilltering {
                 data = fillteredData[indexPath.row] as! Chat
             } else {
+                if chats.count == 0 {
+                    let labelNochat = UILabel()
+                    labelNochat.text = "There are no conversations".localized()
+                    labelNochat.font = .systemFont(ofSize: 13)
+                    labelNochat.textColor = .black
+                    content.addSubview(labelNochat)
+                    labelNochat.anchor(centerX: content.centerXAnchor, centerY: content.centerYAnchor)
+                    cell.backgroundColor = .clear
+                    cell.selectionStyle = .none
+                    return cell
+                }
                 data = chats[indexPath.row]
             }
             let imageView = UIImageView()
@@ -915,7 +930,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                         })
                     }
                 } else {
-                    getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
+                    getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : data.messageScope == "3" ? "Profile---Purple" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
                         imageView.image = image
                     })
                 }

+ 0 - 8
appbuilder-ios/NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -834,10 +834,6 @@ class IncomingThread {
                 if(progress == 100) {
                     Nexilis.saveMessage(message: message, withStatus: false)
                     print("save message incoming")
-                    if let delegate = Nexilis.shared.messageDelegate {
-                        message.mBodies[CoreMessage_TMessageKey.MESSAGE_TEXT] = message.getBody(key : CoreMessage_TMessageKey.MESSAGE_TEXT, default_value : "").toNormalString()
-                        delegate.onReceive(message: message)
-                    }
                 }
             }
             ack(message: message)
@@ -845,10 +841,6 @@ class IncomingThread {
         }
         Nexilis.saveMessage(message: message, withStatus: false)
         print("save message incoming")
-        if let delegate = Nexilis.shared.messageDelegate {
-            message.mBodies[CoreMessage_TMessageKey.MESSAGE_TEXT] = message.getBody(key : CoreMessage_TMessageKey.MESSAGE_TEXT, default_value : "").toNormalString()
-            delegate.onReceive(message: message)
-        }
         ack(message: message)
     }
     

+ 19 - 3
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -263,7 +263,7 @@ public class Nexilis: NSObject {
             Nexilis.dispatch?.wait()
             Nexilis.dispatch = nil
             print("success change user to fpin")
-            _ = Nexilis.writeSync(message: CoreMessage_TMessageBank.getChangeConnectionID(p_pin: f_pin))
+            _ = Nexilis.write(message: CoreMessage_TMessageBank.getChangeConnectionID(p_pin: f_pin))
         } catch{
             print(error)
         }
@@ -1064,6 +1064,13 @@ public class Nexilis: NSObject {
                     rollback.pointee = true
                     print(error)
                 }
+            } else {
+                DispatchQueue.main.async {
+                    if let delegate = Nexilis.shared.messageDelegate, Utils.getSetProfile() {
+                        message.mBodies[CoreMessage_TMessageKey.MESSAGE_TEXT] = message.getBody(key : CoreMessage_TMessageKey.MESSAGE_TEXT, default_value : "").toNormalString()
+                        delegate.onReceive(message: message)
+                    }
+                }
             }
             var pin = l_pin
             if l_pin == me {
@@ -1073,7 +1080,7 @@ public class Nexilis: NSObject {
                 pin = chat_id
             }
             var counter : Int? = nil
-            if l_pin == me || (scope == "4" && f_pin != me) {
+            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))
                     counter! += 1
@@ -1090,9 +1097,15 @@ public class Nexilis: NSObject {
             }
             if is_call_center == "0" {
                 do {
+                    let queryGetLastMessageId = "SELECT message_id FROM MESSAGE where opposite_pin = '\(f_pin)' 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()
+                    }
                     _ = try Database.shared.insertRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
                         "l_pin" : pin,
-                        "message_id" : message_id,
+                        "message_id" : messageId,
                         "counter" : counter!
                     ], replace: true)
                 } catch {
@@ -2801,6 +2814,9 @@ extension Nexilis: MessageDelegate {
                 if !onGoingCC.isEmpty {
                     return
                 }
+                if Utils.inTabChats{
+                    return
+                }
                 if(m["A06"]! == "3" || m["A06"]! == "18" || m["A06"]! == "5") {
                     if inEditorPersonal == sender || (inEditorPersonal != nil && inEditorPersonal!.contains(",")) {
                         return

+ 2 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Utils.swift

@@ -133,6 +133,8 @@ public final class Utils {
     static func getUrlDock() -> String? {
         return Utils.getURLBase()! + "dashboardv2/uploads/fb_icon/" + Utils.getIconDock()!
     }
+    
+    public static var inTabChats = false
 }
 public extension UIImage {
     var jpeg: Data? { jpegData(compressionQuality: 1) }  // QUALITY min = 0 / max = 1

+ 5 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -200,12 +200,12 @@ public class EditorGroup: UIViewController {
                         }
                         _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(l_pin='\(self.dataGroup["group_id"]!!)' and chat_id='\(self.dataTopic["chat_id"]!!)') and message_scope_id='4'")
                         _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(l_pin)'")
+                        if self.fromNotification {
+                            self.didTapExit()
+                        } else {
+                            self.navigationController?.popViewController(animated: true)
+                        }
                     })
-                    if self.fromNotification {
-                        self.didTapExit()
-                    } else {
-                        self.navigationController?.popViewController(animated: true)
-                    }
 //                    self.dataMessages.removeAll()
 //                    self.dataDates.removeAll()
 //                    self.tableChatView.reloadData()

+ 166 - 38
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -89,6 +89,9 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
     var lastScrollIdxSearch = 0
     var buttonUp: UIButton!
     var buttonDown: UIButton!
+    var multipleOffsetUp = 1
+    var lastOffsetDown = 1
+    var gettingDataMessage = true
     
     public override func viewDidDisappear(_ animated: Bool) {
         if self.isMovingFromParent {
@@ -116,6 +119,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
             self.navigationController?.setNavigationBarHidden(false, animated: false)
         }
         updateProfile()
+        gettingDataMessage = false
     }
     
     public override func viewDidLoad() {
@@ -274,13 +278,12 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                         Database.shared.database?.inTransaction({ (fmdb, rollback) in
                             _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
                             _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
+                            if self.fromNotification {
+                                self.didTapExit()
+                            } else {
+                                self.navigationController?.popViewController(animated: true)
+                            }
                         })
-                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
-                        if self.fromNotification {
-                            self.didTapExit()
-                        } else {
-                            self.navigationController?.popViewController(animated: true)
-                        }
 //                        self.dataMessages.removeAll()
 //                        self.dataDates.removeAll()
 //                        self.tableChatView.reloadData()
@@ -354,13 +357,12 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                             Database.shared.database?.inTransaction({ (fmdb, rollback) in
                                 _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
                                 _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
+                                if self.fromNotification {
+                                    self.didTapExit()
+                                } else {
+                                    self.navigationController?.popViewController(animated: true)
+                                }
                             })
-                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
-                            if self.fromNotification {
-                                self.didTapExit()
-                            } else {
-                                self.navigationController?.popViewController(animated: true)
-                            }
     //                        self.dataMessages.removeAll()
     //                        self.dataDates.removeAll()
     //                        self.tableChatView.reloadData()
@@ -429,18 +431,15 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                             let alert = UIAlertController(title: "", message: "Are you sure to delete all message in this conversation?".localized(), preferredStyle: .alert)
                             alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
                             alert.addAction(UIAlertAction(title: "Delete".localized(), style: .destructive, handler: {(_) in
-                                DispatchQueue.global().async {
-                                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
-                                        _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
-                                        _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
-                                    })
-                                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
-                                }
-                                if self.fromNotification {
-                                    self.didTapExit()
-                                } else {
-                                    self.navigationController?.popViewController(animated: true)
-                                }
+                                Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                                    _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
+                                    _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
+                                    if self.fromNotification {
+                                        self.didTapExit()
+                                    } else {
+                                        self.navigationController?.popViewController(animated: true)
+                                    }
+                                })
         //                        self.dataMessages.removeAll()
         //                        self.dataDates.removeAll()
         //                        self.tableChatView.reloadData()
@@ -474,18 +473,15 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                             let alert = UIAlertController(title: "", message: "Are you sure to delete all message in this conversation?".localized(), preferredStyle: .alert)
                             alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
                             alert.addAction(UIAlertAction(title: "Delete".localized(), style: .destructive, handler: {(_) in
-                                DispatchQueue.global().async {
-                                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
-                                        _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
-                                        _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
-                                    })
-                                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
-                                }
-                                if self.fromNotification {
-                                    self.didTapExit()
-                                } else {
-                                    self.navigationController?.popViewController(animated: true)
-                                }
+                                Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                                    _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
+                                    _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
+                                    if self.fromNotification {
+                                        self.didTapExit()
+                                    } else {
+                                        self.navigationController?.popViewController(animated: true)
+                                    }
+                                })
         //                        self.dataMessages.removeAll()
         //                        self.dataDates.removeAll()
         //                        self.tableChatView.reloadData()
@@ -853,7 +849,132 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
         })
     }
     
+    private func addDataMessage() {
+        multipleOffsetUp += 1
+        let queryCount = "SELECT COUNT(*) FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0"
+        let query = "SELECT message_id, f_pin, l_pin, message_scope_id, server_date, status, message_text, audio_id, video_id, image_id, thumb_id, read_receipts, chat_id, file_id, attachment_flag, reff_id, lock, is_stared, blog_id, credential FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0 order by server_date asc LIMIT CASE WHEN (\(queryCount))-\(dataMessages.count)>=20 THEN 20*\(multipleOffsetUp-1) ELSE (\(queryCount))-\(dataMessages.count) END OFFSET CASE WHEN (\(queryCount))>=\(20*multipleOffsetUp) THEN (\(queryCount))-\(20*multipleOffsetUp) ELSE 0 END"
+        Database.shared.database?.inTransaction({ (fmdb, rollback) in
+            if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
+                var tempData: [[String: Any?]] = []
+                while cursorData.next() {
+                    var row: [String: Any?] = [:]
+                    row["message_id"] = cursorData.string(forColumnIndex: 0)
+                    row["f_pin"] = cursorData.string(forColumnIndex: 1)
+                    row["l_pin"] = cursorData.string(forColumnIndex: 2)
+                    row["message_scope_id"] = cursorData.string(forColumnIndex: 3)
+                    row["server_date"] = cursorData.string(forColumnIndex: 4)
+                    row["status"] = cursorData.string(forColumnIndex: 5)
+                    row["message_text"] = cursorData.string(forColumnIndex: 6)
+                    row["audio_id"] = cursorData.string(forColumnIndex: 7)
+                    row["video_id"] = cursorData.string(forColumnIndex: 8)
+                    row["image_id"] = cursorData.string(forColumnIndex: 9)
+                    row["thumb_id"] = cursorData.string(forColumnIndex: 10)
+                    row["read_receipts"] = cursorData.string(forColumnIndex: 11)
+                    row["chat_id"] = cursorData.string(forColumnIndex: 12)
+                    row["file_id"] = cursorData.string(forColumnIndex: 13)
+                    row["attachment_flag"] = cursorData.string(forColumnIndex: 14)
+                    row["reff_id"] = cursorData.string(forColumnIndex: 15)
+                    row["lock"] = cursorData.string(forColumnIndex: 16)
+                    row["is_stared"] = cursorData.string(forColumnIndex: 17)
+                    row["blog_id"] = cursorData.string(forColumnIndex: 18)
+                    row["credential"] = cursorData.string(forColumnIndex: 19)
+                    if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status FROM MESSAGE_STATUS WHERE message_id='\(row["message_id"] as! String)'") {
+                        while cursorStatus.next() {
+                            row["status"] = cursorStatus.string(forColumnIndex: 0)
+                        }
+                        cursorStatus.close()
+                    }
+                    let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
+                    let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
+                    let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
+                    if let dirPath = paths.first {
+                        let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["video_id"] as! String)
+                        let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["file_id"] as! String)
+                        if ((row["video_id"] as! String) != "") {
+                            if FileManager.default.fileExists(atPath: videoURL.path){
+                                row["progress"] = 100.0
+                            } else {
+                                row["progress"] = 0.0
+                            }
+                        } else {
+                            if FileManager.default.fileExists(atPath: fileURL.path){
+                                row["progress"] = 100.0
+                            } else {
+                                row["progress"] = 0.0
+                            }
+                        }
+                    }
+                    row["chat_date"] = chatDate(stringDate: row["server_date"] as! String)
+                    row["isSelected"] = false
+                    if row["credential"] as! String == "1" {
+                        let idMe = UserDefaults.standard.string(forKey: "me")!
+                        if row["f_pin"] as! String == idMe {
+                            let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(row["server_date"] as! String)!), end: Date())
+                            if second > 60 {
+                                listTimerCredential[row["message_id"] as! String] = 0
+                                row["lock"] = "2"
+                                row["reff_id"] = ""
+                                DispatchQueue.global().async {
+                                    Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                                        _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
+                                            "lock" : "2"
+                                        ], _where: "message_id = '\(row["message_id"] as! String)'")
+                                    })
+                                }
+                            } else {
+                                let second = 60 - second
+                                listTimerCredential[row["message_id"] as! String] = second
+                            }
+                        } else {
+                            let hasMessageId = UserDefaults.standard.string(forKey: row["message_id"] as! String)
+                            if hasMessageId != nil {
+                                let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(hasMessageId!)!), end: Date())
+                                if second > 60 {
+                                    listTimerCredential[row["message_id"] as! String] = 0
+                                    row["lock"] = "2"
+                                    row["reff_id"] = ""
+                                    DispatchQueue.global().async {
+                                        Database.shared.database?.inTransaction({ (fmdb, rollback) in
+                                            _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
+                                                "lock" : "2"
+                                            ], _where: "message_id = '\(row["message_id"] as! String)'")
+                                        })
+                                    }
+                                } else {
+                                    let second = 60 - second
+                                    listTimerCredential[row["message_id"] as! String] = second
+                                }
+                            } else {
+                                UserDefaults.standard.set("\(Date().currentTimeMillis())", forKey: row["message_id"] as! String)
+                                listTimerCredential[row["message_id"] as! String] = 60
+                            }
+                        }
+                    }
+                    tempData.append(row)
+                }
+                if tempData.count != 0 && (dataMessages.firstIndex(where: { $0["message_id"] as? String == tempData[0]["message_id"] as? String }) == nil) {
+                    let lastIndex = tempData.count - 1
+                    for i in 0..<tempData.count {
+                        tableChatView.beginUpdates()
+                        dataMessages.insert(tempData[lastIndex - i], at: 0)
+                        if dataMessages.firstIndex(where: { $0["chat_date"] as? String == tempData[lastIndex - i]["chat_date"] as? String }) != nil {
+                            tableChatView.insertRows(at: [IndexPath(row: 0, section: currentIndexpath!.section)], with: .top)
+                        } else {
+                            tableChatView.insertSections(IndexSet(integer: 0), with: .top)
+                            tableChatView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .top)
+                        }
+                        tableChatView.endUpdates()
+                    }
+                }
+                cursorData.close()
+                gettingDataMessage = false
+            }
+        })
+    }
+    
     private func getData() {
+//        let queryCount = "SELECT COUNT(*) FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0"
+//        var query = "SELECT message_id, f_pin, l_pin, message_scope_id, server_date, status, message_text, audio_id, video_id, image_id, thumb_id, read_receipts, chat_id, file_id, attachment_flag, reff_id, lock, is_stared, blog_id, credential FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0 order by server_date asc LIMIT CASE WHEN (\(queryCount))-\(dataMessages.count)>=20 THEN 20 ELSE (\(queryCount))-\(dataMessages.count) END OFFSET CASE WHEN (\(queryCount))>=\(20*multipleOffsetUp) THEN (\(queryCount))-\(20*multipleOffsetUp) ELSE 0 END"
         var query = "SELECT message_id, f_pin, l_pin, message_scope_id, server_date, status, message_text, audio_id, video_id, image_id, thumb_id, read_receipts, chat_id, file_id, attachment_flag, reff_id, lock, is_stared, blog_id, credential FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0 order by server_date asc"
         if isContactCenter {
             if complaintId.isEmpty {
@@ -2088,7 +2209,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
         if isContactCenter {
             opposite_pin = fPinContacCenter
         } else {
-            opposite_pin = l_pin
+            opposite_pin = idMe ?? ""
         }
         var credential = credential
         if isConfidential {
@@ -2576,6 +2697,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
     }
     
     private func checkNewMessage(tableView: UITableView) {
+//        let indexPathFirst = tableView.indexPathsForVisibleRows?.first
+//        if indexPathFirst != nil {
+//            let dataMessages = self.dataMessages.filter({ $0["chat_date"] as! String == dataDates[indexPathFirst!.section] })
+//            if self.dataMessages.firstIndex(where: { $0["message_id"] as? String == dataMessages[indexPathFirst!.row]["message_id"] as? String }) == 0 && !gettingDataMessage {
+//                gettingDataMessage = true
+//                addDataMessage()
+//            }
+//        }
         currentIndexpath = tableView.indexPathsForVisibleRows?.last
         if currentIndexpath != nil {
             let dataMessages = dataMessages.filter({ $0["chat_date"] as! String == dataDates[currentIndexpath!.section] })
@@ -4417,7 +4546,6 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
             for j in 0...listTextEnter.count - 1 {
                 let listText = listTextEnter[j].split(separator: " ")
                 for i in 0...listText.count - 1 {
-                    print("HMM \(listText[i].lowercased().checkStartWithLink())")
                     if listText[i].lowercased().checkStartWithLink() {
                         if ((listText[i].lowercased().starts(with: "www.") && listText[i].lowercased().split(separator: ".").count >= 3) || (!listText[i].lowercased().starts(with: "www.") && listText[i].lowercased().split(separator: ".").count >= 2)) && listText[i].lowercased().split(separator: ".").last!.count >= 2 {
                             let objectGesture = ObjectGesture(target: self, action: #selector(tapMessageText(_:)))

+ 4 - 4
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeDeviceViewController.swift

@@ -139,7 +139,7 @@ public class ChangeDeviceViewController: UIViewController {
                             UserDefaults.standard.synchronize()
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
-                            DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
+                            DispatchQueue.main.async {
                                 Nexilis.hideLoader(completion: {
                                     let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                     imageView.tintColor = .white
@@ -159,7 +159,7 @@ public class ChangeDeviceViewController: UIViewController {
                                     }
                                     self.isDismiss?(thumb)
                                 })
-                            })
+                            }
                         }
                     }
                 } else {
@@ -253,7 +253,7 @@ public class ChangeDeviceViewController: UIViewController {
                         UserDefaults.standard.synchronize()
                         // pos registration
                         _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
-                        DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
+                        DispatchQueue.main.async {
                             Nexilis.hideLoader(completion: {
                                 let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                 imageView.tintColor = .white
@@ -274,7 +274,7 @@ public class ChangeDeviceViewController: UIViewController {
                                 }
                                 self.isDismiss?(thumb)
                             })
-                        })
+                        }
                     }
                 }
             } else {

+ 23 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -48,10 +48,13 @@ class ContactChatViewController: UITableViewController {
     func filterContentForSearchText(_ searchText: String) {
         switch segment.selectedSegmentIndex {
         case 1:
+            Utils.inTabChats = false
             fillteredData = self.contacts.filter { $0.fullName.lowercased().contains(searchText.lowercased()) }
         case 2:
+            Utils.inTabChats = false
             fillteredData = self.groups.filter { $0.name.lowercased().contains(searchText.lowercased()) }
         default:
+            Utils.inTabChats = true
             fillteredData = self.chats.filter { $0.name.lowercased().contains(searchText.lowercased()) || $0.messageText.lowercased().contains(searchText.lowercased()) }
         }
         tableView.reloadData()
@@ -155,6 +158,7 @@ class ContactChatViewController: UITableViewController {
         segment.selectedSegmentIndex = 0
         segment.addTarget(self, action: #selector(segmentChanged(sender:)), for: .valueChanged)
         segment.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12.0)], for: .normal)
+        Utils.inTabChats = true
         
         NotificationCenter.default.addObserver(self, selector: #selector(onReceiveMessage(notification:)), name: NSNotification.Name(rawValue: "onMessageChat"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(onReceiveMessage(notification:)), name: NSNotification.Name(rawValue: "onReceiveChat"), object: nil)
@@ -180,6 +184,10 @@ class ContactChatViewController: UITableViewController {
         getData()
     }
     
+    override func viewWillDisappear(_ animated: Bool) {
+        Utils.inTabChats = false
+    }
+    
     override func viewDidAppear(_ animated: Bool) {
         if isChooser != nil {
             self.navigationController?.navigationBar.topItem?.title = "Forward Messages".localized()
@@ -202,6 +210,9 @@ class ContactChatViewController: UITableViewController {
                 }
             })
         }
+        if segment.selectedSegmentIndex == 0 {
+            Utils.inTabChats = true
+        }
     }
     
 //    func removeAllData() {
@@ -742,6 +753,17 @@ extension ContactChatViewController {
             if isFilltering {
                 data = fillteredData[indexPath.row] as! Chat
             } else {
+                if chats.count == 0 {
+                    let labelNochat = UILabel()
+                    labelNochat.text = "There are no conversations".localized()
+                    labelNochat.font = .systemFont(ofSize: 13)
+                    labelNochat.textColor = .black
+                    content.addSubview(labelNochat)
+                    labelNochat.anchor(centerX: content.centerXAnchor, centerY: content.centerYAnchor)
+                    cell.backgroundColor = .clear
+                    cell.selectionStyle = .none
+                    return cell
+                }
                 data = chats[indexPath.row]
             }
             let imageView = UIImageView()
@@ -769,7 +791,7 @@ extension ContactChatViewController {
                         })
                     }
                 } else {
-                    getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
+                    getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : data.messageScope == "3" ? "Profile---Purple" : "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
                         imageView.image = image
                     })
                 }

+ 4 - 4
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/SignUpSignIn.swift

@@ -147,7 +147,7 @@ public class SignUpSignIn: UIViewController {
                             UserDefaults.standard.synchronize()
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
-                            DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
+                            DispatchQueue.main.async {
                                 Nexilis.hideLoader(completion: {
                                     let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                     imageView.tintColor = .white
@@ -167,7 +167,7 @@ public class SignUpSignIn: UIViewController {
                                     }
                                     self.isDismiss?(thumb)
                                 })
-                            })
+                            }
                         }
                     }
                 } else {
@@ -285,7 +285,7 @@ public class SignUpSignIn: UIViewController {
                             UserDefaults.standard.synchronize()
                             // pos registration
                             _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
-                            DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
+                            DispatchQueue.main.async {
                                 Nexilis.hideLoader(completion: {
                                     let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
                                     imageView.tintColor = .white
@@ -306,7 +306,7 @@ public class SignUpSignIn: UIViewController {
                                     }
                                     self.isDismiss?(thumb)
                                 })
-                            })
+                            }
                         }
                     } else {
                         Database.shared.database?.inTransaction({ fmdb, rollback in