|
@@ -119,6 +119,10 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
tableView.tableHeaderView = segment
|
|
tableView.tableHeaderView = segment
|
|
tableView.tableFooterView = UIView()
|
|
tableView.tableFooterView = UIView()
|
|
|
|
|
|
|
|
+ if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
|
|
|
|
+ tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 80, right: 0)
|
|
|
|
+ }
|
|
|
|
+
|
|
pullBuddy()
|
|
pullBuddy()
|
|
let cpaasMode = PrefsUtil.getCpaasMode()
|
|
let cpaasMode = PrefsUtil.getCpaasMode()
|
|
let isBurger = cpaasMode == PrefsUtil.CPAAS_MODE_BURGER
|
|
let isBurger = cpaasMode == PrefsUtil.CPAAS_MODE_BURGER
|
|
@@ -440,7 +444,7 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
|
|
|
|
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 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 "
|
|
if id.isEmpty {
|
|
if id.isEmpty {
|
|
query += "g.parent = '\(parent)'"
|
|
query += "g.parent = '\(parent)'"
|
|
} else {
|
|
} else {
|
|
@@ -460,10 +464,11 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
groupType: cursor.string(forColumnIndex: 7) ?? "",
|
|
groupType: cursor.string(forColumnIndex: 7) ?? "",
|
|
isOpen: cursor.string(forColumnIndex: 8) ?? "",
|
|
isOpen: cursor.string(forColumnIndex: 8) ?? "",
|
|
official: cursor.string(forColumnIndex: 9) ?? "",
|
|
official: cursor.string(forColumnIndex: 9) ?? "",
|
|
- isEducation: cursor.string(forColumnIndex: 10) ?? "")
|
|
|
|
|
|
+ isEducation: cursor.string(forColumnIndex: 10) ?? "",
|
|
|
|
+ level: cursor.string(forColumnIndex: 11) ?? "")
|
|
|
|
|
|
if group.chatId.isEmpty {
|
|
if group.chatId.isEmpty {
|
|
- let lounge = Group(id: group.id, name: "Lounge".localized(), profile: "", quote: group.quote, by: group.by, date: group.date, parent: group.id, chatId: group.chatId, groupType: group.groupType, isOpen: group.isOpen, official: group.official, isEducation: group.isEducation, isLounge: true)
|
|
|
|
|
|
+ let lounge = Group(id: group.id, name: "Lounge".localized(), profile: "", quote: group.quote, by: group.by, date: group.date, parent: group.id, chatId: group.chatId, groupType: group.groupType, isOpen: group.isOpen, official: group.official, isEducation: group.isEducation, isLounge: true, level: group.level != "-1" ? group.level : "2")
|
|
group.childs.append(lounge)
|
|
group.childs.append(lounge)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -480,22 +485,28 @@ class SecondTabViewController: UIViewController, UIScrollViewDelegate, UIGesture
|
|
groupType: group.groupType,
|
|
groupType: group.groupType,
|
|
isOpen: group.isOpen,
|
|
isOpen: group.isOpen,
|
|
official: group.official,
|
|
official: group.official,
|
|
- isEducation: group.isEducation)
|
|
|
|
|
|
+ isEducation: group.isEducation,
|
|
|
|
+ level: group.level != "-1" ? group.level : "2")
|
|
group.childs.append(topic)
|
|
group.childs.append(topic)
|
|
}
|
|
}
|
|
topicCursor.close()
|
|
topicCursor.close()
|
|
}
|
|
}
|
|
|
|
|
|
if !group.id.isEmpty {
|
|
if !group.id.isEmpty {
|
|
- if group.official == "1" {
|
|
|
|
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
- if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
|
|
|
|
- group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
|
- cursorUser.close()
|
|
|
|
- }
|
|
|
|
- } else if group.official != "1"{
|
|
|
|
- group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
|
- }
|
|
|
|
|
|
+// if group.official == "1" {
|
|
|
|
+// let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+// if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
|
|
|
|
+// group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
|
+// cursorUser.close()
|
|
|
|
+// }
|
|
|
|
+// } else if group.official != "1"{
|
|
|
|
+// group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
|
+// }
|
|
|
|
+ group.childs.append(contentsOf: getGroupRecursive(fmdb: fmdb, parent: group.id))
|
|
|
|
+ group.childs = group.childs.sorted(by: { $0.name < $1.name })
|
|
|
|
+ let dataLounge = group.childs.filter({$0.name == "Lounge".localized()})
|
|
|
|
+ group.childs = group.childs.filter({ $0.name != "Lounge".localized() })
|
|
|
|
+ group.childs.insert(contentsOf: dataLounge, at: 0)
|
|
}
|
|
}
|
|
data.append(group)
|
|
data.append(group)
|
|
}
|
|
}
|
|
@@ -613,148 +624,154 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
navigationController?.show(editorGroupVC, sender: nil)
|
|
navigationController?.show(editorGroupVC, sender: nil)
|
|
}
|
|
}
|
|
case 1:
|
|
case 1:
|
|
- let group: Group
|
|
|
|
- if isFilltering {
|
|
|
|
- if indexPath.row == 0 {
|
|
|
|
- group = fillteredData[indexPath.section] as! Group
|
|
|
|
- } else {
|
|
|
|
- if (fillteredData[indexPath.section] as! Group).childs.count > 0 {
|
|
|
|
- group = (fillteredData[indexPath.section] as! Group).childs[indexPath.row - 1]
|
|
|
|
- } else {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ expandCollapseGroup(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func expandCollapseGroup(tableView: UITableView, indexPath: IndexPath) {
|
|
|
|
+ let group: Group
|
|
|
|
+ if isFilltering {
|
|
|
|
+ if indexPath.row == 0 {
|
|
|
|
+ group = fillteredData[indexPath.section] as! Group
|
|
} else {
|
|
} else {
|
|
- if indexPath.row == 0 {
|
|
|
|
- group = groups[indexPath.section]
|
|
|
|
|
|
+ if (fillteredData[indexPath.section] as! Group).childs.count > 0 {
|
|
|
|
+ group = (fillteredData[indexPath.section] as! Group).childs[indexPath.row - 1]
|
|
} else {
|
|
} else {
|
|
- group = groups[indexPath.section].childs[indexPath.row - 1]
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- group.isSelected = !group.isSelected
|
|
|
|
- if !group.isSelected{
|
|
|
|
- var sects = 0
|
|
|
|
- var sect = indexPath.section
|
|
|
|
- var id = group.id
|
|
|
|
- if let _ = groupMap[id] {
|
|
|
|
- var loooop = true
|
|
|
|
- repeat {
|
|
|
|
- let c = sect + 1
|
|
|
|
- if isFilltering {
|
|
|
|
- if let o = self.fillteredData[c] as? Group {
|
|
|
|
- if o.parent == id {
|
|
|
|
- sects = sects + 1
|
|
|
|
- sect = c
|
|
|
|
- id = o.id
|
|
|
|
- (self.fillteredData[c] as! Group).isSelected = false
|
|
|
|
- self.groupMap.removeValue(forKey: (self.fillteredData[c] as! Group).id)
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- loooop = false
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if c < self.groups.count && self.groups[c].parent == id {
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if indexPath.row == 0 {
|
|
|
|
+ group = groups[indexPath.section]
|
|
|
|
+ } else {
|
|
|
|
+ group = groups[indexPath.section].childs[indexPath.row - 1]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ group.isSelected = !group.isSelected
|
|
|
|
+ if !group.isSelected{
|
|
|
|
+ var sects = 0
|
|
|
|
+ var sect = indexPath.section
|
|
|
|
+ var id = group.id
|
|
|
|
+ if let _ = groupMap[id] {
|
|
|
|
+ var loooop = true
|
|
|
|
+ repeat {
|
|
|
|
+ let c = sect + 1
|
|
|
|
+ if isFilltering {
|
|
|
|
+ if let o = self.fillteredData[c] as? Group {
|
|
|
|
+ if o.parent == id {
|
|
sects = sects + 1
|
|
sects = sects + 1
|
|
sect = c
|
|
sect = c
|
|
- id = self.groups[c].id
|
|
|
|
- self.groups[c].isSelected = false
|
|
|
|
- self.groupMap.removeValue(forKey: self.groups[c].id)
|
|
|
|
|
|
+ id = o.id
|
|
|
|
+ (self.fillteredData[c] as! Group).isSelected = false
|
|
|
|
+ self.groupMap.removeValue(forKey: (self.fillteredData[c] as! Group).id)
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
loooop = false
|
|
loooop = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } while(loooop)
|
|
|
|
- }
|
|
|
|
- for i in stride(from: sects, to: 0, by: -1){
|
|
|
|
- if isFilltering {
|
|
|
|
- self.fillteredData.remove(at: indexPath.section + i)
|
|
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- self.groups.remove(at: indexPath.section + i)
|
|
|
|
|
|
+ if c < self.groups.count && self.groups[c].parent == id {
|
|
|
|
+ sects = sects + 1
|
|
|
|
+ sect = c
|
|
|
|
+ id = self.groups[c].id
|
|
|
|
+ self.groups[c].isSelected = false
|
|
|
|
+ self.groupMap.removeValue(forKey: self.groups[c].id)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ loooop = false
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- groupMap.removeValue(forKey: group.id)
|
|
|
|
|
|
+ } while(loooop)
|
|
}
|
|
}
|
|
- if group.groupType == "NOTJOINED" {
|
|
|
|
- let alert = UIAlertController(title: "Do you want to join this group?".localized(), message: "Groups : \(group.name)\nMembers: \(group.by)".localized(), preferredStyle: .alert)
|
|
|
|
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
|
|
- alert.addAction(UIAlertAction(title: "Join".localized(), style: .default, handler: {(_) in
|
|
|
|
- self.joinOpenGroup(groupId: group.id, completion: { result in
|
|
|
|
- if result {
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- self.groupMap.removeAll()
|
|
|
|
- let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
|
- editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
|
- editorGroupVC.unique_l_pin = group.id
|
|
|
|
- self.navigationController?.show(editorGroupVC, sender: nil)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }))
|
|
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
|
- return
|
|
|
|
|
|
+ for i in stride(from: sects, to: 0, by: -1){
|
|
|
|
+ if isFilltering {
|
|
|
|
+ self.fillteredData.remove(at: indexPath.section + i)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ self.groups.remove(at: indexPath.section + i)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if group.childs.count == 0 {
|
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
|
- let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
- if let cursorMember = Database.shared.getRecords(fmdb: fmdb, query: "select f_pin from GROUPZ_MEMBER where group_id = '\(group.id)' and f_pin = '\(idMe!)'"), cursorMember.next() {
|
|
|
|
- let groupId = group.chatId.isEmpty ? group.id : group.chatId
|
|
|
|
- if let chooser = isChooser {
|
|
|
|
- chooser("4", groupId)
|
|
|
|
- dismiss(animated: true, completion: nil)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- self.groupMap.removeAll()
|
|
|
|
- let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
|
- editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
|
- editorGroupVC.unique_l_pin = groupId
|
|
|
|
- navigationController?.show(editorGroupVC, sender: nil)
|
|
|
|
- cursorMember.close()
|
|
|
|
- } else {
|
|
|
|
- var viewController = UIApplication.shared.windows.first!.rootViewController
|
|
|
|
- if !(viewController is ViewController) {
|
|
|
|
- viewController = self.parent
|
|
|
|
- }
|
|
|
|
- if let viewController = viewController as? ViewController {
|
|
|
|
- viewController.view.makeToast("You are not a member of this group".localized(), duration: 0.5)
|
|
|
|
|
|
+ groupMap.removeValue(forKey: group.id)
|
|
|
|
+ }
|
|
|
|
+ if group.groupType == "NOTJOINED" {
|
|
|
|
+ let alert = UIAlertController(title: "Do you want to join this group?".localized(), message: "Groups : \(group.name)\nMembers: \(group.by)".localized(), preferredStyle: .alert)
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
|
|
|
|
+ alert.addAction(UIAlertAction(title: "Join".localized(), style: .default, handler: {(_) in
|
|
|
|
+ self.joinOpenGroup(groupId: group.id, completion: { result in
|
|
|
|
+ if result {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ self.groupMap.removeAll()
|
|
|
|
+ let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
|
+ editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
|
+ editorGroupVC.unique_l_pin = group.id
|
|
|
|
+ self.navigationController?.show(editorGroupVC, sender: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- } else {
|
|
|
|
- if indexPath.row == 0 {
|
|
|
|
- tableView.reloadData()
|
|
|
|
|
|
+ }))
|
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if group.childs.count == 0 {
|
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
|
+ let idMe = UserDefaults.standard.string(forKey: "me") as String?
|
|
|
|
+ if let cursorMember = Database.shared.getRecords(fmdb: fmdb, query: "select f_pin from GROUPZ_MEMBER where group_id = '\(group.id)' and f_pin = '\(idMe!)'"), cursorMember.next() {
|
|
|
|
+ let groupId = group.chatId.isEmpty ? group.id : group.chatId
|
|
|
|
+ if let chooser = isChooser {
|
|
|
|
+ chooser("4", groupId)
|
|
|
|
+ dismiss(animated: true, completion: nil)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ self.groupMap.removeAll()
|
|
|
|
+ let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
|
|
|
|
+ editorGroupVC.hidesBottomBarWhenPushed = true
|
|
|
|
+ editorGroupVC.unique_l_pin = groupId
|
|
|
|
+ navigationController?.show(editorGroupVC, sender: nil)
|
|
|
|
+ cursorMember.close()
|
|
} else {
|
|
} else {
|
|
- getGroups(id: group.id) { g in
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- print("index path section: \(indexPath.section)")
|
|
|
|
- print("index path row: \(indexPath.row)")
|
|
|
|
|
|
+ var viewController = UIApplication.shared.windows.first!.rootViewController
|
|
|
|
+ if !(viewController is ViewController) {
|
|
|
|
+ viewController = self.parent
|
|
|
|
+ }
|
|
|
|
+ if let viewController = viewController as? ViewController {
|
|
|
|
+ viewController.view.makeToast("You are not a member of this group".localized(), duration: 0.5)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ if indexPath.row == 0 {
|
|
|
|
+ tableView.reloadData()
|
|
|
|
+ } else {
|
|
|
|
+ getGroups(id: group.id) { g in
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ print("index path section: \(indexPath.section)")
|
|
|
|
+ print("index path row: \(indexPath.row)")
|
|
// print("index path item: \(indexPath.item)")
|
|
// print("index path item: \(indexPath.item)")
|
|
- if self.isFilltering {
|
|
|
|
|
|
+ if self.isFilltering {
|
|
// self.fillteredData.remove(at: indexPath.section)
|
|
// self.fillteredData.remove(at: indexPath.section)
|
|
- if self.fillteredData[indexPath.section] is Group {
|
|
|
|
- self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
|
|
|
|
- self.fillteredData.insert(contentsOf: g, at: indexPath.section + 1)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
-// self.groups.remove(at: indexPath.section)
|
|
|
|
- self.groupMap[self.groups[indexPath.section].id] = 1
|
|
|
|
- self.groups.insert(contentsOf: g, at: indexPath.section + 1)
|
|
|
|
|
|
+ if self.fillteredData[indexPath.section] is Group {
|
|
|
|
+ self.groupMap[(self.fillteredData[indexPath.section] as! Group).id] = 1
|
|
|
|
+ self.fillteredData.insert(contentsOf: g, at: indexPath.section + 1)
|
|
}
|
|
}
|
|
- print("groupMap: \(self.groupMap)")
|
|
|
|
- tableView.reloadData()
|
|
|
|
|
|
+ } else {
|
|
|
|
+// self.groups.remove(at: indexPath.section)
|
|
|
|
+ self.groupMap[self.groups[indexPath.section].id] = 1
|
|
|
|
+ self.groups.insert(contentsOf: g, at: indexPath.section + 1)
|
|
}
|
|
}
|
|
|
|
+ print("groupMap: \(self.groupMap)")
|
|
|
|
+ tableView.reloadData()
|
|
|
|
+
|
|
|
|
+ self.expandCollapseGroup(tableView: tableView, indexPath: IndexPath(row: 0, section: indexPath.section + 1))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- 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)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1023,6 +1040,11 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
|
|
content.image = image
|
|
content.image = image
|
|
}
|
|
}
|
|
cell.contentConfiguration = content
|
|
cell.contentConfiguration = content
|
|
|
|
+ if group.level != "-1" && Int(group.level)! < 7 {
|
|
|
|
+ cell.contentView.layoutMargins = .init(top: 0.0, left: CGFloat(25 * Int(group.level)!), bottom: 0.0, right: 0)
|
|
|
|
+ } else if Int(group.level)! > 6 {
|
|
|
|
+ cell.contentView.layoutMargins = .init(top: 0.0, left: CGFloat(25 * (Int(group.level)! - 6)), bottom: 0.0, right: 0)
|
|
|
|
+ }
|
|
default:
|
|
default:
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifierContact", for: indexPath)
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifierContact", for: indexPath)
|
|
var content = cell.defaultContentConfiguration()
|
|
var content = cell.defaultContentConfiguration()
|