mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Refactor cross signing banner.
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Key verification banner user preferences.
|
||||
@objcMembers
|
||||
final class KeyVerificationBannerPreferences: NSObject {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum UserDefaultsKeys {
|
||||
static let hideSetupBanner = "KeyVerificationBannerPreferencesHideSetupBanner"
|
||||
}
|
||||
|
||||
static let shared = KeyVerificationBannerPreferences()
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
/// Remember to hide key backup setup banner.
|
||||
var hideSetupBanner: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: UserDefaultsKeys.hideSetupBanner)
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: UserDefaultsKeys.hideSetupBanner)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset key backup banner preferences to default values
|
||||
func reset() {
|
||||
self.hideSetupBanner = false
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
|
||||
@objc protocol KeyVerificationSetupBannerCellDelegate: class {
|
||||
func keyVerificationSetupBannerCellDidTapCloseAction(_ cell: KeyVerificationSetupBannerCell)
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
final class KeyVerificationSetupBannerCell: MXKTableViewCell, Themable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Outlets
|
||||
|
||||
@IBOutlet private weak var shieldImageView: UIImageView!
|
||||
@IBOutlet private weak var titleLabel: UILabel!
|
||||
@IBOutlet private weak var subtitleLabel: UILabel!
|
||||
@IBOutlet private weak var closeButton: UIButton!
|
||||
|
||||
// MARK: Public
|
||||
|
||||
weak var delegate: KeyVerificationSetupBannerCellDelegate?
|
||||
|
||||
// MARK: - Overrides
|
||||
|
||||
override class func defaultReuseIdentifier() -> String {
|
||||
return String(describing: self)
|
||||
}
|
||||
|
||||
override class func nib() -> UINib {
|
||||
return UINib(nibName: String(describing: self), bundle: nil)
|
||||
}
|
||||
|
||||
override func customizeRendering() {
|
||||
super.customizeRendering()
|
||||
|
||||
let theme = ThemeService.shared().theme
|
||||
self.update(theme: theme)
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
// TODO: Image size is too small, use an higher resolution one.
|
||||
let shieldImage = Asset.Images.encryptionNormal.image.withRenderingMode(.alwaysTemplate)
|
||||
self.shieldImageView.image = shieldImage
|
||||
|
||||
let closeImage = Asset.Images.closeBanner.image.withRenderingMode(.alwaysTemplate)
|
||||
self.closeButton.setImage(closeImage, for: .normal)
|
||||
|
||||
self.titleLabel.text = VectorL10n.keyVerificationSetupBannerTitle
|
||||
self.subtitleLabel.text = VectorL10n.keyVerificationSetupBannerSubtitle
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func update(theme: Theme) {
|
||||
self.shieldImageView.tintColor = theme.textPrimaryColor
|
||||
self.closeButton.tintColor = theme.textPrimaryColor
|
||||
|
||||
self.titleLabel.textColor = theme.textPrimaryColor
|
||||
self.subtitleLabel.textColor = theme.textPrimaryColor
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction private func closeButtonAction(_ sender: Any) {
|
||||
self.delegate?.keyVerificationSetupBannerCellDidTapCloseAction(self)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="81" id="KGk-i7-Jjw" customClass="KeyVerificationSetupBannerCell" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="651" height="81"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
|
||||
<rect key="frame" x="0.0" y="0.0" width="651" height="80.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="encryption_normal" translatesAutoresizingMaskIntoConstraints="NO" id="9tN-7x-mQY">
|
||||
<rect key="frame" x="20" y="24.5" width="32" height="32"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="32" id="34F-3o-CxQ"/>
|
||||
<constraint firstAttribute="width" secondItem="9tN-7x-mQY" secondAttribute="height" multiplier="1:1" id="Anh-L2-mpZ"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" verticalCompressionResistancePriority="751" axis="vertical" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="YjT-XC-M1w">
|
||||
<rect key="frame" x="77" y="15" width="512" height="50.5"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="Set up encryption" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Rt-ER-z7l">
|
||||
<rect key="frame" x="0.0" y="0.0" width="512" height="24"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Verify your other devices easier" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yvG-ND-8Ms">
|
||||
<rect key="frame" x="0.0" y="26" width="512" height="24.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</stackView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dfM-HD-aqv">
|
||||
<rect key="frame" x="599" y="3" width="44" height="44"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="dfM-HD-aqv" secondAttribute="height" multiplier="1:1" id="A8j-ze-vop"/>
|
||||
<constraint firstAttribute="width" constant="44" id="sOg-81-aX8"/>
|
||||
</constraints>
|
||||
<state key="normal" image="close_banner"/>
|
||||
<connections>
|
||||
<action selector="closeButtonAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="JMQ-qw-PgK"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="YjT-XC-M1w" firstAttribute="top" secondItem="dfM-HD-aqv" secondAttribute="top" constant="12" id="4UB-Os-k5Z"/>
|
||||
<constraint firstItem="YjT-XC-M1w" firstAttribute="leading" secondItem="9tN-7x-mQY" secondAttribute="trailing" constant="25" id="CaN-sn-hIV"/>
|
||||
<constraint firstItem="9tN-7x-mQY" firstAttribute="top" relation="greaterThanOrEqual" secondItem="H2p-sc-9uM" secondAttribute="top" id="L5g-jO-DTI"/>
|
||||
<constraint firstItem="9tN-7x-mQY" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Nyv-QV-Pnf"/>
|
||||
<constraint firstItem="9tN-7x-mQY" firstAttribute="centerY" secondItem="YjT-XC-M1w" secondAttribute="centerY" id="VaS-Jr-0Su"/>
|
||||
<constraint firstItem="YjT-XC-M1w" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="15" id="Xz8-dz-WeL"/>
|
||||
<constraint firstItem="dfM-HD-aqv" firstAttribute="leading" secondItem="YjT-XC-M1w" secondAttribute="trailing" constant="10" id="Zwn-hH-GnQ"/>
|
||||
<constraint firstItem="9tN-7x-mQY" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="20" id="fmU-wC-fm5"/>
|
||||
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="9tN-7x-mQY" secondAttribute="bottom" id="gKz-je-baW"/>
|
||||
<constraint firstAttribute="bottom" secondItem="YjT-XC-M1w" secondAttribute="bottom" constant="15" id="nub-27-ohD"/>
|
||||
<constraint firstAttribute="trailing" secondItem="dfM-HD-aqv" secondAttribute="trailing" constant="8" id="xSp-FZ-mzB"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="closeButton" destination="dfM-HD-aqv" id="Yw7-ny-zfU"/>
|
||||
<outlet property="shieldImageView" destination="9tN-7x-mQY" id="8sk-aT-hTz"/>
|
||||
<outlet property="subtitleLabel" destination="yvG-ND-8Ms" id="Fvg-a0-Mx3"/>
|
||||
<outlet property="titleLabel" destination="3Rt-ER-z7l" id="pLB-4l-jTK"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="-1503.2" y="-521.28935532233891"/>
|
||||
</tableViewCell>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="close_banner" width="10" height="10"/>
|
||||
<image name="encryption_normal" width="16" height="16"/>
|
||||
</resources>
|
||||
</document>
|
||||
@@ -16,17 +16,15 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers
|
||||
final class KeyVerificationService: NSObject {
|
||||
final class KeyVerificationService {
|
||||
|
||||
private let cameraAccessManager: CameraAccessManager
|
||||
|
||||
private var authenticatedSessionFactory: AuthenticatedSessionViewControllerFactory?
|
||||
private var supportSetupKeyVerificationByUser: [String: Bool] = [:] // Cached server response
|
||||
|
||||
override init() {
|
||||
init() {
|
||||
self.cameraAccessManager = CameraAccessManager()
|
||||
super.init()
|
||||
}
|
||||
|
||||
func supportedKeyVerificationMethods() -> [String] {
|
||||
@@ -42,43 +40,4 @@ final class KeyVerificationService: NSObject {
|
||||
|
||||
return supportedMethods
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func canSetupKeyVerification(for session: MXSession, success: @escaping ((Bool) -> Void), failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? {
|
||||
|
||||
guard let crossSigning = session.crypto?.crossSigning, crossSigning.state == .notBootstrapped else {
|
||||
// Cross-signing already setup
|
||||
success(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
let userId: String = session.myUserId
|
||||
|
||||
if let supportSetupKeyVerification = self.supportSetupKeyVerificationByUser[userId] {
|
||||
// Return cached response
|
||||
success(supportSetupKeyVerification)
|
||||
return nil
|
||||
}
|
||||
|
||||
let authenticatedSessionFactory = AuthenticatedSessionViewControllerFactory(session: session)
|
||||
|
||||
self.authenticatedSessionFactory = authenticatedSessionFactory
|
||||
|
||||
let path = "\(kMXAPIPrefixPathUnstable)/keys/device_signing/upload"
|
||||
|
||||
return authenticatedSessionFactory.hasSupport(forPath: path, httpMethod: "POST", success: { [weak self] succeeded in
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
self.authenticatedSessionFactory = nil
|
||||
self.supportSetupKeyVerificationByUser[userId] = succeeded
|
||||
success(succeeded)
|
||||
}, failure: { [weak self] error in
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
self.authenticatedSessionFactory = nil
|
||||
failure(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user