From 966fa1761f60cc9e467c515030c3fedcde8a9230 Mon Sep 17 00:00:00 2001 From: Benjamin Erhart Date: Mon, 14 May 2018 15:33:13 +0200 Subject: [PATCH] Issue #603: Display "No Zom Codes for...", if there are no trusted keys AND no untrusted NEW keys for a buddy. --- .../ZomFingerprintBaseViewController.swift | 15 ++++++++++++--- .../ZomVerificationDetailViewController.swift | 13 ++++++++++--- .../ZomVerificationDetailViewController.xib | 2 +- .../ZomVerificationViewController.swift | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Zom/Zom/Classes/View Controllers/ZomFingerprintBaseViewController.swift b/Zom/Zom/Classes/View Controllers/ZomFingerprintBaseViewController.swift index f2e21de..807d718 100644 --- a/Zom/Zom/Classes/View Controllers/ZomFingerprintBaseViewController.swift +++ b/Zom/Zom/Classes/View Controllers/ZomFingerprintBaseViewController.swift @@ -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] } } diff --git a/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.swift b/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.swift index ccf2e94..0ffff09 100644 --- a/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.swift +++ b/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.swift @@ -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") + } } } diff --git a/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.xib b/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.xib index e0af086..341cae1 100644 --- a/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.xib +++ b/Zom/Zom/Classes/View Controllers/ZomVerificationDetailViewController.xib @@ -58,7 +58,7 @@ -