|
@@ -18,6 +18,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
var isAdmin: Bool = false
|
|
var isAdmin: Bool = false
|
|
|
|
|
|
var chats: [Chat] = []
|
|
var chats: [Chat] = []
|
|
|
|
+ var chatGroupMaps: [String: [Chat]] = [:]
|
|
|
|
|
|
var groups: [Group] = []
|
|
var groups: [Group] = []
|
|
|
|
|
|
@@ -34,6 +35,8 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
var alertController = LibAlertController()
|
|
var alertController = LibAlertController()
|
|
|
|
|
|
var noData = false
|
|
var noData = false
|
|
|
|
+ var loadingData = true
|
|
|
|
+ var waitingLoading = false
|
|
|
|
|
|
let textViewSearch = UITextField()
|
|
let textViewSearch = UITextField()
|
|
let buttonImageVoiceSb = UIButton(type: .custom)
|
|
let buttonImageVoiceSb = UIButton(type: .custom)
|
|
@@ -113,7 +116,12 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
fillteredData = self.groups.filter { $0.name.lowercased().contains(searchText.lowercased()) }
|
|
fillteredData = self.groups.filter { $0.name.lowercased().contains(searchText.lowercased()) }
|
|
default:
|
|
default:
|
|
if selectedTag == 0 {
|
|
if selectedTag == 0 {
|
|
- fillteredData = self.chats.filter { $0.name.lowercased().contains(searchText.lowercased()) || $0.messageText.lowercased().contains(searchText.lowercased()) }
|
|
|
|
|
|
+ var group_id: String?
|
|
|
|
+ if let filterGroupKey = self.chatGroupMaps.first(where: { $0.value.contains { $0.name.lowercased().contains(searchText.lowercased()) || $0.groupName.lowercased().contains(searchText.lowercased()) || $0.messageText.lowercased().contains(searchText.lowercased()) } } ) {
|
|
|
|
+ group_id = filterGroupKey.key
|
|
|
|
+ }
|
|
|
|
+ let deepCopyChats = self.chats.map{ $0.copy() }
|
|
|
|
+ fillteredData = deepCopyChats.filter { $0.name.lowercased().contains(searchText.lowercased()) || $0.messageText.lowercased().contains(searchText.lowercased()) || $0.groupId == group_id }
|
|
} else {
|
|
} else {
|
|
switch(selectedTag) {
|
|
switch(selectedTag) {
|
|
case UNREAD_TAG :
|
|
case UNREAD_TAG :
|
|
@@ -359,20 +367,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
}
|
|
}
|
|
|
|
|
|
@objc func startConversation(){
|
|
@objc func startConversation(){
|
|
- let navigationController = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
|
|
|
|
- navigationController.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
|
|
|
|
- Utils.addBackground(view: navigationController.view)
|
|
|
|
- navigationController.modalPresentationStyle = .fullScreen
|
|
|
|
- navigationController.navigationBar.tintColor = .white
|
|
|
|
- navigationController.navigationBar.barTintColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
|
|
|
|
- navigationController.navigationBar.isTranslucent = false
|
|
|
|
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
|
|
|
|
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
|
|
|
|
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
|
|
|
|
- navigationController.navigationBar.titleTextAttributes = textAttributes
|
|
|
|
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
|
|
|
|
- navigationController.navigationBar.barStyle = .black
|
|
|
|
- self.navigationController?.present(navigationController, animated: true, completion: nil)
|
|
|
|
|
|
+ APIS.openChat()
|
|
}
|
|
}
|
|
|
|
|
|
@objc func recordAudio(){
|
|
@objc func recordAudio(){
|
|
@@ -622,23 +617,9 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
}
|
|
}
|
|
if segment.selectedSegmentIndex == 0 {
|
|
if segment.selectedSegmentIndex == 0 {
|
|
Utils.inTabChats = true
|
|
Utils.inTabChats = true
|
|
-// searchController.searchBar.placeholder = "Search chats & messages".localized()
|
|
|
|
-// searchController.searchBar.searchTextField.attributedPlaceholder = NSAttributedString(string: "Search chats & messages".localized(), attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)])
|
|
|
|
- } else {
|
|
|
|
-// searchController.searchBar.placeholder = "Search groups name".localized()
|
|
|
|
-// searchController.searchBar.searchTextField.attributedPlaceholder = NSAttributedString(string: "Search groups name".localized(), attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)])
|
|
|
|
}
|
|
}
|
|
-// removeAllData()
|
|
|
|
-// getData()
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-// func removeAllData() {
|
|
|
|
-// groups.removeAll()
|
|
|
|
-// groupMap.removeAll()
|
|
|
|
-// chats.removeAll()
|
|
|
|
-// tableView.reloadData()
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
func textFieldDidChangeSelection(_ textField: UITextField) {
|
|
func textFieldDidChangeSelection(_ textField: UITextField) {
|
|
if textField == textViewSearch {
|
|
if textField == textViewSearch {
|
|
var textSerch = textField.text ?? ""
|
|
var textSerch = textField.text ?? ""
|
|
@@ -777,29 +758,35 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc func onReloadTab(notification: NSNotification) {
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.getData()
|
|
|
|
|
|
+ private func reloadAllData() {
|
|
|
|
+ DispatchQueue.global().async { [self] in
|
|
|
|
+ if waitingLoading {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ waitingLoading = true
|
|
|
|
+ while loadingData {
|
|
|
|
+ Thread.sleep(forTimeInterval: 0.5)
|
|
|
|
+ }
|
|
|
|
+ waitingLoading = false
|
|
|
|
+ getData()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @objc func onReloadTab(notification: NSNotification) {
|
|
|
|
+ reloadAllData()
|
|
|
|
+ }
|
|
|
|
+
|
|
@objc func onReload(notification: NSNotification) {
|
|
@objc func onReload(notification: NSNotification) {
|
|
let data:[AnyHashable : Any] = notification.userInfo!
|
|
let data:[AnyHashable : Any] = notification.userInfo!
|
|
if data["member"] as? String == User.getMyPin()! {
|
|
if data["member"] as? String == User.getMyPin()! {
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.getData()
|
|
|
|
- }
|
|
|
|
|
|
+ reloadAllData()
|
|
} else if data["state"] as? Int == 99 {
|
|
} else if data["state"] as? Int == 99 {
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.getData()
|
|
|
|
- }
|
|
|
|
|
|
+ reloadAllData()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@objc func onReceiveMessage(notification: NSNotification) {
|
|
@objc func onReceiveMessage(notification: NSNotification) {
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.getData()
|
|
|
|
- }
|
|
|
|
|
|
+ reloadAllData()
|
|
}
|
|
}
|
|
|
|
|
|
@objc func onStatusChat(notification: NSNotification) {
|
|
@objc func onStatusChat(notification: NSNotification) {
|
|
@@ -890,6 +877,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
}
|
|
}
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
self.tableView.reloadData()
|
|
self.tableView.reloadData()
|
|
|
|
+ self.loadingData = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -897,7 +885,41 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
|
|
|
func getChats(completion: @escaping ()->()) {
|
|
func getChats(completion: @escaping ()->()) {
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- self.chats = Chat.getData()
|
|
|
|
|
|
+ self.chatGroupMaps.removeAll()
|
|
|
|
+ let previousChat = self.chats
|
|
|
|
+ let allChats = Chat.getData()
|
|
|
|
+ var tempChats: [Chat] = []
|
|
|
|
+ for singleChat in allChats {
|
|
|
|
+ if !singleChat.groupId.isEmpty {
|
|
|
|
+ let chatParentInPreviousChats = previousChat.first(where: { $0.isParent && $0.groupId == singleChat.groupId })
|
|
|
|
+ if self.chatGroupMaps[singleChat.groupId] != nil {
|
|
|
|
+ self.chatGroupMaps[singleChat.groupId]!.insert(singleChat, at: 0)
|
|
|
|
+ if let parentChat = tempChats.first(where: { $0.groupId == singleChat.groupId && $0.isParent }) {
|
|
|
|
+ let counterParent = parentChat.counter
|
|
|
|
+ parentChat.counter = "\(Int(counterParent)! + Int(singleChat.counter)!)"
|
|
|
|
+ }
|
|
|
|
+ if let parentExist = chatParentInPreviousChats, parentExist.isSelected {
|
|
|
|
+ if let indexParent = previousChat.firstIndex(where: { $0.isParent && $0.groupId == singleChat.groupId }){
|
|
|
|
+ tempChats.insert(singleChat, at: indexParent + self.chatGroupMaps[singleChat.groupId]!.count)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ self.chatGroupMaps[singleChat.groupId] = [singleChat]
|
|
|
|
+ let parentChat = Chat(profile: singleChat.profile, groupName: singleChat.groupName, counter: singleChat.counter, groupId: singleChat.groupId)
|
|
|
|
+ parentChat.isParent = true
|
|
|
|
+ if let parentExist = chatParentInPreviousChats, parentExist.isSelected {
|
|
|
|
+ parentChat.isSelected = true
|
|
|
|
+ tempChats.append(parentChat)
|
|
|
|
+ tempChats.append(singleChat)
|
|
|
|
+ } else {
|
|
|
|
+ tempChats.append(parentChat)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ tempChats.append(singleChat)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ self.chats = tempChats
|
|
completion()
|
|
completion()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1066,6 +1088,10 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
} else {
|
|
} else {
|
|
data = chats[indexPath.row]
|
|
data = chats[indexPath.row]
|
|
}
|
|
}
|
|
|
|
+ if data.isParent {
|
|
|
|
+ expandCollapseChats(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
if let chooser = isChooser {
|
|
if let chooser = isChooser {
|
|
if data.pin == "-999"{
|
|
if data.pin == "-999"{
|
|
return
|
|
return
|
|
@@ -1097,6 +1123,40 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func expandCollapseChats(tableView: UITableView, indexPath: IndexPath) {
|
|
|
|
+ let data: Chat
|
|
|
|
+ if isFiltering {
|
|
|
|
+ data = fillteredData[indexPath.row] as! Chat
|
|
|
|
+ } else {
|
|
|
|
+ data = chats[indexPath.row]
|
|
|
|
+ }
|
|
|
|
+ data.isSelected = !data.isSelected
|
|
|
|
+ if data.isSelected {
|
|
|
|
+ for dataSubChat in self.chatGroupMaps[data.groupId]! {
|
|
|
|
+ if var indexParent = chats.firstIndex(where: { $0.isParent && $0.groupId == data.groupId }) {
|
|
|
|
+ if isFiltering {
|
|
|
|
+ fillteredData.insert(dataSubChat, at: indexParent + 1)
|
|
|
|
+ indexParent+=1
|
|
|
|
+ } else {
|
|
|
|
+ chats.insert(dataSubChat, at: indexParent + 1)
|
|
|
|
+ indexParent+=1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if isFiltering {
|
|
|
|
+ if var changedFillteredData = fillteredData as? [Chat] {
|
|
|
|
+ changedFillteredData.removeAll(where: { $0.isParent == false && $0.groupId == data.groupId })
|
|
|
|
+ self.fillteredData = changedFillteredData
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ chats.removeAll(where: { $0.isParent == false && $0.groupId == data.groupId })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+
|
|
func expandCollapseGroup(tableView: UITableView, indexPath: IndexPath) {
|
|
func expandCollapseGroup(tableView: UITableView, indexPath: IndexPath) {
|
|
let group: Group
|
|
let group: Group
|
|
if isFiltering {
|
|
if isFiltering {
|
|
@@ -1217,17 +1277,12 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
} else {
|
|
} else {
|
|
getGroups(id: group.id) { g in
|
|
getGroups(id: group.id) { g in
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
- //print("index path section: \(indexPath.section)")
|
|
|
|
- //print("index path row: \(indexPath.row)")
|
|
|
|
- //print("index path item: \(indexPath.item)")
|
|
|
|
if self.isFiltering {
|
|
if self.isFiltering {
|
|
-// self.fillteredData.remove(at: indexPath.section)
|
|
|
|
if self.fillteredData[indexPath.section] is Group {
|
|
if self.fillteredData[indexPath.section] is Group {
|
|
self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
|
|
self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
|
|
self.fillteredData.insert(contentsOf: g, at: indexPath.section + 1)
|
|
self.fillteredData.insert(contentsOf: g, at: indexPath.section + 1)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
-// self.groups.remove(at: indexPath.section)
|
|
|
|
self.groupMap[self.groups[indexPath.section].id] = 1
|
|
self.groupMap[self.groups[indexPath.section].id] = 1
|
|
self.groups.insert(contentsOf: g, at: indexPath.section + 1)
|
|
self.groups.insert(contentsOf: g, at: indexPath.section + 1)
|
|
}
|
|
}
|
|
@@ -1375,7 +1430,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
}
|
|
}
|
|
if noData || (isFiltering && fillteredData.count == 0) {
|
|
if noData || (isFiltering && fillteredData.count == 0) {
|
|
let labelNochat = UILabel()
|
|
let labelNochat = UILabel()
|
|
- labelNochat.text = isFiltering ? "No Result".localized() : "There are no conversations".localized()
|
|
|
|
|
|
+ labelNochat.text = isFiltering ? "No Result".localized() : loadingData ? "Loading Data...".localized() : "There are no conversations".localized()
|
|
labelNochat.font = .systemFont(ofSize: 13)
|
|
labelNochat.font = .systemFont(ofSize: 13)
|
|
labelNochat.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
|
|
labelNochat.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
|
|
content.addSubview(labelNochat)
|
|
content.addSubview(labelNochat)
|
|
@@ -1390,7 +1445,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
} else {
|
|
} else {
|
|
if chats.count == 0 {
|
|
if chats.count == 0 {
|
|
let labelNochat = UILabel()
|
|
let labelNochat = UILabel()
|
|
- labelNochat.text = "There are no conversations".localized()
|
|
|
|
|
|
+ labelNochat.text = loadingData ? "Loading Data...".localized() : "There are no conversations".localized()
|
|
labelNochat.font = .systemFont(ofSize: 13)
|
|
labelNochat.font = .systemFont(ofSize: 13)
|
|
labelNochat.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
|
|
labelNochat.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
|
|
content.addSubview(labelNochat)
|
|
content.addSubview(labelNochat)
|
|
@@ -1693,12 +1748,12 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
content.addSubview(imageView)
|
|
content.addSubview(imageView)
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
NSLayoutConstraint.activate([
|
|
NSLayoutConstraint.activate([
|
|
- imageView.leadingAnchor.constraint(equalTo: content.leadingAnchor, constant: 10.0),
|
|
|
|
imageView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
|
|
imageView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
|
|
imageView.bottomAnchor.constraint(equalTo: content.bottomAnchor, constant: -10.0),
|
|
imageView.bottomAnchor.constraint(equalTo: content.bottomAnchor, constant: -10.0),
|
|
imageView.widthAnchor.constraint(equalToConstant: 55.0),
|
|
imageView.widthAnchor.constraint(equalToConstant: 55.0),
|
|
imageView.heightAnchor.constraint(equalToConstant: 55.0)
|
|
imageView.heightAnchor.constraint(equalToConstant: 55.0)
|
|
])
|
|
])
|
|
|
|
+ var leadingAnchor = imageView.leadingAnchor.constraint(equalTo: content.leadingAnchor, constant: 10.0)
|
|
if data.profile.isEmpty && data.pin != "-999" && data.pin != "-997" {
|
|
if data.profile.isEmpty && data.pin != "-999" && data.pin != "-997" {
|
|
if data.messageScope == "3" {
|
|
if data.messageScope == "3" {
|
|
imageView.image = UIImage(named: "Profile---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
imageView.image = UIImage(named: "Profile---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
@@ -1748,141 +1803,36 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- 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
|
|
|
|
|
|
+ if data.messageScope == "3" || data.isParent || data.pin == "-999" {
|
|
|
|
+ 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
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ leadingAnchor = imageView.leadingAnchor.constraint(equalTo: content.leadingAnchor, constant: 40.0)
|
|
|
|
+ let image = UIImage(named: "Conversation---Purple", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
|
|
imageView.image = image
|
|
imageView.image = image
|
|
- })
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ leadingAnchor.isActive = true
|
|
|
|
+
|
|
let titleView = UILabel()
|
|
let titleView = UILabel()
|
|
content.addSubview(titleView)
|
|
content.addSubview(titleView)
|
|
titleView.translatesAutoresizingMaskIntoConstraints = false
|
|
titleView.translatesAutoresizingMaskIntoConstraints = false
|
|
NSLayoutConstraint.activate([
|
|
NSLayoutConstraint.activate([
|
|
titleView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
|
|
titleView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
|
|
- titleView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
|
|
|
|
titleView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
|
|
titleView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
|
|
])
|
|
])
|
|
- titleView.text = data.name
|
|
|
|
titleView.font = UIFont.systemFont(ofSize: 14, weight: .medium)
|
|
titleView.font = UIFont.systemFont(ofSize: 14, weight: .medium)
|
|
|
|
|
|
- let messageView = UILabel()
|
|
|
|
- content.addSubview(messageView)
|
|
|
|
- messageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- NSLayoutConstraint.activate([
|
|
|
|
- messageView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
|
|
|
|
- messageView.topAnchor.constraint(equalTo: titleView.bottomAnchor),
|
|
|
|
- messageView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
|
|
|
|
- ])
|
|
|
|
- messageView.textColor = .gray
|
|
|
|
- if data.messageText.contains("■") {
|
|
|
|
- data.messageText = data.messageText.components(separatedBy: "■")[0]
|
|
|
|
- data.messageText = data.messageText.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
- }
|
|
|
|
- let text = Utils.previewMessageText(chat: data)
|
|
|
|
- let idMe = User.getMyPin() as String?
|
|
|
|
- if let attributeText = text as? NSMutableAttributedString {
|
|
|
|
- let stringMessage = NSMutableAttributedString(string: "")
|
|
|
|
- if data.fpin == idMe {
|
|
|
|
- if data.lock == "1" {
|
|
|
|
- if data.messageScope == "4" {
|
|
|
|
- stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
- }
|
|
|
|
- stringMessage.append(("🚫 _"+"You were deleted this message".localized()+"_").richText())
|
|
|
|
- } else {
|
|
|
|
- let imageStatus = NSTextAttachment()
|
|
|
|
- let status = getRealStatus(messageId: data.messageId)
|
|
|
|
- if status == "0" {
|
|
|
|
- imageStatus.image = UIImage(systemName: "xmark.circle")!.withTintColor(UIColor.red, renderingMode: .alwaysOriginal)
|
|
|
|
- } else if status == "1" {
|
|
|
|
- imageStatus.image = UIImage(systemName: "clock.arrow.circlepath")!.withTintColor(UIColor.lightGray, renderingMode: .alwaysOriginal)
|
|
|
|
- } else if status == "2" {
|
|
|
|
- imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
|
|
|
|
- } else if (status == "3") {
|
|
|
|
- imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
|
|
|
|
- } else if (status == "8") {
|
|
|
|
- imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
|
|
|
|
- } else {
|
|
|
|
- imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
|
|
|
|
- }
|
|
|
|
- imageStatus.bounds = CGRect(x: 0, y: -5, width: 15, height: 15)
|
|
|
|
- let imageStatusString = NSAttributedString(attachment: imageStatus)
|
|
|
|
- stringMessage.append(imageStatusString)
|
|
|
|
- stringMessage.append(NSAttributedString(string: " "))
|
|
|
|
- if data.messageScope == "4" {
|
|
|
|
- stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
- }
|
|
|
|
- stringMessage.append(attributeText)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if data.messageScope == "4" {
|
|
|
|
- var fullname = User.getData(pin: data.fpin, lPin: data.pin)!.fullName
|
|
|
|
- let components = fullname.split(separator: " ")
|
|
|
|
- if components.count >= 2 {
|
|
|
|
- fullname = components.prefix(2).joined(separator: " ")
|
|
|
|
- }
|
|
|
|
- stringMessage.append(NSAttributedString(string: fullname + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
- }
|
|
|
|
- if data.lock == "1" {
|
|
|
|
- stringMessage.append(("🚫 _"+"This message was deleted".localized()+"_").richText())
|
|
|
|
- } else {
|
|
|
|
- stringMessage.append(attributeText)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- messageView.attributedText = stringMessage
|
|
|
|
- }
|
|
|
|
- messageView.numberOfLines = 2
|
|
|
|
-
|
|
|
|
let timeView = UILabel()
|
|
let timeView = UILabel()
|
|
- content.addSubview(timeView)
|
|
|
|
- timeView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- NSLayoutConstraint.activate([
|
|
|
|
- timeView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
|
|
|
|
- timeView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20.0),
|
|
|
|
- ])
|
|
|
|
- timeView.textColor = .gray
|
|
|
|
- timeView.font = UIFont.systemFont(ofSize: 14)
|
|
|
|
-
|
|
|
|
- let date = Date(milliseconds: Int64(data.serverDate)!)
|
|
|
|
- let calendar = Calendar.current
|
|
|
|
-
|
|
|
|
- if (calendar.isDateInToday(date)) {
|
|
|
|
- let formatter = DateFormatter()
|
|
|
|
- formatter.dateFormat = "HH:mm"
|
|
|
|
- formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
- timeView.text = formatter.string(from: date as Date)
|
|
|
|
- } else {
|
|
|
|
- let startOfNow = calendar.startOfDay(for: Date())
|
|
|
|
- let startOfTimeStamp = calendar.startOfDay(for: date)
|
|
|
|
- let components = calendar.dateComponents([.day], from: startOfNow, to: startOfTimeStamp)
|
|
|
|
- let day = -(components.day!)
|
|
|
|
- if day == 1 {
|
|
|
|
- timeView.text = "Yesterday".localized()
|
|
|
|
- } else {
|
|
|
|
- if day < 7 {
|
|
|
|
- let formatter = DateFormatter()
|
|
|
|
- formatter.dateFormat = "EEEE"
|
|
|
|
- let lang: String = SecureUserDefaults.shared.value(forKey: "i18n_language") ?? "en"
|
|
|
|
- if lang == "id" {
|
|
|
|
- formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
- }
|
|
|
|
- timeView.text = formatter.string(from: date)
|
|
|
|
- } else {
|
|
|
|
- let formatter = DateFormatter()
|
|
|
|
- formatter.dateFormat = "M/dd/yy"
|
|
|
|
- formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
- let stringFormat = formatter.string(from: date as Date)
|
|
|
|
- timeView.text = stringFormat
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ let viewCounter = UIView()
|
|
|
|
|
|
if data.counter != "0" {
|
|
if data.counter != "0" {
|
|
timeView.textColor = .systemRed
|
|
timeView.textColor = .systemRed
|
|
- let viewCounter = UIView()
|
|
|
|
content.addSubview(viewCounter)
|
|
content.addSubview(viewCounter)
|
|
viewCounter.translatesAutoresizingMaskIntoConstraints = false
|
|
viewCounter.translatesAutoresizingMaskIntoConstraints = false
|
|
NSLayoutConstraint.activate([
|
|
NSLayoutConstraint.activate([
|
|
- viewCounter.topAnchor.constraint(equalTo: timeView.bottomAnchor, constant: 5.0),
|
|
|
|
- viewCounter.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20),
|
|
|
|
viewCounter.widthAnchor.constraint(greaterThanOrEqualToConstant: 20),
|
|
viewCounter.widthAnchor.constraint(greaterThanOrEqualToConstant: 20),
|
|
viewCounter.heightAnchor.constraint(equalToConstant: 20)
|
|
viewCounter.heightAnchor.constraint(equalToConstant: 20)
|
|
])
|
|
])
|
|
@@ -1909,6 +1859,146 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
labelCounter.textColor = .secondaryColor
|
|
labelCounter.textColor = .secondaryColor
|
|
labelCounter.textAlignment = .center
|
|
labelCounter.textAlignment = .center
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if !data.isParent {
|
|
|
|
+ titleView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0).isActive = true
|
|
|
|
+ titleView.text = data.name
|
|
|
|
+
|
|
|
|
+ content.addSubview(timeView)
|
|
|
|
+ timeView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ timeView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
|
|
|
|
+ timeView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20.0),
|
|
|
|
+ ])
|
|
|
|
+ timeView.textColor = .gray
|
|
|
|
+ timeView.font = UIFont.systemFont(ofSize: 14)
|
|
|
|
+
|
|
|
|
+ let date = Date(milliseconds: Int64(data.serverDate) ?? 0)
|
|
|
|
+ let calendar = Calendar.current
|
|
|
|
+
|
|
|
|
+ if (calendar.isDateInToday(date)) {
|
|
|
|
+ let formatter = DateFormatter()
|
|
|
|
+ formatter.dateFormat = "HH:mm"
|
|
|
|
+ formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
+ timeView.text = formatter.string(from: date as Date)
|
|
|
|
+ } else {
|
|
|
|
+ let startOfNow = calendar.startOfDay(for: Date())
|
|
|
|
+ let startOfTimeStamp = calendar.startOfDay(for: date)
|
|
|
|
+ let components = calendar.dateComponents([.day], from: startOfNow, to: startOfTimeStamp)
|
|
|
|
+ let day = -(components.day!)
|
|
|
|
+ if day == 1 {
|
|
|
|
+ timeView.text = "Yesterday".localized()
|
|
|
|
+ } else {
|
|
|
|
+ if day < 7 {
|
|
|
|
+ let formatter = DateFormatter()
|
|
|
|
+ formatter.dateFormat = "EEEE"
|
|
|
|
+ let lang: String = SecureUserDefaults.shared.value(forKey: "i18n_language") ?? "en"
|
|
|
|
+ if lang == "id" {
|
|
|
|
+ formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
+ }
|
|
|
|
+ timeView.text = formatter.string(from: date)
|
|
|
|
+ } else {
|
|
|
|
+ let formatter = DateFormatter()
|
|
|
|
+ formatter.dateFormat = "M/dd/yy"
|
|
|
|
+ formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
|
|
|
|
+ let stringFormat = formatter.string(from: date as Date)
|
|
|
|
+ timeView.text = stringFormat
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let messageView = UILabel()
|
|
|
|
+ content.addSubview(messageView)
|
|
|
|
+ messageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ messageView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
|
|
|
|
+ messageView.topAnchor.constraint(equalTo: titleView.bottomAnchor),
|
|
|
|
+ messageView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
|
|
|
|
+ ])
|
|
|
|
+ messageView.textColor = .gray
|
|
|
|
+ if data.messageText.contains("■") {
|
|
|
|
+ data.messageText = data.messageText.components(separatedBy: "■")[0]
|
|
|
|
+ data.messageText = data.messageText.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
+ }
|
|
|
|
+ let text = Utils.previewMessageText(chat: data)
|
|
|
|
+ let idMe = User.getMyPin() as String?
|
|
|
|
+ if let attributeText = text as? NSMutableAttributedString {
|
|
|
|
+ let stringMessage = NSMutableAttributedString(string: "")
|
|
|
|
+ if data.fpin == idMe {
|
|
|
|
+ if data.lock == "1" {
|
|
|
|
+ if data.messageScope == "4" {
|
|
|
|
+ stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
+ }
|
|
|
|
+ stringMessage.append(("🚫 _"+"You were deleted this message".localized()+"_").richText())
|
|
|
|
+ } else {
|
|
|
|
+ let imageStatus = NSTextAttachment()
|
|
|
|
+ let status = getRealStatus(messageId: data.messageId)
|
|
|
|
+ if status == "0" {
|
|
|
|
+ imageStatus.image = UIImage(systemName: "xmark.circle")!.withTintColor(UIColor.red, renderingMode: .alwaysOriginal)
|
|
|
|
+ } else if status == "1" {
|
|
|
|
+ imageStatus.image = UIImage(systemName: "clock.arrow.circlepath")!.withTintColor(UIColor.lightGray, renderingMode: .alwaysOriginal)
|
|
|
|
+ } else if status == "2" {
|
|
|
|
+ imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
|
|
|
|
+ } else if (status == "3") {
|
|
|
|
+ imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
|
|
|
|
+ } else if (status == "8") {
|
|
|
|
+ imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
|
|
|
|
+ } else {
|
|
|
|
+ imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
|
|
|
|
+ }
|
|
|
|
+ imageStatus.bounds = CGRect(x: 0, y: -5, width: 15, height: 15)
|
|
|
|
+ let imageStatusString = NSAttributedString(attachment: imageStatus)
|
|
|
|
+ stringMessage.append(imageStatusString)
|
|
|
|
+ stringMessage.append(NSAttributedString(string: " "))
|
|
|
|
+ if data.messageScope == "4" {
|
|
|
|
+ stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
+ }
|
|
|
|
+ stringMessage.append(attributeText)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if data.messageScope == "4" {
|
|
|
|
+ var fullname = User.getData(pin: data.fpin, lPin: data.pin)!.fullName
|
|
|
|
+ let components = fullname.split(separator: " ")
|
|
|
|
+ if components.count >= 2 {
|
|
|
|
+ fullname = components.prefix(2).joined(separator: " ")
|
|
|
|
+ }
|
|
|
|
+ stringMessage.append(NSAttributedString(string: fullname + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .medium)]))
|
|
|
|
+ }
|
|
|
|
+ if data.lock == "1" {
|
|
|
|
+ stringMessage.append(("🚫 _"+"This message was deleted".localized()+"_").richText())
|
|
|
|
+ } else {
|
|
|
|
+ stringMessage.append(attributeText)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ messageView.attributedText = stringMessage
|
|
|
|
+ }
|
|
|
|
+ messageView.numberOfLines = 2
|
|
|
|
+
|
|
|
|
+ if data.counter != "0" {
|
|
|
|
+ viewCounter.topAnchor.constraint(equalTo: timeView.bottomAnchor, constant: 5.0).isActive = true
|
|
|
|
+ viewCounter.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20).isActive = true
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ titleView.centerYAnchor.constraint(equalTo: content.centerYAnchor).isActive = true
|
|
|
|
+ titleView.text = data.groupName
|
|
|
|
+
|
|
|
|
+ let iconName = (data.isSelected) ? "chevron.up.circle" : "chevron.down.circle"
|
|
|
|
+ let imageView = UIImageView(image: UIImage(systemName: iconName))
|
|
|
|
+ imageView.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
|
|
|
|
+ content.addSubview(imageView)
|
|
|
|
+ imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
|
+ imageView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20),
|
|
|
|
+ imageView.centerYAnchor.constraint(equalTo: content.centerYAnchor),
|
|
|
|
+ imageView.widthAnchor.constraint(equalToConstant: 20),
|
|
|
|
+ imageView.heightAnchor.constraint(equalToConstant: 20)
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ if data.counter != "0" {
|
|
|
|
+ viewCounter.trailingAnchor.constraint(equalTo: imageView.leadingAnchor, constant: -5).isActive = true
|
|
|
|
+ viewCounter.centerYAnchor.constraint(equalTo: content.centerYAnchor).isActive = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
case 1:
|
|
case 1:
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifierGroup", for: indexPath)
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifierGroup", for: indexPath)
|
|
var content = cell.defaultContentConfiguration()
|
|
var content = cell.defaultContentConfiguration()
|