<commit_before>//
//  ConversationMoreViewManager.swift
//  Yep
//
//  Created by NIX on 16/3/8.
//  Copyright © 2016年 Catch Inc. All rights reserved.
//

import Foundation

class ConversationMoreViewManager {

    var conversation: Conversation?

    var showProfileAction: (() -> Void)?
    var toggleDoNotDisturbAction: (() -> Void)?
    var reportAction: (() -> Void)?
    var toggleBlockAction: (() -> Void)?
    var shareFeedAction: (() -> Void)?
    var updateGroupAffairAction: (() -> Void)?

    var afterGotSettingsForUserAction: ((userID: String, blocked: Bool, doNotDisturb: Bool) -> Void)?
    var afterGotSettingsForGroupAction: ((groupID: String, notificationEnabled: Bool) -> Void)?

    private var moreViewUpdatePushNotificationsAction: ((notificationEnabled: Bool) -> Void)?

    var userNotificationEnabled: Bool = true {
        didSet {
            if moreViewCreated {
                moreView.items[1] = makeDoNotDisturbItem(notificationEnabled: userNotificationEnabled)
                moreView.refreshItems()
            }
        }
    }

    var userBlocked: Bool = false {
        didSet {
            if moreViewCreated {
                moreView.items[3] = makeBlockItem(blocked: userBlocked)
                moreView.refreshItems()
            }
        }
    }

    var groupNotificationEnabled: Bool = true {
        didSet {
            if moreViewCreated {
                moreView.items[0] = makePushNotificationsItem(notificationEnabled: groupNotificationEnabled)
                moreView.refreshItems()
            }
        }
    }

    private var moreViewCreated: Bool = false

    lazy var moreView: ActionSheetView = {

        let cancelItem = ActionSheetView.Item.Cancel

        let view: ActionSheetView

        if let user = self.conversation?.withFriend {

            view = ActionSheetView(items: [
                .Detail(
                    title: NSLocalizedString("View profile", comment: ""),
                    titleColor: UIColor.darkGrayColor(),
                    action: { [weak self] in
                        self?.showProfileAction?()
                    }
                ),
                self.makeDoNotDisturbItem(notificationEnabled: user.notificationEnabled), // 1
                .Default(
                    title: NSLocalizedString("Report", comment: ""),
                    titleColor: UIColor.yepTintColor(),
                    action: { [weak self] in
                        self?.reportAction?()
                        return true
                    }
                ),
                self.makeBlockItem(blocked: user.blocked), // 3
                cancelItem,
                ]
            )

            do {
                let userID = user.userID

                settingsForUser(userID: userID, failureHandler: nil, completion: { [weak self] blocked, doNotDisturb in
                    self?.afterGotSettingsForUserAction?(userID: userID, blocked: blocked, doNotDisturb: doNotDisturb)
                })
            }

        } else if let group = self.conversation?.withGroup {

            view = ActionSheetView(items: [
                self.makePushNotificationsItem(notificationEnabled: group.notificationEnabled), // 0
                .Default(
                    title: NSLocalizedString("Share this feed", comment: ""),
                    titleColor: UIColor.yepTintColor(),
                    action: { [weak self] in
                        self?.shareFeedAction?()
                        return true
                    }
                ),
                self.updateGroupItem(group: group), // 2
                cancelItem,
                ]
            )

            do {
                self.moreViewUpdatePushNotificationsAction = { [weak self] notificationEnabled in
                    guard let strongSelf = self else { return }
                    strongSelf.moreView.items[0] = strongSelf.makePushNotificationsItem(notificationEnabled: notificationEnabled)
                    strongSelf.moreView.refreshItems()
                }

                let groupID = group.groupID

                settingsForGroup(groupID: groupID, failureHandler: nil, completion: { [weak self]  doNotDisturb in
                    self?.afterGotSettingsForGroupAction?(groupID: groupID, notificationEnabled: !doNotDisturb)
                })
            }
            
        } else {
            view = ActionSheetView(items: [])<commit_msg>add action Report for group conversation<commit_after>//
//  ConversationMoreViewManager.swift
//  Yep
//
//  Created by NIX on 16/3/8.
//  Copyright © 2016年 Catch Inc. All rights reserved.
//

import Foundation

class ConversationMoreViewManager {

    var conversation: Conversation?

    var showProfileAction: (() -> Void)?
    var toggleDoNotDisturbAction: (() -> Void)?
    var reportAction: (() -> Void)?
    var toggleBlockAction: (() -> Void)?
    var shareFeedAction: (() -> Void)?
    var updateGroupAffairAction: (() -> Void)?

    var afterGotSettingsForUserAction: ((userID: String, blocked: Bool, doNotDisturb: Bool) -> Void)?
    var afterGotSettingsForGroupAction: ((groupID: String, notificationEnabled: Bool) -> Void)?

    private var moreViewUpdatePushNotificationsAction: ((notificationEnabled: Bool) -> Void)?

    var userNotificationEnabled: Bool = true {
        didSet {
            if moreViewCreated {
                moreView.items[1] = makeDoNotDisturbItem(notificationEnabled: userNotificationEnabled)
                moreView.refreshItems()
            }
        }
    }

    var userBlocked: Bool = false {
        didSet {
            if moreViewCreated {
                moreView.items[3] = makeBlockItem(blocked: userBlocked)
                moreView.refreshItems()
            }
        }
    }

    var groupNotificationEnabled: Bool = true {
        didSet {
            if moreViewCreated {
                moreView.items[0] = makePushNotificationsItem(notificationEnabled: groupNotificationEnabled)
                moreView.refreshItems()
            }
        }
    }

    private var moreViewCreated: Bool = false

    lazy var moreView: ActionSheetView = {

        let cancelItem = ActionSheetView.Item.Cancel

        let view: ActionSheetView

        if let user = self.conversation?.withFriend {

            view = ActionSheetView(items: [
                .Detail(
                    title: NSLocalizedString("View profile", comment: ""),
                    titleColor: UIColor.darkGrayColor(),
                    action: { [weak self] in
                        self?.showProfileAction?()
                    }
                ),
                self.makeDoNotDisturbItem(notificationEnabled: user.notificationEnabled), // 1
                .Default(
                    title: NSLocalizedString("Report", comment: ""),
                    titleColor: UIColor.yepTintColor(),
                    action: { [weak self] in
                        self?.reportAction?()
                        return true
                    }
                ),
                self.makeBlockItem(blocked: user.blocked), // 3
                cancelItem,
                ]
            )

            do {
                let userID = user.userID

                settingsForUser(userID: userID, failureHandler: nil, completion: { [weak self] blocked, doNotDisturb in
                    self?.afterGotSettingsForUserAction?(userID: userID, blocked: blocked, doNotDisturb: doNotDisturb)
                })
            }

        } else if let group = self.conversation?.withGroup {

            view = ActionSheetView(items: [
                self.makePushNotificationsItem(notificationEnabled: group.notificationEnabled), // 0
                .Default(
                    title: NSLocalizedString("Share this feed", comment: ""),
                    titleColor: UIColor.yepTintColor(),
                    action: { [weak self] in
                        self?.shareFeedAction?()
                        return true
                    }
                ),
                self.updateGroupItem(group: group), // 2
                .Default(
                    title: NSLocalizedString("Report", comment: ""),
                    titleColor: UIColor.yepTintColor(),
                    action: { [weak self] in
                        self?.reportAction?()
                        return true
                    }
                ),
                cancelItem,
                ]
            )

            do {
                self.moreViewUpdatePushNotificationsAction = { [weak self] notificationEnabled in
                    guard let strongSelf = self else { return }
                    strongSelf.moreView.items[0] = strongSelf.makePushNotificationsItem(notificationEnabled: notificationEnabled)
                    strongSelf.moreView.refreshItems()
                }

                let groupID = group.groupID

                settingsForGroup(groupID: groupID, failureHandler: nil, completion: { [weak self]  doNotDisturb in
                    self?.afterGotSettingsForGroupAction?(groupID: groupID, notificationEnabled: !doNotDisturb)
                })
            }
            
        } else {
            view = ActionSheetView(items: [])
{'fraction_non_alphanumeric': 0.08840077905215321, 'fraction_numerical': 0.0034624540142826226, 'mean_word_length': 1.5847315436241611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, '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': '2276411', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2166, 'n_words': 484}