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

import UIKit

class AAUserViewController: AAContentTableController {
    
    var headerRow: AAAvatarRow!
    var isContactRow: AACommonRow!
    
    public init(uid: Int) {
        super.init(style: AAContentTableStyle.settingsPlain)
        
        self.uid = uid
        self.autoTrack = true
        
        self.title = AALocalized("ProfileTitle")
    }
    
    public required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func tableDidLoad() {
        
        // Profile
        section { (s) -> () in
            
            // Profile: Avatar
            self.headerRow = s.avatar { (r) -> () in
                
                r.bindAction = { (r) -> () in
                    r.id = self.uid
                    r.title = self.user.getNameModel().get()
                    r.avatar = self.user.getAvatarModel().get()
                    
                    let presence = self.user.getPresenceModel().get()
                    let presenceText = Actor.getFormatter().formatPresence(presence, with: self.user.getSex())
                    
                    if !self.isBot {
                        r.subtitle = presenceText
                        if presence!.state.ordinal() == ACUserPresence_State.online().ordinal() {
                            r.subtitleColor = self.appStyle.userOnlineColor
                        } else {
                            r.subtitleColor = self.appStyle.userOfflineColor
                        }
                    } else {
                        r.subtitle = "bot"
                        r.subtitleColor = self.appStyle.userOnlineColor
                    }
                }
                
                r.avatarDidTap = { [unowned self] (view: UIView) -> () in
                    let avatar = self.user.getAvatarModel().get()
                    if avatar != nil && avatar?.fullImage != nil {
                        
                        let full = avatar?.fullImage.fileReference
                        let small = avatar?.smallImage.fileReference
                        let size = CGSize(width: Int((avatar?.fullImage.width)!), height: Int((avatar?.fullImage.height)!))
                        
                        self.present(AAPhotoPreviewController(file: full!, previewFile: small, size: size, fromView: view), animated: true, completion: nil)
                    }
                }
            }
            
            if (ActorSDK.sharedActor().enableCalls && !self.isBot) {
                // Profile: Starting Voice Call
                s.action("CallsStartAudio") { (r) -> () in
                    r.selectAction = { () -> Bool in
                        self.execute(Actor.doCall(withUid: jint(self.uid)))
                        return false
                    }
                }
            }
            
            // Profile: Send messages
            s.action("ProfileSendMessage") { (r) -> () in
                r.selectAction = { () -> Bool in
                    if let customController = ActorSDK.sharedActor().delegate.actorControllerForConversation(ACPeer.user(with: jint(self.uid))) {
                        self.navigateDetail(customController)
                    } else {
                        self.navigateDetail(ConversationViewController(peer: ACPeer.user(with: jint(self.uid))))
                    }
                    self.popover?.dismiss(animated: true)
                    return false
                }
            }
        }
        
        let nick = self.user.getNickModel().get()
        let about = self.user.getAboutModel().get()
        
        if !self.isBot || nick != nil || about != nil {
            
            // Contact
            section { (s) -> () in
                
                // Contact: Nickname
                if let n = nick {
                    s.titled("ProfileUsername", content: "@\(n)")
                }
                
                // Contact: Phones
                s.arrays { (r: AAManagedArrayRows<ACUserPhone, AATitledCell>) -> () in
                    r.height = 55
                    r.data = self.user.getPhonesModel().get().toSwiftArray()
                    r.bindData = { (c: AATitledCell, d: ACUserPhone) -> () in
                        c.setContent(AALocalized("SettingsMobilePhone"), content: "+\(d.phone)", isAction: false)
                    }
                    r.bindCopy = { (d: ACUserPhone) -> String? in
                        return "+\(d.phone)"
                    }
                    r.selectAction = { (c: ACUserPhone) -> Bool in
                        let phoneNumber = c.phone
                        let hasPhone = UIApplication.shared.canOpenURL(URL(string: "telprompt://")!)
                        if (!hasPhone) {
                            UIPasteboard.general.string = "+\(phoneNumber)"
                            self.alertUser("NumberCopied")
                        } else {
                            ActorSDK.sharedActor().openUrl("telprompt://+\(phoneNumber)")
                        }
                        return true
                    }
                }
                
                // Contact: Emails
                s.arrays { (r: AAManagedArrayRows<ACUserEmail, AATitledCell>) -> () in
                    r.height = 55
                    r.data = self.user.getEmailsModel().get().toSwiftArray()
                    r.bindData = { (c: AATitledCell, d: ACUserEmail) -> () in
                        c.setContent(d.title, content: d.email, isAction: false)
                    }
                    r.bindCopy = { (d: ACUserEmail) -> String? in
                        return d.email
                    }
                    r.selectAction = { (c: ACUserEmail) -> Bool in
                        ActorSDK.sharedActor().openUrl("mailto:\(c.email)")
                        return true
                    }
                }
                
                // Contact: About
                if let a = about {
                    s.text("ProfileAbout", content: a)
                }
            }
        }
        
        section { (s) -> () in
            s.common { (r) -> () in
                let peer = ACPeer.user(with: jint(self.uid))
                r.style = .switch
                r.content = AALocalized("ProfileNotifications")
                
                r.bindAction = { (r) -> () in
                    r.switchOn = Actor.isNotificationsEnabled(with: peer)
                }
                
                r.switchAction = { (on: Bool) -> () in
                    if !on && !self.user.isBot() {
                        self.confirmAlertUser("ProfileNotificationsWarring",
                            action: "ProfileNotificationsWarringAction",
                            tapYes: { () -> () in
                                Actor.changeNotificationsEnabled(with: peer, withValue: false)
                            }, tapNo: { () -> () in
                                r.reload()
                        })
                        return
                    }
                    Actor.changeNotificationsEnabled(with: peer, withValue: on)
                }
                
                if(ActorSDK.sharedActor().enableChatGroupSound) {
                    if(Actor.isNotificationsEnabled(with: peer)){
                        r.selectAction = {() -> Bool in
                            // Sound: Choose sound
                            let setRingtoneController = AARingtonesViewController()
                            let sound = Actor.getNotificationsSound(with: peer)
                            setRingtoneController.selectedRingtone = (sound != nil) ? sound! : ""<commit_msg>chore(iOS): change AARingtonesViewController fields, AAUserViewController access modifiers to open<commit_after>//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import UIKit

open class AAUserViewController: AAContentTableController {
    
    var headerRow: AAAvatarRow!
    var isContactRow: AACommonRow!
    open var setRingtoneController: AARingtonesViewController
    open var sound: String
    
    public init(uid: Int) {
        super.init(style: AAContentTableStyle.settingsPlain)
        
        self.uid = uid
        self.autoTrack = true
        
        self.title = AALocalized("ProfileTitle")
    }
    
    public required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func tableDidLoad() {
        
        // Profile
        section { (s) -> () in
            
            // Profile: Avatar
            self.headerRow = s.avatar { (r) -> () in
                
                r.bindAction = { (r) -> () in
                    r.id = self.uid
                    r.title = self.user.getNameModel().get()
                    r.avatar = self.user.getAvatarModel().get()
                    
                    let presence = self.user.getPresenceModel().get()
                    let presenceText = Actor.getFormatter().formatPresence(presence, with: self.user.getSex())
                    
                    if !self.isBot {
                        r.subtitle = presenceText
                        if presence!.state.ordinal() == ACUserPresence_State.online().ordinal() {
                            r.subtitleColor = self.appStyle.userOnlineColor
                        } else {
                            r.subtitleColor = self.appStyle.userOfflineColor
                        }
                    } else {
                        r.subtitle = "bot"
                        r.subtitleColor = self.appStyle.userOnlineColor
                    }
                }
                
                r.avatarDidTap = { [unowned self] (view: UIView) -> () in
                    let avatar = self.user.getAvatarModel().get()
                    if avatar != nil && avatar?.fullImage != nil {
                        
                        let full = avatar?.fullImage.fileReference
                        let small = avatar?.smallImage.fileReference
                        let size = CGSize(width: Int((avatar?.fullImage.width)!), height: Int((avatar?.fullImage.height)!))
                        
                        self.present(AAPhotoPreviewController(file: full!, previewFile: small, size: size, fromView: view), animated: true, completion: nil)
                    }
                }
            }
            
            if (ActorSDK.sharedActor().enableCalls && !self.isBot) {
                // Profile: Starting Voice Call
                s.action("CallsStartAudio") { (r) -> () in
                    r.selectAction = { () -> Bool in
                        self.execute(Actor.doCall(withUid: jint(self.uid)))
                        return false
                    }
                }
            }
            
            // Profile: Send messages
            s.action("ProfileSendMessage") { (r) -> () in
                r.selectAction = { () -> Bool in
                    if let customController = ActorSDK.sharedActor().delegate.actorControllerForConversation(ACPeer.user(with: jint(self.uid))) {
                        self.navigateDetail(customController)
                    } else {
                        self.navigateDetail(ConversationViewController(peer: ACPeer.user(with: jint(self.uid))))
                    }
                    self.popover?.dismiss(animated: true)
                    return false
                }
            }
        }
        
        let nick = self.user.getNickModel().get()
        let about = self.user.getAboutModel().get()
        
        if !self.isBot || nick != nil || about != nil {
            
            // Contact
            section { (s) -> () in
                
                // Contact: Nickname
                if let n = nick {
                    s.titled("ProfileUsername", content: "@\(n)")
                }
                
                // Contact: Phones
                s.arrays { (r: AAManagedArrayRows<ACUserPhone, AATitledCell>) -> () in
                    r.height = 55
                    r.data = self.user.getPhonesModel().get().toSwiftArray()
                    r.bindData = { (c: AATitledCell, d: ACUserPhone) -> () in
                        c.setContent(AALocalized("SettingsMobilePhone"), content: "+\(d.phone)", isAction: false)
                    }
                    r.bindCopy = { (d: ACUserPhone) -> String? in
                        return "+\(d.phone)"
                    }
                    r.selectAction = { (c: ACUserPhone) -> Bool in
                        let phoneNumber = c.phone
                        let hasPhone = UIApplication.shared.canOpenURL(URL(string: "telprompt://")!)
                        if (!hasPhone) {
                            UIPasteboard.general.string = "+\(phoneNumber)"
                            self.alertUser("NumberCopied")
                        } else {
                            ActorSDK.sharedActor().openUrl("telprompt://+\(phoneNumber)")
                        }
                        return true
                    }
                }
                
                // Contact: Emails
                s.arrays { (r: AAManagedArrayRows<ACUserEmail, AATitledCell>) -> () in
                    r.height = 55
                    r.data = self.user.getEmailsModel().get().toSwiftArray()
                    r.bindData = { (c: AATitledCell, d: ACUserEmail) -> () in
                        c.setContent(d.title, content: d.email, isAction: false)
                    }
                    r.bindCopy = { (d: ACUserEmail) -> String? in
                        return d.email
                    }
                    r.selectAction = { (c: ACUserEmail) -> Bool in
                        ActorSDK.sharedActor().openUrl("mailto:\(c.email)")
                        return true
                    }
                }
                
                // Contact: About
                if let a = about {
                    s.text("ProfileAbout", content: a)
                }
            }
        }
        
        section { (s) -> () in
            s.common { (r) -> () in
                let peer = ACPeer.user(with: jint(self.uid))
                r.style = .switch
                r.content = AALocalized("ProfileNotifications")
                
                r.bindAction = { (r) -> () in
                    r.switchOn = Actor.isNotificationsEnabled(with: peer)
                }
                
                r.switchAction = { (on: Bool) -> () in
                    if !on && !self.user.isBot() {
                        self.confirmAlertUser("ProfileNotificationsWarring",
                            action: "ProfileNotificationsWarringAction",
                            tapYes: { () -> () in
                                Actor.changeNotificationsEnabled(with: peer, withValue: false)
                            }, tapNo: { () -> () in
                                r.reload()
                        })
                        return
                    }
                    Actor.changeNotificationsEnabled(with: peer, withValue: on)
                }
                
                if(ActorSDK.sharedActor().enableChatGroupSound) {
                    if(Actor.isNotificationsEnabled(with: peer)){
                        r.selectAction = {() -> Bool in
                            // Sound: Choose sound
                            setRingtoneController = AARingtonesViewController()
                            sound = Actor.getNotificationsSound(with: peer)
                            setRingtoneController.selectedRingtone = (sound != nil) ? sound! : ""
{'fraction_non_alphanumeric': 0.10372997276929896, 'fraction_numerical': 0.0015198530808688494, 'mean_word_length': 1.064313725490196, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2896705', 'n_tokens_mistral': 4053, 'n_tokens_neox': 3714, 'n_words': 713}