diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 362fa14772..e710506b84 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -95,7 +95,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg navigationRootCoordinator = NavigationRootCoordinator() - Self.setupServiceLocator(appSettings: appSettings) + Self.setupServiceLocator(appSettings: appSettings, appHooks: appHooks) ServiceLocator.shared.analytics.startIfEnabled() @@ -340,14 +340,15 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg // MARK: - Private - private static func setupServiceLocator(appSettings: AppSettings) { + private static func setupServiceLocator(appSettings: AppSettings, appHooks: AppHooks) { ServiceLocator.shared.register(userIndicatorController: UserIndicatorController()) ServiceLocator.shared.register(appSettings: appSettings) ServiceLocator.shared.register(networkMonitor: NetworkMonitor()) ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: appSettings.bugReportServiceBaseURL, applicationId: appSettings.bugReportApplicationId, sdkGitSHA: sdkGitSha(), - maxUploadSize: appSettings.bugReportMaxUploadSize)) + maxUploadSize: appSettings.bugReportMaxUploadSize, + appHooks: appHooks)) let posthogAnalyticsClient = PostHogAnalyticsClient() posthogAnalyticsClient.updateSuperProperties(AnalyticsEvent.SuperProperties(appPlatform: .EXI, cryptoSDK: .Rust, cryptoSDKVersion: sdkGitSha())) ServiceLocator.shared.register(analytics: AnalyticsService(client: posthogAnalyticsClient, diff --git a/ElementX/Sources/Hooks/AppHooks.swift b/ElementX/Sources/Hooks/AppHooks.swift index f908dbe04e..3101ac9a7b 100644 --- a/ElementX/Sources/Hooks/AppHooks.swift +++ b/ElementX/Sources/Hooks/AppHooks.swift @@ -19,7 +19,7 @@ import Foundation // MARK: Registration class AppHooks: AppHooksProtocol { - private(set) var appSettingsHook: AppSettingsHookProtocol? + private var appSettingsHook: AppSettingsHookProtocol? func registerAppSettingsHook(_ hook: AppSettingsHookProtocol) { appSettingsHook = hook } @@ -28,6 +28,16 @@ class AppHooks: AppHooksProtocol { guard let appSettingsHook else { return appSettings } return appSettingsHook.run(appSettings: appSettings) } + + private var bugReportHook: BugReportHookProtocol? + func registerBugReportHook(_ hook: BugReportHookProtocol) { + bugReportHook = hook + } + + func runBugReportHook(_ bugReport: BugReport) -> BugReport { + guard let bugReportHook else { return bugReport } + return bugReportHook.run(bugReport: bugReport) + } } protocol AppHooksProtocol { @@ -43,3 +53,7 @@ extension AppHooksProtocol { protocol AppSettingsHookProtocol { func run(appSettings: AppSettings) -> AppSettings } + +protocol BugReportHookProtocol { + func run(bugReport: BugReport) -> BugReport +} diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index c8d0b0e7f0..8505f500ef 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -26,6 +26,9 @@ class BugReportService: NSObject, BugReportServiceProtocol { private let sdkGitSHA: String private let maxUploadSize: Int private let session: URLSession + + private let appHooks: AppHooks + private let progressSubject = PassthroughSubject() private var cancellables = Set() @@ -35,12 +38,14 @@ class BugReportService: NSObject, BugReportServiceProtocol { applicationId: String, sdkGitSHA: String, maxUploadSize: Int, - session: URLSession = .shared) { + session: URLSession = .shared, + appHooks: AppHooks) { self.baseURL = baseURL self.applicationId = applicationId self.sdkGitSHA = sdkGitSHA self.maxUploadSize = maxUploadSize self.session = session + self.appHooks = appHooks super.init() } @@ -53,6 +58,8 @@ class BugReportService: NSObject, BugReportServiceProtocol { // swiftlint:disable:next cyclomatic_complexity func submitBugReport(_ bugReport: BugReport, progressListener: CurrentValueSubject) async -> Result { + let bugReport = appHooks.runBugReportHook(bugReport) + var params = [ MultipartFormData(key: "text", type: .text(value: bugReport.text)), MultipartFormData(key: "can_contact", type: .text(value: "\(bugReport.canContact)")) diff --git a/ElementX/Sources/Services/BugReport/BugReportServiceProtocol.swift b/ElementX/Sources/Services/BugReport/BugReportServiceProtocol.swift index a56057a0ab..1a4fd8390f 100644 --- a/ElementX/Sources/Services/BugReport/BugReportServiceProtocol.swift +++ b/ElementX/Sources/Services/BugReport/BugReportServiceProtocol.swift @@ -26,7 +26,7 @@ struct BugReport: Equatable { let text: String let includeLogs: Bool let canContact: Bool - let githubLabels: [String] + var githubLabels: [String] let files: [URL] } diff --git a/Enterprise b/Enterprise index e03750f654..9fae88678e 160000 --- a/Enterprise +++ b/Enterprise @@ -1 +1 @@ -Subproject commit e03750f654cd3800c14b41827fb3f6ab57f7d5f0 +Subproject commit 9fae88678e844e9284c3b10591ac700970862d9c diff --git a/UnitTests/Sources/BugReportServiceTests.swift b/UnitTests/Sources/BugReportServiceTests.swift index 415fb80a05..c2d2730cb8 100644 --- a/UnitTests/Sources/BugReportServiceTests.swift +++ b/UnitTests/Sources/BugReportServiceTests.swift @@ -54,7 +54,8 @@ class BugReportServiceTests: XCTestCase { applicationId: "mock_app_id", sdkGitSHA: "1234", maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, - session: .mock) + session: .mock, + appHooks: AppHooks()) XCTAssertFalse(service.crashedLastRun) } @@ -63,7 +64,8 @@ class BugReportServiceTests: XCTestCase { applicationId: "mock_app_id", sdkGitSHA: "1234", maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, - session: .mock) + session: .mock, + appHooks: AppHooks()) let bugReport = BugReport(userID: "@mock:client.com", deviceID: nil,