浏览代码

update fix just member can access editor group

alqindiirsyam 2 年之前
父节点
当前提交
5196d116b7

+ 26 - 12
appbuilder-ios/AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -655,7 +655,7 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                             }
                             }
                         }
                         }
                         else {
                         else {
-                            if self.groups[c].parent == id {
+                            if c < self.groups.count && self.groups[c].parent == id {
                                 sects = sects + 1
                                 sects = sects + 1
                                 sect = c
                                 sect = c
                                 id = self.groups[c].id
                                 id = self.groups[c].id
@@ -698,17 +698,31 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
                 return
                 return
             }
             }
             if group.childs.count == 0 {
             if group.childs.count == 0 {
-                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)
+                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)
+                        }
+                    }
+                })
             } else {
             } else {
                 if indexPath.row == 0 {
                 if indexPath.row == 0 {
                     tableView.reloadData()
                     tableView.reloadData()

+ 20 - 12
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -536,7 +536,7 @@ extension ContactChatViewController {
                             }
                             }
                         }
                         }
                         else {
                         else {
-                            if self.groups[c].parent == id {
+                            if c < self.groups.count && self.groups[c].parent == id {
                                 sects = sects + 1
                                 sects = sects + 1
                                 sect = c
                                 sect = c
                                 id = self.groups[c].id
                                 id = self.groups[c].id
@@ -579,17 +579,25 @@ extension ContactChatViewController {
                 return
                 return
             }
             }
             if group.childs.count == 0 {
             if group.childs.count == 0 {
-                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)
+                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 {
+                        self.view.makeToast("You are not a member of this group".localized(), duration: 0.5)
+                    }
+                })
             } else {
             } else {
                 if indexPath.row == 0 {
                 if indexPath.row == 0 {
                     tableView.reloadData()
                     tableView.reloadData()