summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-11-01 06:32:20 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-11-03 10:58:53 +0100
commitd44ffae4df69e8203751e676e5e9ea29d223675c (patch)
tree93dcf03a540aafb0f9dddb7e60fa245e42fd968e
parentb8523b04e98e444f199ab3718adb48f8faf7bd55 (diff)
downloadmullvadvpn-d44ffae4df69e8203751e676e5e9ea29d223675c.tar.xz
mullvadvpn-d44ffae4df69e8203751e676e5e9ea29d223675c.zip
Add problem report interactor
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj4
-rw-r--r--ios/MullvadVPN/ProblemReportInteractor.swift64
-rw-r--r--ios/MullvadVPN/ProblemReportViewController.swift50
3 files changed, 85 insertions, 33 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 73b7b77a3e..95624211f7 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -160,6 +160,7 @@
5875960A26F371FC00BF6711 /* Tunnel+Messaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5875960926F371FC00BF6711 /* Tunnel+Messaging.swift */; };
5877D70F282137E8002FCFC7 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FF2C02281BDE02009EF542 /* SettingsManager.swift */; };
5878A27329091D6D0096FC88 /* TunnelBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27229091D6D0096FC88 /* TunnelBlockObserver.swift */; };
+ 5878A26F2907E7E00096FC88 /* ProblemReportInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A26E2907E7E00096FC88 /* ProblemReportInteractor.swift */; };
5878A27529093A310096FC88 /* StorePaymentEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27429093A310096FC88 /* StorePaymentEvent.swift */; };
5878A27729093A4F0096FC88 /* StorePaymentBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A27629093A4F0096FC88 /* StorePaymentBlockObserver.swift */; };
5878A279290954790096FC88 /* ConnectInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5878A278290954790096FC88 /* ConnectInteractor.swift */; };
@@ -643,6 +644,7 @@
58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConstraints.swift; sourceTree = "<group>"; };
58781CD422AFBA39009B9D8E /* RelaySelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelector.swift; sourceTree = "<group>"; };
5878A27229091D6D0096FC88 /* TunnelBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelBlockObserver.swift; sourceTree = "<group>"; };
+ 5878A26E2907E7E00096FC88 /* ProblemReportInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProblemReportInteractor.swift; sourceTree = "<group>"; };
5878A27429093A310096FC88 /* StorePaymentEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePaymentEvent.swift; sourceTree = "<group>"; };
5878A27629093A4F0096FC88 /* StorePaymentBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePaymentBlockObserver.swift; sourceTree = "<group>"; };
5878A278290954790096FC88 /* ConnectInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectInteractor.swift; sourceTree = "<group>"; };
@@ -1293,6 +1295,7 @@
58EF580A25D69D7A00AEBA94 /* ProblemReportSubmissionOverlayView.swift */,
58293FAC2510CA58005D0BB5 /* ProblemReportViewController.swift */,
585DA87526B0249A00B8C587 /* RelayCache */,
+ 5878A26E2907E7E00096FC88 /* ProblemReportInteractor.swift */,
06FAE67828F83CA50033DD93 /* RESTCreateApplePaymentResponse+Localization.swift */,
58F1311427E0B2AB007AC5BC /* Result+Extensions.swift */,
580909D22876D09A0078138D /* RevokedDeviceViewController.swift */,
@@ -2148,6 +2151,7 @@
587EB66A270EFACB00123C75 /* CharacterSet+IPAddress.swift in Sources */,
5888AD83227B11080051EB06 /* SelectLocationCell.swift in Sources */,
5891BF1C25E3E3EB006D6FB0 /* Bundle+ProductVersion.swift in Sources */,
+ 5878A26F2907E7E00096FC88 /* ProblemReportInteractor.swift in Sources */,
5807E2C02432038B00F5FF30 /* String+Split.swift in Sources */,
58CE5E66224146200008646E /* LoginViewController.swift in Sources */,
58EF580B25D69D7A00AEBA94 /* ProblemReportSubmissionOverlayView.swift in Sources */,
diff --git a/ios/MullvadVPN/ProblemReportInteractor.swift b/ios/MullvadVPN/ProblemReportInteractor.swift
new file mode 100644
index 0000000000..744eedcbac
--- /dev/null
+++ b/ios/MullvadVPN/ProblemReportInteractor.swift
@@ -0,0 +1,64 @@
+//
+// ProblemReportInteractor.swift
+// MullvadVPN
+//
+// Created by pronebird on 25/10/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import MullvadREST
+import MullvadTypes
+import Operations
+
+final class ProblemReportInteractor {
+ private let apiProxy: REST.APIProxy
+ private let tunnelManager: TunnelManager
+
+ private lazy var consolidatedLog: ConsolidatedApplicationLog = {
+ let securityGroupIdentifier = ApplicationConfiguration.securityGroupIdentifier
+
+ // TODO: make sure we redact old tokens
+
+ let redactStrings = [tunnelManager.deviceState.accountData?.number].compactMap { $0 }
+
+ let report = ConsolidatedApplicationLog(
+ redactCustomStrings: redactStrings,
+ redactContainerPathsForSecurityGroupIdentifiers: [securityGroupIdentifier]
+ )
+
+ report.addLogFiles(fileURLs: ApplicationConfiguration.logFileURLs, includeLogBackups: true)
+
+ return report
+ }()
+
+ init(apiProxy: REST.APIProxy, tunnelManager: TunnelManager) {
+ self.apiProxy = apiProxy
+ self.tunnelManager = tunnelManager
+ }
+
+ func sendReport(
+ email: String,
+ message: String,
+ completion: @escaping (OperationCompletion<Void, REST.Error>) -> Void
+ ) -> Cancellable {
+ let request = REST.ProblemReportRequest(
+ address: email,
+ message: message,
+ log: consolidatedLog.string,
+ metadata: consolidatedLog.metadata.reduce(into: [:]) { output, entry in
+ output[entry.key.rawValue] = entry.value
+ }
+ )
+
+ return apiProxy.sendProblemReport(
+ request,
+ retryStrategy: .default,
+ completionHandler: completion
+ )
+ }
+
+ var reportString: String {
+ return consolidatedLog.string
+ }
+}
diff --git a/ios/MullvadVPN/ProblemReportViewController.swift b/ios/MullvadVPN/ProblemReportViewController.swift
index 5a543b5746..622cc1600c 100644
--- a/ios/MullvadVPN/ProblemReportViewController.swift
+++ b/ios/MullvadVPN/ProblemReportViewController.swift
@@ -7,33 +7,16 @@
//
import MullvadREST
+import MullvadTypes
import Operations
import UIKit
class ProblemReportViewController: UIViewController, UITextFieldDelegate, ConditionalNavigation {
- private let apiProxy = REST.ProxyFactory.shared.createAPIProxy()
+ private let interactor: ProblemReportInteractor
private var textViewKeyboardResponder: AutomaticKeyboardResponder?
private var scrollViewKeyboardResponder: AutomaticKeyboardResponder?
- private lazy var consolidatedLog: ConsolidatedApplicationLog = {
- let securityGroupIdentifier = ApplicationConfiguration.securityGroupIdentifier
-
- // TODO: make sure we redact old tokens
-
- let redactStrings = [TunnelManager.shared.deviceState.accountData?.number]
- .compactMap { $0 }
-
- let report = ConsolidatedApplicationLog(
- redactCustomStrings: redactStrings,
- redactContainerPathsForSecurityGroupIdentifiers: [securityGroupIdentifier]
- )
-
- report.addLogFiles(fileURLs: ApplicationConfiguration.logFileURLs, includeLogBackups: true)
-
- return report
- }()
-
/// Scroll view
private lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView()
@@ -204,6 +187,16 @@ class ProblemReportViewController: UIViewController, UITextFieldDelegate, Condit
return false
}
+ init(interactor: ProblemReportInteractor) {
+ self.interactor = interactor
+
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
override func viewDidLoad() {
super.viewDidLoad()
@@ -283,7 +276,7 @@ class ProblemReportViewController: UIViewController, UITextFieldDelegate, Condit
@objc func handleViewLogsButtonTap() {
let reviewController = ProblemReportReviewViewController(
- reportString: consolidatedLog.string
+ reportString: interactor.reportString
)
let navigationController = UINavigationController(rootViewController: reviewController)
@@ -681,21 +674,12 @@ class ProblemReportViewController: UIViewController, UITextFieldDelegate, Condit
private func sendProblemReport() {
let viewModel = Self.persistentViewModel
- let log = consolidatedLog.string
- let metadata = consolidatedLog.metadata.reduce(into: [:]) { output, entry in
- output[entry.key.rawValue] = entry.value
- }
-
- let request = REST.ProblemReportRequest(
- address: viewModel.email,
- message: viewModel.message,
- log: log,
- metadata: metadata
- )
-
willSendProblemReport()
- _ = apiProxy.sendProblemReport(request, retryStrategy: .default) { completion in
+ _ = interactor.sendReport(
+ email: viewModel.email,
+ message: viewModel.message
+ ) { completion in
self.didSendProblemReport(viewModel: viewModel, completion: completion)
}
}