|
@@ -18,8 +18,6 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
|
|
|
var chats: [Chat] = []
|
|
var chats: [Chat] = []
|
|
|
|
|
|
- var contacts: [User] = []
|
|
|
|
-
|
|
|
|
var groups: [Group] = []
|
|
var groups: [Group] = []
|
|
|
|
|
|
var cancelSearchButton = UIBarButtonItem()
|
|
var cancelSearchButton = UIBarButtonItem()
|
|
@@ -380,16 +378,16 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
} else {
|
|
} else {
|
|
searchController.searchBar.placeholder = "Search groups name".localized()
|
|
searchController.searchBar.placeholder = "Search groups name".localized()
|
|
}
|
|
}
|
|
- removeAllData()
|
|
|
|
|
|
+// removeAllData()
|
|
getData()
|
|
getData()
|
|
}
|
|
}
|
|
|
|
|
|
- func removeAllData() {
|
|
|
|
- groups.removeAll()
|
|
|
|
- groupMap.removeAll()
|
|
|
|
- chats.removeAll()
|
|
|
|
- tableView.reloadData()
|
|
|
|
- }
|
|
|
|
|
|
+// func removeAllData() {
|
|
|
|
+// groups.removeAll()
|
|
|
|
+// groupMap.removeAll()
|
|
|
|
+// chats.removeAll()
|
|
|
|
+// tableView.reloadData()
|
|
|
|
+// }
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
tabBarController?.navigationItem.leftBarButtonItem = nil
|
|
tabBarController?.navigationItem.leftBarButtonItem = nil
|
|
@@ -436,28 +434,25 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
|
|
|
func getData() {
|
|
func getData() {
|
|
getChats {
|
|
getChats {
|
|
- self.getContacts {
|
|
|
|
- self.getGroups { g1 in
|
|
|
|
- self.groupMap.removeAll()
|
|
|
|
- self.groups.removeAll()
|
|
|
|
- self.groups.append(contentsOf: g1)
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.tableView.reloadData()
|
|
|
|
- }
|
|
|
|
- DispatchQueue.global().async {
|
|
|
|
- self.getOpenGroups(listGroups: g1, completion: { g in
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- for og in g {
|
|
|
|
- if self.groups.first(where: { $0.id == og.id }) == nil {
|
|
|
|
- self.groups.append(og)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.tableView.reloadData()
|
|
|
|
|
|
+ self.getGroups { g1 in
|
|
|
|
+ self.groupMap.removeAll()
|
|
|
|
+ self.groups = g1
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ self.getOpenGroups(listGroups: g1, completion: { g in
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ for og in g {
|
|
|
|
+ if self.groups.first(where: { $0.id == og.id }) == nil {
|
|
|
|
+ self.groups.append(og)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -465,36 +460,11 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
|
|
|
func getChats(completion: @escaping ()->()) {
|
|
func getChats(completion: @escaping ()->()) {
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- self.chats.removeAll()
|
|
|
|
- self.chats.append(contentsOf: Chat.getData())
|
|
|
|
|
|
+ self.chats = Chat.getData()
|
|
completion()
|
|
completion()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private func getContacts(completion: @escaping ()->()) {
|
|
|
|
- DispatchQueue.global().async {
|
|
|
|
- self.contacts.removeAll()
|
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
|
- if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT f_pin, first_name, last_name, image_id, official_account, user_type FROM BUDDY where f_pin <> '\(UserDefaults.standard.string(forKey: "me")!)' order by 5 desc, 2 collate nocase asc") {
|
|
|
|
- while cursorData.next() {
|
|
|
|
- let user = User(pin: cursorData.string(forColumnIndex: 0) ?? "",
|
|
|
|
- firstName: cursorData.string(forColumnIndex: 1) ?? "",
|
|
|
|
- lastName: cursorData.string(forColumnIndex: 2) ?? "",
|
|
|
|
- thumb: cursorData.string(forColumnIndex: 3) ?? "",
|
|
|
|
- userType: cursorData.string(forColumnIndex: 5) ?? "")
|
|
|
|
- if (user.firstName + " " + user.lastName).trimmingCharacters(in: .whitespaces) == "USR\(user.pin)" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- user.official = cursorData.string(forColumnIndex: 4) ?? ""
|
|
|
|
- self.contacts.append(user)
|
|
|
|
- }
|
|
|
|
- cursorData.close()
|
|
|
|
- }
|
|
|
|
- completion()
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private func getGroupRecursive(fmdb: FMDatabase, id: String = "", parent: String = "") -> [Group] {
|
|
private func getGroupRecursive(fmdb: FMDatabase, id: String = "", parent: String = "") -> [Group] {
|
|
var data: [Group] = []
|
|
var data: [Group] = []
|
|
var query = "select g.group_id, g.f_name, g.image_id, g.quote, g.created_by, g.created_date, g.parent, g.group_type, g.is_open, g.official, g.is_education, g.level from GROUPZ g where "
|
|
var query = "select g.group_id, g.f_name, g.image_id, g.quote, g.created_by, g.created_date, g.parent, g.group_type, g.is_open, g.official, g.is_education, g.level from GROUPZ g where "
|
|
@@ -680,11 +650,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
case 1:
|
|
case 1:
|
|
expandCollapseGroup(tableView: tableView, indexPath: indexPath)
|
|
expandCollapseGroup(tableView: tableView, indexPath: indexPath)
|
|
default:
|
|
default:
|
|
- let data = contacts[indexPath.row]
|
|
|
|
- let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
|
|
|
|
- editorPersonalVC.hidesBottomBarWhenPushed = true
|
|
|
|
- editorPersonalVC.unique_l_pin = data.pin
|
|
|
|
- navigationController?.show(editorPersonalVC, sender: nil)
|
|
|
|
|
|
+ expandCollapseGroup(tableView: tableView, indexPath: indexPath)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|