<commit_before>//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import Foundation

open class AAGroupViewMembersController: AAContentTableController {
    
    fileprivate var membersRow: AAManagedArrayRows<ACGroupMember, AAGroupMemberCell>!
    
    fileprivate var isLoaded = false
    fileprivate var isLoading = false
    open var nextBatch: IOSByteArray! = nil
    
    public init(gid: Int) {
        super.init(style: .plain)
        self.gid = gid
        
        navigationItem.title = AALocalized("GroupViewMembers")
        
        if group.isCanInviteMembers.get().booleanValue() {
            navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(didAddPressed))
        }
    }
    
    public required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open override func tableDidLoad() {
        section { (s) in
            self.membersRow = s.arrays({ (r: AAManagedArrayRows<ACGroupMember, AAGroupMemberCell>) -> () in
                r.height = 48
                r.data = [ACGroupMember]()
                
                r.bindData = { (c, d) -> () in
                    let user = Actor.getUserWithUid(d.uid)
                    c.bind(user, isAdmin: d.isAdministrator)
                    
                    // Notify to request onlines
                    Actor.onUserVisible(withUid: d.uid)
                }
                
                r.itemShown = { (index, d) in
                    if index > r.data.count - 10 {
                        self.loadMore()
                    }
                }
                
                r.selectAction = { (d) -> Bool in
                    let user = Actor.getUserWithUid(d.uid)
                    if (user.getId() == Actor.myUid()) {
                        return true
                    }
                    
                    self.alertSheet { (a: AAAlertSetting) -> () in
                        
                        a.cancel = "AlertCancel"
                        
                        a.action("GroupMemberInfo") { () -> () in
                            var controller: AAViewController! = ActorSDK.sharedActor().delegate.actorControllerForUser(Int(user.getId()))
                            if controller == nil {
                                controller = AAUserViewController(uid: Int(user.getId()))
                            }
                            self.navigateNext(controller, removeCurrent: false)
                        }
                        
                        a.action("GroupMemberWrite") { () -> () in
                            if let customController = ActorSDK.sharedActor().delegate.actorControllerForConversation(ACPeer.user(with: user.getId())) {
                                self.navigateDetail(customController)
                            } else {
                                self.navigateDetail(ConversationViewController(peer: ACPeer.user(with: user.getId())))
                            }
                            self.popover?.dismiss(animated: true)
                        }
                        
                        a.action("GroupMemberCall", closure: { () -> () in
                            let phones = user.getPhonesModel().get()!
                            if phones.size() == 0 {
                                self.alertUser("GroupMemberCallNoPhones")
                            } else if phones.size() == 1 {
                                let number = phones.getWith(0)!
                                ActorSDK.sharedActor().openUrl("telprompt://+\(number.phone)")
                            } else {
                                
                                var numbers = [String]()
                                for i in 0..<phones.size() {
                                    let p = phones.getWith(i)!
                                    numbers.append("\(p.title): +\(p.phone)")
                                }
                                self.showActionSheet(numbers,
                                    cancelButton: "AlertCancel",
                                    destructButton: nil,
                                    sourceView: self.view,
                                    sourceRect: self.view.bounds,
                                    tapClosure: { (index) -> () in
                                        if (index >= 0) {
                                            let number = phones.getWith(jint(index))!
                                            ActorSDK.sharedActor().openUrl("telprompt://+\(number.phone)")
                                        }
                                })
                            }
                        })
                        
                        // Can kick user
                        let canKick: Bool =
                            (self.group.isCanKickAnyone.get().booleanValue() ||
                                (self.group.isCanKickInvited.get().booleanValue() && d.inviterUid == Actor.myUid()))
                        
                        if canKick {
                            let isChannel = self.group.groupType == ACGroupType.channel()
                            let name = Actor.getUserWithUid(d.uid).getNameModel().get()
                            a.destructive(isChannel ? "ChannelMemberKick" : "GroupMemberKick") { () -> () in
                                self.confirmDestructive(AALocalized(isChannel ? "ChannelMemberKickMessage" : "GroupMemberKickMessage")
                                    .replace("{name}", dest: name!), action: AALocalized(isChannel ? "ChannelMemberKickAction" : "GroupMemberKickAction")) {
                                        self.executeSafe(Actor.kickMemberCommand(withGid: jint(self.gid), withUid: user.getId()))
                                }
                            }
                        }
                    }
                    
                    return true
                }
            })
        }
        
        loadMore()
    }
    
    fileprivate func loadMore() {
        if isLoading {
            return
        }
        if isLoaded {
            return
        }
        
        isLoading = true
        Actor.loadMembers(withGid: jint(gid), withLimit: 20, withNext: nextBatch).then { (slice: ACGroupMembersSlice!) in
            for i in 0..<slice.members.size() {
                self.membersRow.data.append(slice.members.getWith(i) as! ACGroupMember)
            }
            self.tableView.reloadData()
            if slice.next == nil {
                self.nextBatch = nil
                self.isLoaded = true
            }
            self.isLoading = false
        }
    }
    
    func didAddPressed() {
        navigateNext(AAAddParticipantViewController(gid: self.gid))
    }
}<commit_msg>fix(iOS): remove from members list after kick<commit_after>//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import Foundation

open class AAGroupViewMembersController: AAContentTableController {
    
    fileprivate var membersRow: AAManagedArrayRows<ACGroupMember, AAGroupMemberCell>!
    
    fileprivate var isLoaded = false
    fileprivate var isLoading = false
    open var nextBatch: IOSByteArray! = nil
    
    public init(gid: Int) {
        super.init(style: .plain)
        self.gid = gid
        
        navigationItem.title = AALocalized("GroupViewMembers")
        
        if group.isCanInviteMembers.get().booleanValue() {
            navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(didAddPressed))
        }
    }
    
    public required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open override func tableDidLoad() {
        section { (s) in
            self.membersRow = s.arrays({ (r: AAManagedArrayRows<ACGroupMember, AAGroupMemberCell>) -> () in
                r.height = 48
                r.data = [ACGroupMember]()
                
                r.bindData = { (c, d) -> () in
                    let user = Actor.getUserWithUid(d.uid)
                    c.bind(user, isAdmin: d.isAdministrator)
                    
                    // Notify to request onlines
                    Actor.onUserVisible(withUid: d.uid)
                }
                
                var id = 0
                r.itemShown = { (index, d) in
                    id = index
                    if index > r.data.count - 10 {
                        self.loadMore()
                    }
                }
                
                r.selectAction = { (d) -> Bool in
                    let user = Actor.getUserWithUid(d.uid)
                    if (user.getId() == Actor.myUid()) {
                        return true
                    }
                    
                    self.alertSheet { (a: AAAlertSetting) -> () in
                        
                        a.cancel = "AlertCancel"
                        
                        a.action("GroupMemberInfo") { () -> () in
                            var controller: AAViewController! = ActorSDK.sharedActor().delegate.actorControllerForUser(Int(user.getId()))
                            if controller == nil {
                                controller = AAUserViewController(uid: Int(user.getId()))
                            }
                            self.navigateNext(controller, removeCurrent: false)
                        }
                        
                        a.action("GroupMemberWrite") { () -> () in
                            if let customController = ActorSDK.sharedActor().delegate.actorControllerForConversation(ACPeer.user(with: user.getId())) {
                                self.navigateDetail(customController)
                            } else {
                                self.navigateDetail(ConversationViewController(peer: ACPeer.user(with: user.getId())))
                            }
                            self.popover?.dismiss(animated: true)
                        }
                        
                        a.action("GroupMemberCall", closure: { () -> () in
                            let phones = user.getPhonesModel().get()!
                            if phones.size() == 0 {
                                self.alertUser("GroupMemberCallNoPhones")
                            } else if phones.size() == 1 {
                                let number = phones.getWith(0)!
                                ActorSDK.sharedActor().openUrl("telprompt://+\(number.phone)")
                            } else {
                                
                                var numbers = [String]()
                                for i in 0..<phones.size() {
                                    let p = phones.getWith(i)!
                                    numbers.append("\(p.title): +\(p.phone)")
                                }
                                self.showActionSheet(numbers,
                                    cancelButton: "AlertCancel",
                                    destructButton: nil,
                                    sourceView: self.view,
                                    sourceRect: self.view.bounds,
                                    tapClosure: { (index) -> () in
                                        if (index >= 0) {
                                            let number = phones.getWith(jint(index))!
                                            ActorSDK.sharedActor().openUrl("telprompt://+\(number.phone)")
                                        }
                                })
                            }
                        })
                        
                        // Can kick user
                        let canKick: Bool =
                            (self.group.isCanKickAnyone.get().booleanValue() ||
                                (self.group.isCanKickInvited.get().booleanValue() && d.inviterUid == Actor.myUid()))
                        
                        if canKick {
                            let isChannel = self.group.groupType == ACGroupType.channel()
                            let name = Actor.getUserWithUid(d.uid).getNameModel().get()
                            a.destructive(isChannel ? "ChannelMemberKick" : "GroupMemberKick") { () -> () in
                                self.confirmDestructive(AALocalized(isChannel ? "ChannelMemberKickMessage" : "GroupMemberKickMessage")
                                    .replace("{name}", dest: name!), action: AALocalized(isChannel ? "ChannelMemberKickAction" : "GroupMemberKickAction")) {
                                        self.executeSafe(Actor.kickMemberCommand(withGid: jint(self.gid), withUid: user.getId()), successBlock: { (r) in
                                            self.membersRow.data.remove(at: id)
                                            self.tableView.reloadData()
                                        })
                                }
                            }
                        }
                    }
                    
                    return true
                }
            })
        }
        
        loadMore()
    }
    
    fileprivate func loadMore() {
        if isLoading {
            return
        }
        if isLoaded {
            return
        }
        
        isLoading = true
        Actor.loadMembers(withGid: jint(gid), withLimit: 20, withNext: nextBatch).then { (slice: ACGroupMembersSlice!) in
            for i in 0..<slice.members.size() {
                self.membersRow.data.append(slice.members.getWith(i) as! ACGroupMember)
            }
            self.tableView.reloadData()
            if slice.next == nil {
                self.nextBatch = nil
                self.isLoaded = true
            }
            self.isLoading = false
        }
    }
    
    
    
    func didAddPressed() {
        navigateNext(AAAddParticipantViewController(gid: self.gid))
    }
}
{'fraction_non_alphanumeric': 0.0926867146689256, 'fraction_numerical': 0.00289425384723987, 'mean_word_length': 1.0001411831144995, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 47, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6022078', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3208, 'n_words': 575}