<commit_before>//
//  ZomFingerprintVerificationCell.swift
//  Zom
//
//  Created by <NAME> on 07.03.18.
//

import UIKit
import FormatterKit

/**
 Cell to be used in `ZomVerificationDetailViewController`.

 Shows details of an `OMEMODevice` or `OTRFingerprint`.

 The user can toggle the trust state of a key aka. fingerprint aka. device using the provided
 `self.trustStatusSwitch` except on expired OMEMO keys.
*/
class ZomFingerprintVerificationCell: UITableViewCell {

    @IBOutlet weak var trustBadge: UILabel!
    @IBOutlet weak var infoLb: UILabel!
    @IBOutlet weak var trustStatusSwitch: UISwitch!
    @IBOutlet weak var fingerprintLb: UILabel!

    weak var delegate :ZomVerificationDetailViewController?

    private var omemoDevice: OMEMODevice?
    private var otrFingerprint: OTRFingerprint?

    override func awakeFromNib() {
        super.awakeFromNib()

        // Enforce the color. It's not enough in the XIB, propably because of the themeing.
        trustStatusSwitch.onTintColor = UIColor.zomGreen
    }

    /**
     Set up this cell with an `OMEMODevice` key.

     - parameter device: The `OMEMODevice`
    */
    func set(_ device: OMEMODevice) {
        omemoDevice = device
        let trusted = device.isTrusted()

        trustBadge.backgroundColor = trusted ? UIColor.zomGreen : UIColor.zomRed

        var infos: [String] = []

        let interval = -Date().timeIntervalSince(device.lastSeenDate)
        infos.append(TTTTimeIntervalFormatter().string(forTimeInterval: interval))

        if device.isExpired() {
            infos.append(NSLocalizedString("Expired", comment: "Describing trust state of OMEMO key"))
        }
        else {
            infos.append(getTrustStateString(trusted))
        }

        infoLb.text = infos.joined(separator: ". ")

        trustStatusSwitch.isOn = trusted
        trustStatusSwitch.isEnabled = !device.isExpired()

        setFingerprint(device.humanReadableFingerprint, isNew: device.trustLevel == .untrustedNew)
    }

    /**
     Set up this cell with an `OTRFingerprint`.

     - parameter fingerprint: The `OTRFingerprint`
    */
    func set(_ fingerprint: OTRFingerprint) {
        otrFingerprint = fingerprint
        let trusted = fingerprint.isTrusted()

        trustBadge.backgroundColor = trusted ? UIColor.zomGreen : UIColor.zomRed<commit_msg>Issue #603: Hide trust toggle on expired fingerprints.<commit_after>//
//  ZomFingerprintVerificationCell.swift
//  Zom
//
//  Created by <NAME> on 07.03.18.
//

import UIKit
import FormatterKit

/**
 Cell to be used in `ZomVerificationDetailViewController`.

 Shows details of an `OMEMODevice` or `OTRFingerprint`.

 The user can toggle the trust state of a key aka. fingerprint aka. device using the provided
 `self.trustStatusSwitch` except on expired OMEMO keys.
*/
class ZomFingerprintVerificationCell: UITableViewCell {

    @IBOutlet weak var trustBadge: UILabel!
    @IBOutlet weak var infoLb: UILabel!
    @IBOutlet weak var trustStatusSwitch: UISwitch!
    @IBOutlet weak var fingerprintLb: UILabel!

    weak var delegate :ZomVerificationDetailViewController?

    private var omemoDevice: OMEMODevice?
    private var otrFingerprint: OTRFingerprint?

    override func awakeFromNib() {
        super.awakeFromNib()

        // Enforce the color. It's not enough in the XIB, propably because of the themeing.
        trustStatusSwitch.onTintColor = UIColor.zomGreen
    }

    /**
     Set up this cell with an `OMEMODevice` key.

     - parameter device: The `OMEMODevice`
    */
    func set(_ device: OMEMODevice) {
        omemoDevice = device
        let trusted = device.isTrusted()

        trustBadge.backgroundColor = trusted ? UIColor.zomGreen : UIColor.zomRed

        var infos: [String] = []

        let interval = -Date().timeIntervalSince(device.lastSeenDate)
        infos.append(TTTTimeIntervalFormatter().string(forTimeInterval: interval))

        if device.isExpired() {
            infos.append(NSLocalizedString("Expired", comment: "Describing trust state of OMEMO key"))
        }
        else {
            infos.append(getTrustStateString(trusted))
        }

        infoLb.text = infos.joined(separator: ". ")

        trustStatusSwitch.isOn = trusted
        trustStatusSwitch.isHidden = device.isExpired()

        setFingerprint(device.humanReadableFingerprint, isNew: device.trustLevel == .untrustedNew)
    }

    /**
     Set up this cell with an `OTRFingerprint`.

     - parameter fingerprint: The `OTRFingerprint`
    */
    func set(_ fingerprint: OTRFingerprint) {
        otrFingerprint = fingerprint
        let trusted = fingerprint.isTrusted()

        trustBadge.backgroundColor = trusted ? UIColor.zomGreen : UIColor.zomRed
{'fraction_non_alphanumeric': 0.08645899554990465, 'fraction_numerical': 0.003178639542275906, 'mean_word_length': 3.003392705682782, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7056836', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1402, 'n_words': 370}