|
@@ -31,6 +31,8 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
@IBOutlet var viewTextfield: UIView!
|
|
|
@IBOutlet weak var buttonAckConfidential: UIButton!
|
|
|
@IBOutlet weak var constraintLeftTextField: NSLayoutConstraint!
|
|
|
+ @IBOutlet weak var constraintBottomTableViewWithTextfield: NSLayoutConstraint!
|
|
|
+ @IBOutlet weak var viewAttachment: UIStackView!
|
|
|
public var dataPerson: [String: String?] = [:]
|
|
|
var dataMessages: [[String: Any?]] = []
|
|
|
var dataDates: [String] = []
|
|
@@ -59,6 +61,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
var copySession = false
|
|
|
var forwardSession = false
|
|
|
var deleteSession = false
|
|
|
+ var isSearching = false
|
|
|
let containerMultpileSelectSession = UIView()
|
|
|
let containerAction = UIView()
|
|
|
var removed = false
|
|
@@ -78,6 +81,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
var listTimerCredential: [String: Int] = [:]
|
|
|
var timerCredential: [String: Timer] = [:]
|
|
|
let contactChatNav = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
|
|
|
+ var searchBar: UISearchBar!
|
|
|
+ var constraintBottomContainerMultpileSelectSession = NSLayoutConstraint()
|
|
|
+ var titleSearchMatches: UILabel!
|
|
|
+ var textSearch = ""
|
|
|
+ var countMatchesSearch = 0
|
|
|
+ var lastScrollIdxSearch = 0
|
|
|
+ var buttonUp: UIButton!
|
|
|
+ var buttonDown: UIButton!
|
|
|
|
|
|
public override func viewDidDisappear(_ animated: Bool) {
|
|
|
if self.isMovingFromParent {
|
|
@@ -215,33 +226,29 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
|
|
|
private func setRightButtonItem() {
|
|
|
navigationItem.rightBarButtonItems = nil
|
|
|
- var menu = UIMenu(title: "", children: [
|
|
|
- UIAction(title: "Delete Conversation".localized(), handler: {(_) in
|
|
|
- if !self.isContactCenter {
|
|
|
- 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
|
|
|
- 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()
|
|
|
- }))
|
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
- }
|
|
|
- })
|
|
|
- ])
|
|
|
+ var menu = UIMenu()
|
|
|
let exblock = User.getData(pin: self.dataPerson["f_pin"]!!)?.ex_block
|
|
|
blocking = exblock == nil ? "0" : exblock!.isEmpty ? "0" : exblock!
|
|
|
if blocking == "1" && self.dataPerson["f_pin"]!! != "-999" {
|
|
|
menu = UIMenu(title: "", children: [
|
|
|
+ UIAction(title: "Search".localized(), handler: {(_) in
|
|
|
+ self.isSearching = true
|
|
|
+ if self.reffId != nil {
|
|
|
+ self.deleteReplyView()
|
|
|
+ }
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
+ if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
+ self.navigationItem.rightBarButtonItems = nil
|
|
|
+ }
|
|
|
+ self.navigationItem.rightBarButtonItem = cancelButton
|
|
|
+ if self.isContactCenter || self.fromNotification {
|
|
|
+ self.navigationItem.leftBarButtonItem = nil
|
|
|
+ }
|
|
|
+ self.changeAppBar()
|
|
|
+ self.addMultipleSelectSession()
|
|
|
+ }
|
|
|
+ }),
|
|
|
UIAction(title: "Unblock".localized(), handler: {(_) in
|
|
|
if !self.isContactCenter {
|
|
|
DispatchQueue.global().async {
|
|
@@ -282,13 +289,11 @@ 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)
|
|
|
- }
|
|
|
+ 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"]!!)'")
|
|
|
+ })
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
if self.fromNotification {
|
|
|
self.didTapExit()
|
|
|
} else {
|
|
@@ -306,6 +311,24 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
} else if blocking == "0" {
|
|
|
if self.dataPerson["f_pin"]!! != "-999"{
|
|
|
menu = UIMenu(title: "", children: [
|
|
|
+ UIAction(title: "Search".localized(), handler: {(_) in
|
|
|
+ self.isSearching = true
|
|
|
+ if self.reffId != nil {
|
|
|
+ self.deleteReplyView()
|
|
|
+ }
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
+ if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
+ self.navigationItem.rightBarButtonItems = nil
|
|
|
+ }
|
|
|
+ self.navigationItem.rightBarButtonItem = cancelButton
|
|
|
+ if self.isContactCenter || self.fromNotification {
|
|
|
+ self.navigationItem.leftBarButtonItem = nil
|
|
|
+ }
|
|
|
+ self.changeAppBar()
|
|
|
+ self.addMultipleSelectSession()
|
|
|
+ }
|
|
|
+ }),
|
|
|
UIAction(title: "Block".localized(), handler: {(_) in
|
|
|
if !self.isContactCenter {
|
|
|
DispatchQueue.global().async {
|
|
@@ -366,6 +389,24 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
])
|
|
|
} else {
|
|
|
menu = UIMenu(title: "", children: [
|
|
|
+ UIAction(title: "Search".localized(), handler: {(_) in
|
|
|
+ self.isSearching = true
|
|
|
+ if self.reffId != nil {
|
|
|
+ self.deleteReplyView()
|
|
|
+ }
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
+ if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
+ self.navigationItem.rightBarButtonItems = nil
|
|
|
+ }
|
|
|
+ self.navigationItem.rightBarButtonItem = cancelButton
|
|
|
+ if self.isContactCenter || self.fromNotification {
|
|
|
+ self.navigationItem.leftBarButtonItem = nil
|
|
|
+ }
|
|
|
+ self.changeAppBar()
|
|
|
+ self.addMultipleSelectSession()
|
|
|
+ }
|
|
|
+ }),
|
|
|
UIAction(title: "Delete Conversation".localized(), handler: {(_) in
|
|
|
if !self.isContactCenter {
|
|
|
let alert = UIAlertController(title: "", message: "Are you sure to delete all message in this conversation?".localized(), preferredStyle: .alert)
|
|
@@ -575,116 +616,127 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
let viewAppBar = UIView()
|
|
|
viewAppBar.frame.size = CGSize(width: self.view.frame.size.width, height: 44)
|
|
|
|
|
|
- let imageProfile = UIImageView(frame: CGRect(x: 0, y: 7, width: 30, height: 30))
|
|
|
- imageProfile.circle()
|
|
|
- imageProfile.clipsToBounds = true
|
|
|
- let pictureImage = dataPerson["picture"]!
|
|
|
- var count = 0
|
|
|
- if isContactCenter {
|
|
|
- if fPinContacCenter.isEmpty && isRequestContactCenter {
|
|
|
- getImage(name: dataPerson["picture"]!!, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
- imageProfile.image = image
|
|
|
- }
|
|
|
- viewAppBar.addSubview(imageProfile)
|
|
|
- } else {
|
|
|
- if users.count == 1 {
|
|
|
- viewAppBar.addSubview(imageProfile)
|
|
|
- getImage(name: users[0].thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
+ if !isSearching {
|
|
|
+ let imageProfile = UIImageView(frame: CGRect(x: 0, y: 7, width: 30, height: 30))
|
|
|
+ imageProfile.circle()
|
|
|
+ imageProfile.clipsToBounds = true
|
|
|
+ let pictureImage = dataPerson["picture"]!
|
|
|
+ var count = 0
|
|
|
+ if isContactCenter {
|
|
|
+ if fPinContacCenter.isEmpty && isRequestContactCenter {
|
|
|
+ getImage(name: dataPerson["picture"]!!, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
imageProfile.image = image
|
|
|
- imageProfile.contentMode = .scaleAspectFit
|
|
|
}
|
|
|
+ viewAppBar.addSubview(imageProfile)
|
|
|
} else {
|
|
|
- for user in users {
|
|
|
- if count == 3 {
|
|
|
- count += 1
|
|
|
- continue
|
|
|
+ if users.count == 1 {
|
|
|
+ viewAppBar.addSubview(imageProfile)
|
|
|
+ getImage(name: users[0].thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
+ imageProfile.image = image
|
|
|
+ imageProfile.contentMode = .scaleAspectFit
|
|
|
}
|
|
|
- if count == 0 {
|
|
|
- let pictures = UIImageView(frame: CGRect(x: 0, y: 7, width: 30, height: 30))
|
|
|
- pictures.circle()
|
|
|
- pictures.clipsToBounds = true
|
|
|
- viewAppBar.addSubview(pictures)
|
|
|
- getImage(name: user.thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
- pictures.image = image
|
|
|
- pictures.contentMode = .scaleAspectFit
|
|
|
+ } else {
|
|
|
+ for user in users {
|
|
|
+ if count == 3 {
|
|
|
+ count += 1
|
|
|
+ continue
|
|
|
}
|
|
|
- } else {
|
|
|
- let pictures = UIImageView(frame: CGRect(x: count * 20 , y: 7, width: 30, height: 30))
|
|
|
- pictures.circle()
|
|
|
- pictures.clipsToBounds = true
|
|
|
- viewAppBar.addSubview(pictures)
|
|
|
- getImage(name: user.thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
- pictures.image = image
|
|
|
- pictures.contentMode = .scaleAspectFit
|
|
|
+ if count == 0 {
|
|
|
+ let pictures = UIImageView(frame: CGRect(x: 0, y: 7, width: 30, height: 30))
|
|
|
+ pictures.circle()
|
|
|
+ pictures.clipsToBounds = true
|
|
|
+ viewAppBar.addSubview(pictures)
|
|
|
+ getImage(name: user.thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
+ pictures.image = image
|
|
|
+ pictures.contentMode = .scaleAspectFit
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let pictures = UIImageView(frame: CGRect(x: count * 20 , y: 7, width: 30, height: 30))
|
|
|
+ pictures.circle()
|
|
|
+ pictures.clipsToBounds = true
|
|
|
+ viewAppBar.addSubview(pictures)
|
|
|
+ getImage(name: user.thumb, placeholderImage: UIImage(systemName: "person.circle.fill")!) { result, isDownloaded, image in
|
|
|
+ pictures.image = image
|
|
|
+ pictures.contentMode = .scaleAspectFit
|
|
|
+ }
|
|
|
}
|
|
|
+ count += 1
|
|
|
}
|
|
|
- count += 1
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- } else if dataPerson["f_pin"]!! == "-999" {
|
|
|
- viewAppBar.addSubview(imageProfile)
|
|
|
- if Utils.getIconDock() != nil {
|
|
|
- let dataImage = try? Data(contentsOf: URL(string: Utils.getUrlDock()!)!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
- if dataImage != nil {
|
|
|
- imageProfile.image = UIImage(data: dataImage!)
|
|
|
+ } else if dataPerson["f_pin"]!! == "-999" {
|
|
|
+ viewAppBar.addSubview(imageProfile)
|
|
|
+ if Utils.getIconDock() != nil {
|
|
|
+ let dataImage = try? Data(contentsOf: URL(string: Utils.getUrlDock()!)!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
+ if dataImage != nil {
|
|
|
+ imageProfile.image = UIImage(data: dataImage!)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ imageProfile.image = UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
|
}
|
|
|
- } else {
|
|
|
- imageProfile.image = UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
|
+ imageProfile.contentMode = .scaleAspectFit
|
|
|
}
|
|
|
- imageProfile.contentMode = .scaleAspectFit
|
|
|
- }
|
|
|
- else if (pictureImage != "" && pictureImage != nil) {
|
|
|
- viewAppBar.addSubview(imageProfile)
|
|
|
- imageProfile.setImage(name: pictureImage!)
|
|
|
- imageProfile.contentMode = .scaleAspectFill
|
|
|
- } else {
|
|
|
- viewAppBar.addSubview(imageProfile)
|
|
|
- imageProfile.image = UIImage(systemName: "person")
|
|
|
- imageProfile.contentMode = .scaleAspectFit
|
|
|
- imageProfile.backgroundColor = .lightGray
|
|
|
- }
|
|
|
-
|
|
|
- var titleNavigation = UILabel(frame: CGRect(x: 35, y: 0, width: viewAppBar.frame.size.width - 150, height: 44))
|
|
|
- if dataPerson["f_pin"]!! != "-999" && !isContactCenter && (blocking == "-1" || blocking == "1") {
|
|
|
- titleNavigation = UILabel(frame: CGRect(x: 35, y: 0, width: viewAppBar.frame.size.width - 250, height: 44))
|
|
|
- } else if isContactCenter {
|
|
|
- if users.count > 0 {
|
|
|
- titleNavigation = UILabel(frame: CGRect(x: 35 * (CGFloat(users.count)) - (CGFloat((users.count - 1) * 15)), y: 0, width: viewAppBar.frame.size.width - 150 - (35 * (CGFloat(users.count - 1)) - (CGFloat((users.count - 1) * 15))), height: 44))
|
|
|
+ else if (pictureImage != "" && pictureImage != nil) {
|
|
|
+ viewAppBar.addSubview(imageProfile)
|
|
|
+ imageProfile.setImage(name: pictureImage!)
|
|
|
+ imageProfile.contentMode = .scaleAspectFill
|
|
|
+ } else {
|
|
|
+ viewAppBar.addSubview(imageProfile)
|
|
|
+ imageProfile.image = UIImage(systemName: "person")
|
|
|
+ imageProfile.contentMode = .scaleAspectFit
|
|
|
+ imageProfile.backgroundColor = .lightGray
|
|
|
}
|
|
|
- }
|
|
|
- viewAppBar.addSubview(titleNavigation)
|
|
|
- if ((dataPerson["isOfficial"] == "1" && !isContactCenter) || (dataPerson["isOfficial"] == "1" && fPinContacCenter.isEmpty)) {
|
|
|
- var name = dataPerson["name"]!!
|
|
|
- if (isContactCenter) {
|
|
|
- name = name + " " + "Contact Center".localized()
|
|
|
+
|
|
|
+ var titleNavigation = UILabel(frame: CGRect(x: 35, y: 0, width: viewAppBar.frame.size.width - 150, height: 44))
|
|
|
+ if dataPerson["f_pin"]!! != "-999" && !isContactCenter && (blocking == "-1" || blocking == "1") {
|
|
|
+ titleNavigation = UILabel(frame: CGRect(x: 35, y: 0, width: viewAppBar.frame.size.width - 250, height: 44))
|
|
|
+ } else if isContactCenter {
|
|
|
+ if users.count > 0 {
|
|
|
+ titleNavigation = UILabel(frame: CGRect(x: 35 * (CGFloat(users.count)) - (CGFloat((users.count - 1) * 15)), y: 0, width: viewAppBar.frame.size.width - 150 - (35 * (CGFloat(users.count - 1)) - (CGFloat((users.count - 1) * 15))), height: 44))
|
|
|
+ }
|
|
|
}
|
|
|
- titleNavigation.set(image: UIImage(named: "ic_official_flag", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(.white), with: " \(name)", size: 15, y: -4)
|
|
|
- } else {
|
|
|
- if !isContactCenter {
|
|
|
- titleNavigation.text = dataPerson["name"] as? String
|
|
|
+ viewAppBar.addSubview(titleNavigation)
|
|
|
+ if ((dataPerson["isOfficial"] == "1" && !isContactCenter) || (dataPerson["isOfficial"] == "1" && fPinContacCenter.isEmpty)) {
|
|
|
+ var name = dataPerson["name"]!!
|
|
|
+ if (isContactCenter) {
|
|
|
+ name = name + " " + "Contact Center".localized()
|
|
|
+ }
|
|
|
+ titleNavigation.set(image: UIImage(named: "ic_official_flag", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(.white), with: " \(name)", size: 15, y: -4)
|
|
|
} else {
|
|
|
- if users.count == 1 {
|
|
|
- titleNavigation.text = users[0].fullName
|
|
|
+ if !isContactCenter {
|
|
|
+ titleNavigation.text = dataPerson["name"] as? String
|
|
|
} else {
|
|
|
- var stringName = ""
|
|
|
- for user in users {
|
|
|
- if stringName.isEmpty {
|
|
|
- stringName = user.fullName
|
|
|
- } else {
|
|
|
- stringName += ", \(user.fullName)"
|
|
|
+ if users.count == 1 {
|
|
|
+ titleNavigation.text = users[0].fullName
|
|
|
+ } else {
|
|
|
+ var stringName = ""
|
|
|
+ for user in users {
|
|
|
+ if stringName.isEmpty {
|
|
|
+ stringName = user.fullName
|
|
|
+ } else {
|
|
|
+ stringName += ", \(user.fullName)"
|
|
|
+ }
|
|
|
}
|
|
|
+ titleNavigation.text = stringName
|
|
|
}
|
|
|
- titleNavigation.text = stringName
|
|
|
}
|
|
|
}
|
|
|
+ titleNavigation.textColor = .white
|
|
|
+ titleNavigation.font = UIFont.systemFont(ofSize: 12).bold
|
|
|
+ navigationItem.titleView = viewAppBar
|
|
|
+ } else {
|
|
|
+ searchBar = UISearchBar()
|
|
|
+ searchBar.autocapitalizationType = .none
|
|
|
+ searchBar.delegate = self
|
|
|
+ searchBar.searchTextField.tintColor = .mainColor
|
|
|
+ searchBar.barTintColor = .secondaryColor
|
|
|
+ searchBar.searchTextField.backgroundColor = .secondaryColor
|
|
|
+ searchBar.showsCancelButton = false
|
|
|
+ navigationItem.titleView = searchBar
|
|
|
+ self.definesPresentationContext = true
|
|
|
}
|
|
|
- titleNavigation.textColor = .white
|
|
|
- titleNavigation.font = UIFont.systemFont(ofSize: 12).bold
|
|
|
-
|
|
|
- navigationItem.titleView = viewAppBar
|
|
|
|
|
|
- if copySession || forwardSession || deleteSession {
|
|
|
+ if copySession || forwardSession || deleteSession || isSearching {
|
|
|
navigationItem.hidesBackButton = true
|
|
|
navigationController?.interactivePopGestureRecognizer?.isEnabled = false
|
|
|
} else {
|
|
@@ -1748,11 +1800,15 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
|
|
|
@objc func dismissKeyboard() {
|
|
|
- textFieldSend.resignFirstResponder() // dismiss keyoard
|
|
|
- if (self.constraintBottomAttachment.constant != 0.0) {
|
|
|
- constraintBottomAttachment.constant = 0.0
|
|
|
- self.viewSticker.removeConstraints(self.viewSticker.constraints)
|
|
|
- self.viewSticker.removeFromSuperview()
|
|
|
+ if isSearching {
|
|
|
+ searchBar.resignFirstResponder()
|
|
|
+ } else {
|
|
|
+ textFieldSend.resignFirstResponder() // dismiss keyoard
|
|
|
+ if (self.constraintBottomAttachment.constant != 0.0) {
|
|
|
+ constraintBottomAttachment.constant = 0.0
|
|
|
+ self.viewSticker.removeConstraints(self.viewSticker.constraints)
|
|
|
+ self.viewSticker.removeFromSuperview()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1825,6 +1881,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
let duration: CGFloat = info[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber as! CGFloat
|
|
|
|
|
|
self.constraintViewTextField.constant = 0
|
|
|
+ self.constraintBottomContainerMultpileSelectSession.constant = 0
|
|
|
UIView.animate(withDuration: TimeInterval(duration), animations: {
|
|
|
self.view.layoutIfNeeded()
|
|
|
})
|
|
@@ -1847,13 +1904,21 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
|
|
|
if self.constraintViewTextField.constant != keyboardHeight - 60 {
|
|
|
self.constraintViewTextField.constant = keyboardHeight - 60
|
|
|
+ if isSearching {
|
|
|
+ self.constraintViewTextField.constant = self.constraintViewTextField.constant + 60
|
|
|
+ self.constraintBottomContainerMultpileSelectSession.constant = -keyboardHeight
|
|
|
+ }
|
|
|
UIView.animate(withDuration: TimeInterval(duration), animations: {
|
|
|
self.view.layoutIfNeeded()
|
|
|
})
|
|
|
- if (self.currentIndexpath != nil) {
|
|
|
- self.tableChatView.scrollToRow(at: IndexPath(row: self.currentIndexpath!.row, section: self.currentIndexpath!.section), at: .none, animated: false)
|
|
|
- } else {
|
|
|
+ if isSearching {
|
|
|
self.tableChatView.scrollToBottom()
|
|
|
+ } else {
|
|
|
+ if (self.currentIndexpath != nil) {
|
|
|
+ self.tableChatView.scrollToRow(at: IndexPath(row: self.currentIndexpath!.row, section: self.currentIndexpath!.section), at: .none, animated: false)
|
|
|
+ } else {
|
|
|
+ self.tableChatView.scrollToBottom()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -2864,17 +2929,25 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
if self.removed {
|
|
|
return
|
|
|
}
|
|
|
- self.handleReply(indexPath: indexPath!)
|
|
|
+ if self.isSearching {
|
|
|
+ self.cancelAction()
|
|
|
+ }
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
|
|
|
+ self.handleReply(indexPath: indexPath!)
|
|
|
+ })
|
|
|
})
|
|
|
let forward = UIAction(title: "Forward".localized(), image: UIImage(systemName: "arrowshape.turn.up.right.fill"), handler: {(_) in
|
|
|
if self.removed {
|
|
|
return
|
|
|
}
|
|
|
- self.forwardSession = true
|
|
|
+ if self.isSearching {
|
|
|
+ self.cancelAction()
|
|
|
+ }
|
|
|
if self.reffId != nil {
|
|
|
self.deleteReplyView()
|
|
|
}
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ self.forwardSession = true
|
|
|
let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
self.navigationItem.rightBarButtonItems = nil
|
|
@@ -2896,11 +2969,14 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
if self.removed {
|
|
|
return
|
|
|
}
|
|
|
- self.copySession = true
|
|
|
+ if self.isSearching {
|
|
|
+ self.cancelAction()
|
|
|
+ }
|
|
|
if self.reffId != nil {
|
|
|
self.deleteReplyView()
|
|
|
}
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ self.copySession = true
|
|
|
let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
self.navigationItem.rightBarButtonItems = nil
|
|
@@ -2931,11 +3007,14 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
if self.removed {
|
|
|
return
|
|
|
}
|
|
|
- self.deleteSession = true
|
|
|
+ if self.isSearching {
|
|
|
+ self.cancelAction()
|
|
|
+ }
|
|
|
if self.reffId != nil {
|
|
|
self.deleteReplyView()
|
|
|
}
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
|
|
|
+ self.deleteSession = true
|
|
|
let cancelButton = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(self.cancelAction))
|
|
|
if self.dataPerson["f_pin"] != "-999" && !self.isContactCenter {
|
|
|
self.navigationItem.rightBarButtonItems = nil
|
|
@@ -2995,6 +3074,25 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
self.forwardSession = false
|
|
|
} else if self.deleteSession {
|
|
|
self.deleteSession = false
|
|
|
+ } else if self.isSearching {
|
|
|
+ self.countMatchesSearch = 0
|
|
|
+ self.isSearching = false
|
|
|
+ }
|
|
|
+ if self.viewTextfield.isHidden {
|
|
|
+ self.viewTextfield.isHidden = false
|
|
|
+ }
|
|
|
+ if self.viewAttachment.isHidden {
|
|
|
+ self.viewAttachment.isHidden = false
|
|
|
+ }
|
|
|
+ if !self.isSearching {
|
|
|
+ self.constraintBottomTableViewWithTextfield.constant = self.constraintBottomTableViewWithTextfield.constant + 70
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
|
|
|
+ if (self.currentIndexpath != nil) {
|
|
|
+ self.tableChatView.scrollToRow(at: IndexPath(row: self.currentIndexpath!.row, section: self.currentIndexpath!.section), at: .none, animated: true)
|
|
|
+ } else {
|
|
|
+ self.tableChatView.scrollToBottom()
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
let data = self.dataMessages.filter({ $0["isSelected"] as! Bool == true })
|
|
|
for i in 0..<data.count {
|
|
@@ -3016,13 +3114,17 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
|
|
|
private func addMultipleSelectSession() {
|
|
|
+ viewTextfield.isHidden = true
|
|
|
+ viewAttachment.isHidden = true
|
|
|
+ constraintBottomTableViewWithTextfield.constant = constraintBottomTableViewWithTextfield.constant - 70
|
|
|
view.addSubview(containerMultpileSelectSession)
|
|
|
containerMultpileSelectSession.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ constraintBottomContainerMultpileSelectSession = containerMultpileSelectSession.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0)
|
|
|
NSLayoutConstraint.activate([
|
|
|
containerMultpileSelectSession.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
|
|
|
containerMultpileSelectSession.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
|
|
|
- containerMultpileSelectSession.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
|
|
|
- containerMultpileSelectSession.heightAnchor.constraint(equalToConstant: 120)
|
|
|
+ constraintBottomContainerMultpileSelectSession,
|
|
|
+ containerMultpileSelectSession.heightAnchor.constraint(equalToConstant: 50)
|
|
|
])
|
|
|
containerMultpileSelectSession.backgroundColor = .white
|
|
|
addSubviewMultipleSession()
|
|
@@ -3044,52 +3146,104 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
container.layer.shadowColor = UIColor.black.cgColor
|
|
|
container.backgroundColor = .secondaryColor
|
|
|
|
|
|
- let title = UILabel()
|
|
|
- container.addSubview(title)
|
|
|
- title.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- NSLayoutConstraint.activate([
|
|
|
- title.centerXAnchor.constraint(equalTo: container.centerXAnchor),
|
|
|
- title.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
- ])
|
|
|
- let countSelected = dataMessages.filter({ $0["isSelected"] as! Bool == true }).count
|
|
|
- title.text = "\(countSelected) " + "Selected".localized()
|
|
|
- title.textColor = .mainColor
|
|
|
- title.font = UIFont.systemFont(ofSize: 15.0).bold
|
|
|
-
|
|
|
- let button = UIImageView()
|
|
|
- container.addSubview(button)
|
|
|
- button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- NSLayoutConstraint.activate([
|
|
|
- button.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 15),
|
|
|
- button.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
- button.widthAnchor.constraint(equalToConstant: 30),
|
|
|
- button.heightAnchor.constraint(equalToConstant: 30),
|
|
|
- ])
|
|
|
- if copySession {
|
|
|
- button.image = UIImage(systemName: "doc.on.doc")
|
|
|
- if countSelected == 0 {
|
|
|
- button.tintColor = .gray
|
|
|
- } else {
|
|
|
- button.tintColor = .mainColor
|
|
|
- }
|
|
|
- } else if forwardSession {
|
|
|
- button.image = UIImage(systemName: "arrowshape.turn.up.right")
|
|
|
- if countSelected == 0 {
|
|
|
- button.tintColor = .gray
|
|
|
- } else {
|
|
|
- button.tintColor = .mainColor
|
|
|
- }
|
|
|
- } else if deleteSession {
|
|
|
- button.image = UIImage(systemName: "trash")
|
|
|
- if countSelected == 0 {
|
|
|
- button.tintColor = .gray
|
|
|
- } else {
|
|
|
- button.tintColor = .red
|
|
|
+ if !isSearching {
|
|
|
+ let title = UILabel()
|
|
|
+ container.addSubview(title)
|
|
|
+ title.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ title.centerXAnchor.constraint(equalTo: container.centerXAnchor),
|
|
|
+ title.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
+ ])
|
|
|
+ let countSelected = dataMessages.filter({ $0["isSelected"] as! Bool == true }).count
|
|
|
+ title.text = "\(countSelected) " + "Selected".localized()
|
|
|
+ title.textColor = .mainColor
|
|
|
+ title.font = UIFont.systemFont(ofSize: 15.0).bold
|
|
|
+
|
|
|
+ let button = UIImageView()
|
|
|
+ container.addSubview(button)
|
|
|
+ button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ button.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 15),
|
|
|
+ button.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
+ button.widthAnchor.constraint(equalToConstant: 30),
|
|
|
+ button.heightAnchor.constraint(equalToConstant: 30),
|
|
|
+ ])
|
|
|
+ if copySession {
|
|
|
+ button.image = UIImage(systemName: "doc.on.doc")
|
|
|
+ if countSelected == 0 {
|
|
|
+ button.tintColor = .gray
|
|
|
+ } else {
|
|
|
+ button.tintColor = .mainColor
|
|
|
+ }
|
|
|
+ } else if forwardSession {
|
|
|
+ button.image = UIImage(systemName: "arrowshape.turn.up.right")
|
|
|
+ if countSelected == 0 {
|
|
|
+ button.tintColor = .gray
|
|
|
+ } else {
|
|
|
+ button.tintColor = .mainColor
|
|
|
+ }
|
|
|
+ } else if deleteSession {
|
|
|
+ button.image = UIImage(systemName: "trash")
|
|
|
+ if countSelected == 0 {
|
|
|
+ button.tintColor = .gray
|
|
|
+ } else {
|
|
|
+ button.tintColor = .red
|
|
|
+ }
|
|
|
}
|
|
|
+ let buttonGesture = UITapGestureRecognizer(target: self, action: #selector(sessionAction))
|
|
|
+ button.isUserInteractionEnabled = true
|
|
|
+ button.addGestureRecognizer(buttonGesture)
|
|
|
+ } else {
|
|
|
+ buttonUp = UIButton()
|
|
|
+ container.addSubview(buttonUp)
|
|
|
+ buttonUp.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ buttonUp.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 10),
|
|
|
+ buttonUp.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
+ buttonUp.widthAnchor.constraint(equalToConstant: 30),
|
|
|
+ buttonUp.heightAnchor.constraint(equalToConstant: 30),
|
|
|
+ ])
|
|
|
+ buttonUp.addTarget(self, action: #selector(upSearchText), for: .touchUpInside)
|
|
|
+
|
|
|
+ buttonDown = UIButton()
|
|
|
+ container.addSubview(buttonDown)
|
|
|
+ buttonDown.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ buttonDown.leadingAnchor.constraint(equalTo: buttonUp.trailingAnchor, constant: 15),
|
|
|
+ buttonDown.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
+ buttonDown.widthAnchor.constraint(equalToConstant: 30),
|
|
|
+ buttonDown.heightAnchor.constraint(equalToConstant: 30),
|
|
|
+ ])
|
|
|
+ buttonDown.addTarget(self, action: #selector(downSearchText), for: .touchUpInside)
|
|
|
+
|
|
|
+ buttonUp.setImage(UIImage(systemName: "chevron.up"), for: .normal)
|
|
|
+ buttonUp.tintColor = .gray
|
|
|
+
|
|
|
+ buttonDown.setImage(UIImage(systemName: "chevron.down"), for: .normal)
|
|
|
+ buttonDown.tintColor = .gray
|
|
|
+
|
|
|
+ titleSearchMatches = UILabel()
|
|
|
+ container.addSubview(titleSearchMatches)
|
|
|
+ titleSearchMatches.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ titleSearchMatches.centerXAnchor.constraint(equalTo: container.centerXAnchor),
|
|
|
+ titleSearchMatches.centerYAnchor.constraint(equalTo:container.centerYAnchor),
|
|
|
+ ])
|
|
|
+ titleSearchMatches.textColor = .mainColor
|
|
|
+ titleSearchMatches.font = UIFont.systemFont(ofSize: 15.0).bold
|
|
|
+ titleSearchMatches.isHidden = true
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
|
|
|
+ self.searchBar.becomeFirstResponder()
|
|
|
+ })
|
|
|
}
|
|
|
- let buttonGesture = UITapGestureRecognizer(target: self, action: #selector(sessionAction))
|
|
|
- button.isUserInteractionEnabled = true
|
|
|
- button.addGestureRecognizer(buttonGesture)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func upSearchText() {
|
|
|
+ scrollToFirstSearchMessage(indexScroll: lastScrollIdxSearch + 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func downSearchText() {
|
|
|
+ scrollToFirstSearchMessage(indexScroll: lastScrollIdxSearch - 1)
|
|
|
}
|
|
|
|
|
|
@objc func sessionAction() {
|
|
@@ -4133,6 +4287,13 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if isSearching && textSearch.count > 1 {
|
|
|
+ messageText.attributedText = textChat.richText(isSearching: true, textSearch: textSearch)
|
|
|
+ if textChat.lowercased().contains(textSearch) {
|
|
|
+ countMatchesSearch += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
let stringDate = (dataMessages[indexPath.row]["server_date"] as? String) ?? ""
|
|
|
if !stringDate.isEmpty {
|
|
|
if (dataMessages[indexPath.row]["credential"] as? String) == "1" && dataMessages[indexPath.row]["lock"] as? String != "2" {
|
|
@@ -5035,6 +5196,83 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
|
|
|
imageSticker.heightAnchor.constraint(equalToConstant: 30).isActive = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ func scrollToFirstSearchMessage(indexScroll: Int = 1) {
|
|
|
+ if textSearch.count < 2 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var lastIndex = 0
|
|
|
+ let messageTextForSearch: [[String: Any?]] = self.dataMessages.reversed()
|
|
|
+ for idx in 0..<messageTextForSearch.count {
|
|
|
+ if (messageTextForSearch[idx]["message_text"] as! String).lowercased().contains(textSearch) {
|
|
|
+ lastIndex += 1
|
|
|
+ if lastIndex < indexScroll {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ lastScrollIdxSearch = lastIndex
|
|
|
+ let section = self.dataDates.firstIndex(of: messageTextForSearch[idx]["chat_date"] as! String)
|
|
|
+ if section == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let row = self.dataMessages.filter({ $0["chat_date"] as! String == self.dataDates[section!]}).firstIndex(where: { $0["message_id"] as? String == messageTextForSearch[idx]["message_id"] as? String})
|
|
|
+ if row == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let indexPath = IndexPath(row: row!, section: section!)
|
|
|
+ self.tableChatView.scrollToRow(at: indexPath, at: .middle, animated: true)
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
+ if let cell = self.tableChatView.cellForRow(at: indexPath) {
|
|
|
+ let containerMessage = cell.contentView.subviews[0]
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
+ if (messageTextForSearch[idx]["f_pin"] as? String == idMe) {
|
|
|
+ containerMessage.backgroundColor = .blueBubbleColor.withAlphaComponent(0.3)
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
+ if (messageTextForSearch[idx]["attachment_flag"] as? String == "11") {
|
|
|
+ containerMessage.backgroundColor = .clear
|
|
|
+ } else {
|
|
|
+ containerMessage.backgroundColor = .blueBubbleColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ containerMessage.backgroundColor = .grayColor.withAlphaComponent(0.3)
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
+ if (messageTextForSearch[idx]["attachment_flag"] as? String == "11") {
|
|
|
+ containerMessage.backgroundColor = .clear
|
|
|
+ } else {
|
|
|
+ containerMessage.backgroundColor = .grayColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ titleSearchMatches.isHidden = false
|
|
|
+ if countMatchesSearch != 0 {
|
|
|
+ if countMatchesSearch > 1 {
|
|
|
+ titleSearchMatches.text = "\(lastScrollIdxSearch) " + "of".localized() + " \(countMatchesSearch) " + "matches".localized()
|
|
|
+ } else {
|
|
|
+ titleSearchMatches.text = "\(countMatchesSearch) " + "matches".localized()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ titleSearchMatches.text = "Not found".localized()
|
|
|
+ }
|
|
|
+ if lastScrollIdxSearch == countMatchesSearch || countMatchesSearch == 0 {
|
|
|
+ buttonUp.isEnabled = false
|
|
|
+ buttonUp.tintColor = .gray
|
|
|
+ } else {
|
|
|
+ buttonUp.isEnabled = true
|
|
|
+ buttonUp.tintColor = .mainColor
|
|
|
+ }
|
|
|
+ if countMatchesSearch == 0 || lastScrollIdxSearch == 1 || countMatchesSearch == 1 {
|
|
|
+ buttonDown.isEnabled = false
|
|
|
+ buttonDown.tintColor = .gray
|
|
|
+ } else {
|
|
|
+ buttonDown.isEnabled = true
|
|
|
+ buttonDown.tintColor = .mainColor
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension UITableView {
|
|
@@ -5079,6 +5317,18 @@ extension UIImage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+extension EditorPersonal: UISearchBarDelegate {
|
|
|
+
|
|
|
+ public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
|
|
+ textSearch = searchText
|
|
|
+ countMatchesSearch = 0
|
|
|
+ titleSearchMatches.isHidden = true
|
|
|
+ tableChatView.reloadData()
|
|
|
+ scrollToFirstSearchMessage()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
public class ObjectGesture: UITapGestureRecognizer {
|
|
|
public var message_id = ""
|
|
|
public var image_id = ""
|