Skip to content

Commit

Permalink
Issue zom#603: Display "No Zom Codes for...", if there are no trusted…
Browse files Browse the repository at this point in the history
… keys AND no untrusted NEW keys for a buddy.
  • Loading branch information
tladesignz committed May 14, 2018
1 parent 3dfd19d commit 966fa17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,32 @@ class ZomFingerprintBaseViewController: UIViewController {
}

/**
- returns: the total number of `.untrustedNew` OMEMO and OTR keys aka. fingerprints.
Counts the number of trusted (`.trustedTofu` and `.trustedUser`) OMEMO keys resp. OTR
fingerprints and the number of `.untrustedNew` OMEMO keys resp. OTR fingerprints.

- returns: An Array of size 2, first is number of .untrustedNew, second is number of trusted.
*/
func countUntrusted() -> Int {
func countKeys() -> [Int] {
var untrusted = 0
var trusted = 0

for device in omemoDevices {
if device.trustLevel == .untrustedNew {
untrusted += 1
} else if device.trustLevel == .trustedTofu || device.trustLevel == .trustedUser {
trusted += 1
}
}

for fingerprint in otrFingerprints {
if fingerprint.trustLevel == .untrustedNew {
untrusted += 1
} else if fingerprint.trustLevel == .trustedTofu
|| fingerprint.trustLevel == .trustedUser {
trusted += 1
}
}

return untrusted
return [trusted, untrusted]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,18 @@ class ZomVerificationDetailViewController: ZomFingerprintBaseViewController, UIT
information in the `subtitleLb` label.
*/
private func updateUntrustedNewFingerprintsInfo() {
let untrusted = countUntrusted()
let trust = countKeys()
let trusted = trust[0]
let untrusted = trust[1]

ZomFingerprintBaseViewController.setBadge(badgeLb, ok: untrusted < 1)

subtitleLb.text = NSLocalizedString("\(untrusted) Untrusted New Codes for \(buddyName())",
comment: "Subtitle for code verification detail scene")
if trusted > 0 || untrusted > 0 {
subtitleLb.text = NSLocalizedString("\(untrusted) Untrusted New Codes for \(buddyName())",
comment: "Subtitle for code verification detail scene")
} else {
subtitleLb.text = NSLocalizedString("No Zom Codes for \(buddyName())",
comment: "Subtitle for code verification detail scene")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="&lt;x&gt; Untrusted Codes for &lt;buddy&gt;" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hrq-Te-DwM">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="&lt;x&gt; Untrusted New Codes for &lt;buddy&gt;" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hrq-Te-DwM">
<rect key="frame" x="32" y="113" width="311" height="21"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<nil key="textColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ZomVerificationViewController: ZomFingerprintBaseViewController {
OTR fingerprint if no OMEMO device found.
*/
override func fingerprintsLoaded() {
ZomFingerprintBaseViewController.setBadge(badgeLb, ok: countUntrusted() < 1)
ZomFingerprintBaseViewController.setBadge(badgeLb, ok: countKeys()[1] < 1)

if let device = omemoDevices
.filter({ (device) -> Bool in return device.trustLevel == .untrustedNew })
Expand Down

0 comments on commit 966fa17

Please sign in to comment.