diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 6e1c1e710..fb37f9d18 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -426,7 +426,6 @@ 484202C5D50983442D24D061 /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BD6ED18E2EB61E28C340AD /* AttributedString.swift */; }; 4870F7F72CEBEFDAD1C973A6 /* VoiceMessageMediaEventsTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3521DF92391551E02004D8 /* VoiceMessageMediaEventsTimelineView.swift */; }; 489BB6A733D3DA0FE7062650 /* IdentityConfirmationScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C71B9802433F1B4252291BB /* IdentityConfirmationScreenViewModelProtocol.swift */; }; - 48F2D00593F6D73434D3F893 /* AnalyticsService+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */; }; 491D62ACD19E6F134B1766AF /* RoomNotificationSettingsUserDefinedScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3203C6566DC17B7AECC1B7FD /* RoomNotificationSettingsUserDefinedScreen.swift */; }; 492274DA6691EE985C2FCCAA /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 21C83087604B154AA30E9A8F /* SnapshotTesting */; }; 4940B439681767BE9D78CFDB /* AppLockSetupBiometricsScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F5EE5DE3B55D59299DB5BC /* AppLockSetupBiometricsScreenViewModelTests.swift */; }; @@ -1005,6 +1004,7 @@ A5D551E5691749066E0E0C44 /* RoomDetailsScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 837B440C4705E4B899BCB899 /* RoomDetailsScreenViewModel.swift */; }; A5FD8284744E2FECFC842FC1 /* TraceLogPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7149BDDE47F8AD104E644E2 /* TraceLogPack.swift */; }; A64B52D9F73F9A6B95AF24FE /* UserDetailsEditScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CD503F5E0938FE53C7C6E7 /* UserDetailsEditScreenCoordinator.swift */; }; + A65999909C9D478DB71982B4 /* AnalyticsServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558AA5B376CE8C3982A9557F /* AnalyticsServiceProtocol.swift */; }; A6B83EB78F025D21B6EBA90C /* CompoundIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044E501B8331B339874D1B96 /* CompoundIcon.swift */; }; A6D4C5EEA85A6A0ABA1559D6 /* RoomDetailsEditScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D09C79746BDCD9173EB3A7 /* RoomDetailsEditScreenModels.swift */; }; A6DEC1ADEC8FEEC206A0FA37 /* AttributedStringBuilderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72F37B5DA798C9AE436F2C2C /* AttributedStringBuilderProtocol.swift */; }; @@ -1441,6 +1441,7 @@ F2E580C0FBFBEFFE9D69893B /* RoomPreviewProxyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 739077686814E4EA339B1C83 /* RoomPreviewProxyProtocol.swift */; }; F34D06F86C29E219E7132E87 /* AuthenticationStartScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F71A54CB96DAA1E72C6541D /* AuthenticationStartScreenViewModel.swift */; }; F35FAD1B1B289E221A07D719 /* ManageRoomMemberSheetViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB7B588A06911B455AC0B4C9 /* ManageRoomMemberSheetViewModelProtocol.swift */; }; + F371FB436B77F939DF9EF276 /* AnalyticsServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BEE119165C106FA83F253EF /* AnalyticsServiceMock.swift */; }; F37629BAA5E8F50AAF2A131D /* SoftLogoutScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB7BAD55A4E2B8E5828CD64C /* SoftLogoutScreenViewModel.swift */; }; F382E2FE3AC3719BC1F22D9C /* MapURLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB08D1F7C27A8C24EF81073C /* MapURLs.swift */; }; F38D32C1B0232AAFE6A0822C /* ExtensionLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A8571A8A071FB41778C016 /* ExtensionLogger.swift */; }; @@ -1778,6 +1779,7 @@ 1BA5A62DA4B543827FF82354 /* LAContextMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LAContextMock.swift; sourceTree = ""; }; 1BA8082E26C77A2C587B34B3 /* MockTimelineController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTimelineController.swift; sourceTree = ""; }; 1BC752C2A4606C4C2D1ADB41 /* 94 */ = {isa = PBXFileReference; path = 94; sourceTree = ""; }; + 1BEE119165C106FA83F253EF /* AnalyticsServiceMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsServiceMock.swift; sourceTree = ""; }; 1C21A715237F2B6D6E80998C /* SecureBackupControllerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureBackupControllerProtocol.swift; sourceTree = ""; }; 1C25B6EBEB414431187D73B7 /* TimelineReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineReplyView.swift; sourceTree = ""; }; 1C78111573987B1D79ED0868 /* LinkMetadataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkMetadataProvider.swift; sourceTree = ""; }; @@ -2104,6 +2106,7 @@ 54AD70D6E03D2031AE1B5A52 /* TimelineReactionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineReactionsView.swift; sourceTree = ""; }; 54C4E7B46099462F12000C91 /* DeveloperOptionsScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperOptionsScreenViewModelProtocol.swift; sourceTree = ""; }; 5557DDA438841AF5DC003D0B /* SpaceListScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceListScreenViewModelTests.swift; sourceTree = ""; }; + 558AA5B376CE8C3982A9557F /* AnalyticsServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsServiceProtocol.swift; sourceTree = ""; }; 55AEEF8142DF1B59DB40FB93 /* TimelineItemSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemSender.swift; sourceTree = ""; }; 5644919DB2022397D9D5825A /* MockSoftLogoutScreenState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSoftLogoutScreenState.swift; sourceTree = ""; }; 565F1B2B300597C616B37888 /* FullscreenDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullscreenDialog.swift; sourceTree = ""; }; @@ -2526,7 +2529,6 @@ A232D9156D225BD9FD1D0C43 /* PhotoLibraryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoLibraryPicker.swift; sourceTree = ""; }; A243A6E6207297123E60DE48 /* TimelineItemMacContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemMacContextMenu.swift; sourceTree = ""; }; A2723A4AF3AB9F5E18D26E49 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/InfoPlist.strings; sourceTree = ""; }; - A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnalyticsService+Mock.swift"; sourceTree = ""; }; A3A4F56855188DAD23E59031 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = ""; }; A3B4B58B79A6FA250B24A1EC /* HomeScreenContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenContent.swift; sourceTree = ""; }; A3E3DE6616DCA81AD5F4791B /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -3766,7 +3768,7 @@ isa = PBXGroup; children = ( 69CB8242D69B7E4D0B32E18D /* AggregatedReactionMock.swift */, - A384A5A9F8472A0DA76FDB27 /* AnalyticsService+Mock.swift */, + 1BEE119165C106FA83F253EF /* AnalyticsServiceMock.swift */, 3BAC027034248429A438886B /* AppMediatorMock.swift */, 0554FEA301486A8CFA475D5A /* AuthenticationClientBuilderFactoryMock.swift */, 9FD7E851E2BA8C5A8D284B2A /* BannedRoomProxyMock.swift */, @@ -4376,6 +4378,7 @@ children = ( E3B97591B2D3D4D67553506D /* AnalyticsClientProtocol.swift */, 5445FCE0CE15E634FDC1A2E2 /* AnalyticsService.swift */, + 558AA5B376CE8C3982A9557F /* AnalyticsServiceProtocol.swift */, A6B891A6DA826E2461DBB40F /* PHGPostHogConfiguration.swift */, 5CEEAE1BFAACD6C96B6DB731 /* PHGPostHogProtocol.swift */, 1715E3D7F53C0748AA50C91C /* PostHogAnalyticsClient.swift */, @@ -8079,8 +8082,9 @@ 6DC8E43BA04AC2AC4EB2EB97 /* AnalyticsPromptScreenModels.swift in Sources */, DB65401349C143DFF883E2B0 /* AnalyticsPromptScreenViewModel.swift in Sources */, 05BAB510CBC2ED35C154ADD0 /* AnalyticsPromptScreenViewModelProtocol.swift in Sources */, - 48F2D00593F6D73434D3F893 /* AnalyticsService+Mock.swift in Sources */, 3C73442084BF8A6939F0F80B /* AnalyticsService.swift in Sources */, + F371FB436B77F939DF9EF276 /* AnalyticsServiceMock.swift in Sources */, + A65999909C9D478DB71982B4 /* AnalyticsServiceProtocol.swift in Sources */, 020F7E70167FB2833266F2F0 /* AnalyticsSettingsScreen.swift in Sources */, 95690DDD9D547D3D842ACBE3 /* AnalyticsSettingsScreenCoordinator.swift in Sources */, 7C6376192F578E0BA801BFEC /* AnalyticsSettingsScreenModels.swift in Sources */, diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 89be226cb..dfab253da 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -22,7 +22,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private let targetConfiguration: Target.ConfigurationResult private let appMediator: AppMediator private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private let appDelegate: AppDelegate @@ -946,7 +946,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } } - private static func setupSentry(bugReportService: BugReportServiceProtocol, appSettings: AppSettings, analytics: AnalyticsService) { + private static func setupSentry(bugReportService: BugReportServiceProtocol, appSettings: AppSettings, analytics: AnalyticsServiceProtocol) { guard let bugReportSentryURL = appSettings.bugReportSentryURL else { return } let options: Options = .init() diff --git a/ElementX/Sources/Application/FlowCoordinatorProtocol.swift b/ElementX/Sources/Application/FlowCoordinatorProtocol.swift index dcbecff45..1f656a50d 100644 --- a/ElementX/Sources/Application/FlowCoordinatorProtocol.swift +++ b/ElementX/Sources/Application/FlowCoordinatorProtocol.swift @@ -36,7 +36,7 @@ struct CommonFlowParameters { let appMediator: AppMediatorProtocol let appSettings: AppSettings let appHooks: AppHooks - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol let notificationManager: NotificationManagerProtocol let stateMachineFactory: StateMachineFactoryProtocol diff --git a/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift index 3135ed8c6..8818d39a7 100644 --- a/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/AuthenticationFlowCoordinator.swift @@ -23,7 +23,7 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol { private let appMediator: AppMediatorProtocol private let appSettings: AppSettings private let appHooks: AppHooks - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol enum State: StateType { @@ -109,7 +109,7 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol { appMediator: AppMediatorProtocol, appSettings: AppSettings, appHooks: AppHooks, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.authenticationService = authenticationService self.bugReportService = bugReportService diff --git a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift index 08a27ec21..69b060965 100644 --- a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift @@ -19,7 +19,7 @@ enum OnboardingFlowCoordinatorAction { class OnboardingFlowCoordinator: FlowCoordinatorProtocol { private let userSession: UserSessionProtocol private let appLockService: AppLockServiceProtocol - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let appMediator: AppMediatorProtocol private let appSettings: AppSettings private let appHooks: AppHooks diff --git a/ElementX/Sources/FlowCoordinators/RoomRolesAndPermissionsFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomRolesAndPermissionsFlowCoordinator.swift index aba137a9c..a80e1f6d1 100644 --- a/ElementX/Sources/FlowCoordinators/RoomRolesAndPermissionsFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomRolesAndPermissionsFlowCoordinator.swift @@ -20,7 +20,7 @@ struct RoomRolesAndPermissionsFlowCoordinatorParameters { let mediaProvider: MediaProviderProtocol let navigationStackCoordinator: NavigationStackCoordinator let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } class RoomRolesAndPermissionsFlowCoordinator: FlowCoordinatorProtocol { @@ -28,7 +28,7 @@ class RoomRolesAndPermissionsFlowCoordinator: FlowCoordinatorProtocol { private let navigationStackCoordinator: NavigationStackCoordinator private let mediaProvider: MediaProviderProtocol private let userIndicatorController: UserIndicatorControllerProtocol - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol enum State: StateType { /// The state machine hasn't started. diff --git a/ElementX/Sources/Mocks/AnalyticsService+Mock.swift b/ElementX/Sources/Mocks/AnalyticsService+Mock.swift deleted file mode 100644 index 5f31dcd7e..000000000 --- a/ElementX/Sources/Mocks/AnalyticsService+Mock.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2026 Element Creations Ltd. -// -// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. -// Please see LICENSE files in the repository root for full details. -// - -extension AnalyticsService { - static func mock(_ clientOverride: AnalyticsClientProtocol? = nil, settings: AppSettings? = nil) -> AnalyticsService { - let client: AnalyticsClientProtocol - if let clientOverride { - client = clientOverride - } else { - let mockClient = AnalyticsClientMock() - mockClient.isRunning = false - client = mockClient - } - - return .init(client: client, appSettings: settings ?? AppSettings()) - } -} diff --git a/ElementX/Sources/Mocks/AnalyticsServiceMock.swift b/ElementX/Sources/Mocks/AnalyticsServiceMock.swift new file mode 100644 index 000000000..d60c77d25 --- /dev/null +++ b/ElementX/Sources/Mocks/AnalyticsServiceMock.swift @@ -0,0 +1,16 @@ +// +// Copyright 2026 Element Creations Ltd. +// +// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. +// Please see LICENSE files in the repository root for full details. +// + +extension AnalyticsServiceMock { + static func `default`() -> AnalyticsServiceMock { + let mock = AnalyticsServiceMock() + mock.isEnabled = false + mock.shouldShowAnalyticsPrompt = false + mock.signpost = Signposter() + return mock + } +} diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index c211cca0a..65e35f1c0 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -256,6 +256,761 @@ class AnalyticsClientMock: AnalyticsClientProtocol, @unchecked Sendable { updateUserPropertiesClosure?(event) } } +class AnalyticsServiceMock: AnalyticsServiceProtocol, @unchecked Sendable { + var signpost: Signposter { + get { return underlyingSignpost } + set(value) { underlyingSignpost = value } + } + var underlyingSignpost: Signposter! + var shouldShowAnalyticsPrompt: Bool { + get { return underlyingShouldShowAnalyticsPrompt } + set(value) { underlyingShouldShowAnalyticsPrompt = value } + } + var underlyingShouldShowAnalyticsPrompt: Bool! + var isEnabled: Bool { + get { return underlyingIsEnabled } + set(value) { underlyingIsEnabled = value } + } + var underlyingIsEnabled: Bool! + + //MARK: - optIn + + var optInUnderlyingCallsCount = 0 + var optInCallsCount: Int { + get { + if Thread.isMainThread { + return optInUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = optInUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + optInUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + optInUnderlyingCallsCount = newValue + } + } + } + } + var optInCalled: Bool { + return optInCallsCount > 0 + } + var optInClosure: (() -> Void)? + + func optIn() { + optInCallsCount += 1 + optInClosure?() + } + //MARK: - optOut + + var optOutUnderlyingCallsCount = 0 + var optOutCallsCount: Int { + get { + if Thread.isMainThread { + return optOutUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = optOutUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + optOutUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + optOutUnderlyingCallsCount = newValue + } + } + } + } + var optOutCalled: Bool { + return optOutCallsCount > 0 + } + var optOutClosure: (() -> Void)? + + func optOut() { + optOutCallsCount += 1 + optOutClosure?() + } + //MARK: - startIfEnabled + + var startIfEnabledUnderlyingCallsCount = 0 + var startIfEnabledCallsCount: Int { + get { + if Thread.isMainThread { + return startIfEnabledUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = startIfEnabledUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + startIfEnabledUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + startIfEnabledUnderlyingCallsCount = newValue + } + } + } + } + var startIfEnabledCalled: Bool { + return startIfEnabledCallsCount > 0 + } + var startIfEnabledClosure: (() -> Void)? + + func startIfEnabled() { + startIfEnabledCallsCount += 1 + startIfEnabledClosure?() + } + //MARK: - reset + + var resetUnderlyingCallsCount = 0 + var resetCallsCount: Int { + get { + if Thread.isMainThread { + return resetUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = resetUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + resetUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + resetUnderlyingCallsCount = newValue + } + } + } + } + var resetCalled: Bool { + return resetCallsCount > 0 + } + var resetClosure: (() -> Void)? + + func reset() { + resetCallsCount += 1 + resetClosure?() + } + //MARK: - resetConsentState + + var resetConsentStateUnderlyingCallsCount = 0 + var resetConsentStateCallsCount: Int { + get { + if Thread.isMainThread { + return resetConsentStateUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = resetConsentStateUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + resetConsentStateUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + resetConsentStateUnderlyingCallsCount = newValue + } + } + } + } + var resetConsentStateCalled: Bool { + return resetConsentStateCallsCount > 0 + } + var resetConsentStateClosure: (() -> Void)? + + func resetConsentState() { + resetConsentStateCallsCount += 1 + resetConsentStateClosure?() + } + //MARK: - track + + var trackScreenDurationUnderlyingCallsCount = 0 + var trackScreenDurationCallsCount: Int { + get { + if Thread.isMainThread { + return trackScreenDurationUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackScreenDurationUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackScreenDurationUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackScreenDurationUnderlyingCallsCount = newValue + } + } + } + } + var trackScreenDurationCalled: Bool { + return trackScreenDurationCallsCount > 0 + } + var trackScreenDurationReceivedArguments: (screen: AnalyticsEvent.MobileScreen.ScreenName, milliseconds: Int?)? + var trackScreenDurationReceivedInvocations: [(screen: AnalyticsEvent.MobileScreen.ScreenName, milliseconds: Int?)] = [] + var trackScreenDurationClosure: ((AnalyticsEvent.MobileScreen.ScreenName, Int?) -> Void)? + + func track(screen: AnalyticsEvent.MobileScreen.ScreenName, duration milliseconds: Int?) { + trackScreenDurationCallsCount += 1 + trackScreenDurationReceivedArguments = (screen: screen, milliseconds: milliseconds) + DispatchQueue.main.async { + self.trackScreenDurationReceivedInvocations.append((screen: screen, milliseconds: milliseconds)) + } + trackScreenDurationClosure?(screen, milliseconds) + } + //MARK: - trackInteraction + + var trackInteractionIndexNameUnderlyingCallsCount = 0 + var trackInteractionIndexNameCallsCount: Int { + get { + if Thread.isMainThread { + return trackInteractionIndexNameUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackInteractionIndexNameUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackInteractionIndexNameUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackInteractionIndexNameUnderlyingCallsCount = newValue + } + } + } + } + var trackInteractionIndexNameCalled: Bool { + return trackInteractionIndexNameCallsCount > 0 + } + var trackInteractionIndexNameReceivedArguments: (index: Int?, name: AnalyticsEvent.Interaction.Name)? + var trackInteractionIndexNameReceivedInvocations: [(index: Int?, name: AnalyticsEvent.Interaction.Name)] = [] + var trackInteractionIndexNameClosure: ((Int?, AnalyticsEvent.Interaction.Name) -> Void)? + + func trackInteraction(index: Int?, name: AnalyticsEvent.Interaction.Name) { + trackInteractionIndexNameCallsCount += 1 + trackInteractionIndexNameReceivedArguments = (index: index, name: name) + DispatchQueue.main.async { + self.trackInteractionIndexNameReceivedInvocations.append((index: index, name: name)) + } + trackInteractionIndexNameClosure?(index, name) + } + //MARK: - trackError + + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserUnderlyingCallsCount = 0 + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserCallsCount: Int { + get { + if Thread.isMainThread { + return trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserUnderlyingCallsCount = newValue + } + } + } + } + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserCalled: Bool { + return trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserCallsCount > 0 + } + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserReceivedArguments: (context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int?, eventLocalAgeMillis: Int?, isFederated: Bool?, isMatrixDotOrg: Bool?, userTrustsOwnIdentity: Bool?, wasVisibleToUser: Bool?)? + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserReceivedInvocations: [(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int?, eventLocalAgeMillis: Int?, isFederated: Bool?, isMatrixDotOrg: Bool?, userTrustsOwnIdentity: Bool?, wasVisibleToUser: Bool?)] = [] + var trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserClosure: ((String?, AnalyticsEvent.Error.Domain, AnalyticsEvent.Error.Name, Int?, Int?, Bool?, Bool?, Bool?, Bool?) -> Void)? + + func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int?, eventLocalAgeMillis: Int?, isFederated: Bool?, isMatrixDotOrg: Bool?, userTrustsOwnIdentity: Bool?, wasVisibleToUser: Bool?) { + trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserCallsCount += 1 + trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserReceivedArguments = (context: context, domain: domain, name: name, timeToDecryptMillis: timeToDecryptMillis, eventLocalAgeMillis: eventLocalAgeMillis, isFederated: isFederated, isMatrixDotOrg: isMatrixDotOrg, userTrustsOwnIdentity: userTrustsOwnIdentity, wasVisibleToUser: wasVisibleToUser) + DispatchQueue.main.async { + self.trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserReceivedInvocations.append((context: context, domain: domain, name: name, timeToDecryptMillis: timeToDecryptMillis, eventLocalAgeMillis: eventLocalAgeMillis, isFederated: isFederated, isMatrixDotOrg: isMatrixDotOrg, userTrustsOwnIdentity: userTrustsOwnIdentity, wasVisibleToUser: wasVisibleToUser)) + } + trackErrorContextDomainNameTimeToDecryptMillisEventLocalAgeMillisIsFederatedIsMatrixDotOrgUserTrustsOwnIdentityWasVisibleToUserClosure?(context, domain, name, timeToDecryptMillis, eventLocalAgeMillis, isFederated, isMatrixDotOrg, userTrustsOwnIdentity, wasVisibleToUser) + } + //MARK: - trackCreatedRoom + + var trackCreatedRoomIsDMUnderlyingCallsCount = 0 + var trackCreatedRoomIsDMCallsCount: Int { + get { + if Thread.isMainThread { + return trackCreatedRoomIsDMUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackCreatedRoomIsDMUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackCreatedRoomIsDMUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackCreatedRoomIsDMUnderlyingCallsCount = newValue + } + } + } + } + var trackCreatedRoomIsDMCalled: Bool { + return trackCreatedRoomIsDMCallsCount > 0 + } + var trackCreatedRoomIsDMReceivedIsDM: Bool? + var trackCreatedRoomIsDMReceivedInvocations: [Bool] = [] + var trackCreatedRoomIsDMClosure: ((Bool) -> Void)? + + func trackCreatedRoom(isDM: Bool) { + trackCreatedRoomIsDMCallsCount += 1 + trackCreatedRoomIsDMReceivedIsDM = isDM + DispatchQueue.main.async { + self.trackCreatedRoomIsDMReceivedInvocations.append(isDM) + } + trackCreatedRoomIsDMClosure?(isDM) + } + //MARK: - trackComposer + + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadUnderlyingCallsCount = 0 + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadCallsCount: Int { + get { + if Thread.isMainThread { + return trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadUnderlyingCallsCount = newValue + } + } + } + } + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadCalled: Bool { + return trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadCallsCount > 0 + } + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadReceivedArguments: (inThread: Bool, isEditing: Bool, isReply: Bool, messageType: AnalyticsEvent.Composer.MessageType, startsThread: Bool?)? + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadReceivedInvocations: [(inThread: Bool, isEditing: Bool, isReply: Bool, messageType: AnalyticsEvent.Composer.MessageType, startsThread: Bool?)] = [] + var trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadClosure: ((Bool, Bool, Bool, AnalyticsEvent.Composer.MessageType, Bool?) -> Void)? + + func trackComposer(inThread: Bool, isEditing: Bool, isReply: Bool, messageType: AnalyticsEvent.Composer.MessageType, startsThread: Bool?) { + trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadCallsCount += 1 + trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadReceivedArguments = (inThread: inThread, isEditing: isEditing, isReply: isReply, messageType: messageType, startsThread: startsThread) + DispatchQueue.main.async { + self.trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadReceivedInvocations.append((inThread: inThread, isEditing: isEditing, isReply: isReply, messageType: messageType, startsThread: startsThread)) + } + trackComposerInThreadIsEditingIsReplyMessageTypeStartsThreadClosure?(inThread, isEditing, isReply, messageType, startsThread) + } + //MARK: - trackViewRoom + + var trackViewRoomIsDMIsSpaceUnderlyingCallsCount = 0 + var trackViewRoomIsDMIsSpaceCallsCount: Int { + get { + if Thread.isMainThread { + return trackViewRoomIsDMIsSpaceUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackViewRoomIsDMIsSpaceUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackViewRoomIsDMIsSpaceUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackViewRoomIsDMIsSpaceUnderlyingCallsCount = newValue + } + } + } + } + var trackViewRoomIsDMIsSpaceCalled: Bool { + return trackViewRoomIsDMIsSpaceCallsCount > 0 + } + var trackViewRoomIsDMIsSpaceReceivedArguments: (isDM: Bool, isSpace: Bool)? + var trackViewRoomIsDMIsSpaceReceivedInvocations: [(isDM: Bool, isSpace: Bool)] = [] + var trackViewRoomIsDMIsSpaceClosure: ((Bool, Bool) -> Void)? + + func trackViewRoom(isDM: Bool, isSpace: Bool) { + trackViewRoomIsDMIsSpaceCallsCount += 1 + trackViewRoomIsDMIsSpaceReceivedArguments = (isDM: isDM, isSpace: isSpace) + DispatchQueue.main.async { + self.trackViewRoomIsDMIsSpaceReceivedInvocations.append((isDM: isDM, isSpace: isSpace)) + } + trackViewRoomIsDMIsSpaceClosure?(isDM, isSpace) + } + //MARK: - trackJoinedRoom + + var trackJoinedRoomIsDMIsSpaceActiveMemberCountUnderlyingCallsCount = 0 + var trackJoinedRoomIsDMIsSpaceActiveMemberCountCallsCount: Int { + get { + if Thread.isMainThread { + return trackJoinedRoomIsDMIsSpaceActiveMemberCountUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackJoinedRoomIsDMIsSpaceActiveMemberCountUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackJoinedRoomIsDMIsSpaceActiveMemberCountUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackJoinedRoomIsDMIsSpaceActiveMemberCountUnderlyingCallsCount = newValue + } + } + } + } + var trackJoinedRoomIsDMIsSpaceActiveMemberCountCalled: Bool { + return trackJoinedRoomIsDMIsSpaceActiveMemberCountCallsCount > 0 + } + var trackJoinedRoomIsDMIsSpaceActiveMemberCountReceivedArguments: (isDM: Bool, isSpace: Bool, activeMemberCount: UInt)? + var trackJoinedRoomIsDMIsSpaceActiveMemberCountReceivedInvocations: [(isDM: Bool, isSpace: Bool, activeMemberCount: UInt)] = [] + var trackJoinedRoomIsDMIsSpaceActiveMemberCountClosure: ((Bool, Bool, UInt) -> Void)? + + func trackJoinedRoom(isDM: Bool, isSpace: Bool, activeMemberCount: UInt) { + trackJoinedRoomIsDMIsSpaceActiveMemberCountCallsCount += 1 + trackJoinedRoomIsDMIsSpaceActiveMemberCountReceivedArguments = (isDM: isDM, isSpace: isSpace, activeMemberCount: activeMemberCount) + DispatchQueue.main.async { + self.trackJoinedRoomIsDMIsSpaceActiveMemberCountReceivedInvocations.append((isDM: isDM, isSpace: isSpace, activeMemberCount: activeMemberCount)) + } + trackJoinedRoomIsDMIsSpaceActiveMemberCountClosure?(isDM, isSpace, activeMemberCount) + } + //MARK: - trackPollCreated + + var trackPollCreatedIsUndisclosedNumberOfAnswersUnderlyingCallsCount = 0 + var trackPollCreatedIsUndisclosedNumberOfAnswersCallsCount: Int { + get { + if Thread.isMainThread { + return trackPollCreatedIsUndisclosedNumberOfAnswersUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackPollCreatedIsUndisclosedNumberOfAnswersUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackPollCreatedIsUndisclosedNumberOfAnswersUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackPollCreatedIsUndisclosedNumberOfAnswersUnderlyingCallsCount = newValue + } + } + } + } + var trackPollCreatedIsUndisclosedNumberOfAnswersCalled: Bool { + return trackPollCreatedIsUndisclosedNumberOfAnswersCallsCount > 0 + } + var trackPollCreatedIsUndisclosedNumberOfAnswersReceivedArguments: (isUndisclosed: Bool, numberOfAnswers: Int)? + var trackPollCreatedIsUndisclosedNumberOfAnswersReceivedInvocations: [(isUndisclosed: Bool, numberOfAnswers: Int)] = [] + var trackPollCreatedIsUndisclosedNumberOfAnswersClosure: ((Bool, Int) -> Void)? + + func trackPollCreated(isUndisclosed: Bool, numberOfAnswers: Int) { + trackPollCreatedIsUndisclosedNumberOfAnswersCallsCount += 1 + trackPollCreatedIsUndisclosedNumberOfAnswersReceivedArguments = (isUndisclosed: isUndisclosed, numberOfAnswers: numberOfAnswers) + DispatchQueue.main.async { + self.trackPollCreatedIsUndisclosedNumberOfAnswersReceivedInvocations.append((isUndisclosed: isUndisclosed, numberOfAnswers: numberOfAnswers)) + } + trackPollCreatedIsUndisclosedNumberOfAnswersClosure?(isUndisclosed, numberOfAnswers) + } + //MARK: - trackPollVote + + var trackPollVoteUnderlyingCallsCount = 0 + var trackPollVoteCallsCount: Int { + get { + if Thread.isMainThread { + return trackPollVoteUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackPollVoteUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackPollVoteUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackPollVoteUnderlyingCallsCount = newValue + } + } + } + } + var trackPollVoteCalled: Bool { + return trackPollVoteCallsCount > 0 + } + var trackPollVoteClosure: (() -> Void)? + + func trackPollVote() { + trackPollVoteCallsCount += 1 + trackPollVoteClosure?() + } + //MARK: - trackPollEnd + + var trackPollEndUnderlyingCallsCount = 0 + var trackPollEndCallsCount: Int { + get { + if Thread.isMainThread { + return trackPollEndUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackPollEndUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackPollEndUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackPollEndUnderlyingCallsCount = newValue + } + } + } + } + var trackPollEndCalled: Bool { + return trackPollEndCallsCount > 0 + } + var trackPollEndClosure: (() -> Void)? + + func trackPollEnd() { + trackPollEndCallsCount += 1 + trackPollEndClosure?() + } + //MARK: - trackRoomModeration + + var trackRoomModerationActionRoleUnderlyingCallsCount = 0 + var trackRoomModerationActionRoleCallsCount: Int { + get { + if Thread.isMainThread { + return trackRoomModerationActionRoleUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackRoomModerationActionRoleUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackRoomModerationActionRoleUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackRoomModerationActionRoleUnderlyingCallsCount = newValue + } + } + } + } + var trackRoomModerationActionRoleCalled: Bool { + return trackRoomModerationActionRoleCallsCount > 0 + } + var trackRoomModerationActionRoleReceivedArguments: (action: AnalyticsEvent.RoomModeration.Action, role: RoomRole?)? + var trackRoomModerationActionRoleReceivedInvocations: [(action: AnalyticsEvent.RoomModeration.Action, role: RoomRole?)] = [] + var trackRoomModerationActionRoleClosure: ((AnalyticsEvent.RoomModeration.Action, RoomRole?) -> Void)? + + func trackRoomModeration(action: AnalyticsEvent.RoomModeration.Action, role: RoomRole?) { + trackRoomModerationActionRoleCallsCount += 1 + trackRoomModerationActionRoleReceivedArguments = (action: action, role: role) + DispatchQueue.main.async { + self.trackRoomModerationActionRoleReceivedInvocations.append((action: action, role: role)) + } + trackRoomModerationActionRoleClosure?(action, role) + } + //MARK: - trackSessionSecurityState + + var trackSessionSecurityStateUnderlyingCallsCount = 0 + var trackSessionSecurityStateCallsCount: Int { + get { + if Thread.isMainThread { + return trackSessionSecurityStateUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackSessionSecurityStateUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackSessionSecurityStateUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackSessionSecurityStateUnderlyingCallsCount = newValue + } + } + } + } + var trackSessionSecurityStateCalled: Bool { + return trackSessionSecurityStateCallsCount > 0 + } + var trackSessionSecurityStateReceivedState: SessionSecurityState? + var trackSessionSecurityStateReceivedInvocations: [SessionSecurityState] = [] + var trackSessionSecurityStateClosure: ((SessionSecurityState) -> Void)? + + func trackSessionSecurityState(_ state: SessionSecurityState) { + trackSessionSecurityStateCallsCount += 1 + trackSessionSecurityStateReceivedState = state + DispatchQueue.main.async { + self.trackSessionSecurityStateReceivedInvocations.append(state) + } + trackSessionSecurityStateClosure?(state) + } + //MARK: - updateUserProperties + + var updateUserPropertiesUnderlyingCallsCount = 0 + var updateUserPropertiesCallsCount: Int { + get { + if Thread.isMainThread { + return updateUserPropertiesUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = updateUserPropertiesUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + updateUserPropertiesUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + updateUserPropertiesUnderlyingCallsCount = newValue + } + } + } + } + var updateUserPropertiesCalled: Bool { + return updateUserPropertiesCallsCount > 0 + } + var updateUserPropertiesReceivedUserProperties: AnalyticsEvent.UserProperties? + var updateUserPropertiesReceivedInvocations: [AnalyticsEvent.UserProperties] = [] + var updateUserPropertiesClosure: ((AnalyticsEvent.UserProperties) -> Void)? + + func updateUserProperties(_ userProperties: AnalyticsEvent.UserProperties) { + updateUserPropertiesCallsCount += 1 + updateUserPropertiesReceivedUserProperties = userProperties + DispatchQueue.main.async { + self.updateUserPropertiesReceivedInvocations.append(userProperties) + } + updateUserPropertiesClosure?(userProperties) + } + //MARK: - trackPinUnpinEvent + + var trackPinUnpinEventUnderlyingCallsCount = 0 + var trackPinUnpinEventCallsCount: Int { + get { + if Thread.isMainThread { + return trackPinUnpinEventUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = trackPinUnpinEventUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + trackPinUnpinEventUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + trackPinUnpinEventUnderlyingCallsCount = newValue + } + } + } + } + var trackPinUnpinEventCalled: Bool { + return trackPinUnpinEventCallsCount > 0 + } + var trackPinUnpinEventReceivedEvent: AnalyticsEvent.PinUnpinAction? + var trackPinUnpinEventReceivedInvocations: [AnalyticsEvent.PinUnpinAction] = [] + var trackPinUnpinEventClosure: ((AnalyticsEvent.PinUnpinAction) -> Void)? + + func trackPinUnpinEvent(_ event: AnalyticsEvent.PinUnpinAction) { + trackPinUnpinEventCallsCount += 1 + trackPinUnpinEventReceivedEvent = event + DispatchQueue.main.async { + self.trackPinUnpinEventReceivedInvocations.append(event) + } + trackPinUnpinEventClosure?(event) + } +} class AppLockServiceMock: AppLockServiceProtocol, @unchecked Sendable { var isMandatory: Bool { get { return underlyingIsMandatory } diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift index 49380f7c4..5979887df 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift @@ -16,7 +16,7 @@ struct LoginScreenCoordinatorParameters { let loginHint: String? let userIndicatorController: UserIndicatorControllerProtocol let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum LoginScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift index 9019e275f..ab608a2a2 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift @@ -15,7 +15,7 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc private let authenticationService: AuthenticationServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private let appSettings: AppSettings - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private var actionsSubject: PassthroughSubject = .init() var actions: AnyPublisher { @@ -26,7 +26,7 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc loginHint: String?, userIndicatorController: UserIndicatorControllerProtocol, appSettings: AppSettings, - analytics: AnalyticsService) { + analytics: AnalyticsServiceProtocol) { self.authenticationService = authenticationService self.userIndicatorController = userIndicatorController self.appSettings = appSettings diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginScreen.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginScreen.swift index 43146dbb4..a0feadced 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginScreen.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/View/LoginScreen.swift @@ -158,14 +158,11 @@ struct LoginScreen_Previews: PreviewProvider, TestablePreview { Task { await authenticationService.configure(for: homeserverAddress, flow: .login) } - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - let viewModel = LoginScreenViewModel(authenticationService: authenticationService, loginHint: nil, userIndicatorController: UserIndicatorControllerMock(), - appSettings: appSettings, - analytics: analytics) + appSettings: AppSettings(), + analytics: AnalyticsServiceMock.default()) if withCredentials { viewModel.context.username = "alice" diff --git a/ElementX/Sources/Screens/CallScreen/CallScreenCoordinator.swift b/ElementX/Sources/Screens/CallScreen/CallScreenCoordinator.swift index cb67f7316..396da8df4 100644 --- a/ElementX/Sources/Screens/CallScreen/CallScreenCoordinator.swift +++ b/ElementX/Sources/Screens/CallScreen/CallScreenCoordinator.swift @@ -16,7 +16,7 @@ struct CallScreenCoordinatorParameters { let allowPictureInPicture: Bool let appSettings: AppSettings let appHooks: AppHooks - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum CallScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift index ba38a380a..28b15f1b2 100644 --- a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift +++ b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift @@ -18,7 +18,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol private let configuration: ElementCallConfiguration private let isPictureInPictureAllowed: Bool private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let widgetDriver: ElementCallWidgetDriverProtocol @@ -41,7 +41,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol allowPictureInPicture: Bool, appHooks: AppHooks, appSettings: AppSettings, - analyticsService: AnalyticsService) { + analyticsService: AnalyticsServiceProtocol) { self.elementCallService = elementCallService self.configuration = configuration self.appSettings = appSettings diff --git a/ElementX/Sources/Screens/CallScreen/View/CallScreen.swift b/ElementX/Sources/Screens/CallScreen/View/CallScreen.swift index 6e2867d4a..9f322fc96 100644 --- a/ElementX/Sources/Screens/CallScreen/View/CallScreen.swift +++ b/ElementX/Sources/Screens/CallScreen/View/CallScreen.swift @@ -364,9 +364,6 @@ struct CallScreen_Previews: PreviewProvider { roomProxy.elementCallWidgetDriverDeviceIDReturnValue = widgetDriver - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return CallScreenViewModel(elementCallService: ElementCallServiceMock(.init()), configuration: .init(roomProxy: roomProxy, clientProxy: clientProxy, @@ -377,8 +374,8 @@ struct CallScreen_Previews: PreviewProvider { colorScheme: .light), allowPictureInPicture: false, appHooks: AppHooks(), - appSettings: appSettings, - analyticsService: analytics) + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default()) }() static var previews: some View { diff --git a/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenCoordinator.swift b/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenCoordinator.swift index a1bcd3996..f43c6f247 100644 --- a/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenCoordinator.swift +++ b/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenCoordinator.swift @@ -14,7 +14,7 @@ struct PollFormScreenCoordinatorParameters { /// The max number of allowed options, if no value provided the default value of the view model will be used. var maxNumberOfOptions: Int? let timelineController: TimelineControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol } diff --git a/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenViewModel.swift b/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenViewModel.swift index 97b415d09..51e582b98 100644 --- a/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenViewModel.swift +++ b/ElementX/Sources/Screens/CreatePollScreen/PollFormScreenViewModel.swift @@ -13,7 +13,7 @@ typealias PollFormScreenViewModelType = StateStoreViewModelV2 = .init() @@ -24,7 +24,7 @@ class PollFormScreenViewModel: PollFormScreenViewModelType, PollFormScreenViewMo init(mode: PollFormMode, maxNumberOfOptions: Int? = nil, timelineController: TimelineControllerProtocol, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.timelineController = timelineController self.analytics = analytics diff --git a/ElementX/Sources/Screens/CreatePollScreen/View/PollFormScreen.swift b/ElementX/Sources/Screens/CreatePollScreen/View/PollFormScreen.swift index c5aab3e37..f8724a1fc 100644 --- a/ElementX/Sources/Screens/CreatePollScreen/View/PollFormScreen.swift +++ b/ElementX/Sources/Screens/CreatePollScreen/View/PollFormScreen.swift @@ -227,7 +227,7 @@ struct PollFormScreen_Previews: PreviewProvider, TestablePreview { static func makeViewModel(mode: PollFormMode) -> PollFormScreenViewModel { PollFormScreenViewModel(mode: mode, timelineController: MockTimelineController(), - analytics: .mock(), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) } } diff --git a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift index 9ad7d2fcb..3248aee39 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift @@ -16,7 +16,7 @@ struct CreateRoomScreenCoordinatorParameters { let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum CreateRoomScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift index 497a0db53..c944927a9 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift @@ -15,7 +15,7 @@ typealias CreateRoomScreenViewModelType = StateStoreViewModel let appSettings: AppSettings - let analyticsService: AnalyticsService + let analyticsService: AnalyticsServiceProtocol let notificationManager: NotificationManagerProtocol let userIndicatorController: UserIndicatorControllerProtocol } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 1322fbe9b..6a63e4437 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -16,7 +16,7 @@ typealias HomeScreenViewModelType = StateStoreViewModel - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let appSettings: AppSettings private let notificationManager: NotificationManagerProtocol private let userIndicatorController: UserIndicatorControllerProtocol @@ -32,7 +32,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol init(userSession: UserSessionProtocol, selectedRoomPublisher: CurrentValuePublisher, appSettings: AppSettings, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, notificationManager: NotificationManagerProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.userSession = userSession diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index 61c973208..f98c0b4cb 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -222,13 +222,10 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview { let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) } diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift index a559ad6cc..9d2f084fd 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift @@ -143,13 +143,10 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview { static let viewModel = { let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@user:example.com", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))))))) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) }() diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift index c90288e90..2e8b85444 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift @@ -200,13 +200,10 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview { let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) } diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift index 024733917..dc982206b 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift @@ -132,13 +132,10 @@ struct HomeScreenKnockedCell_Previews: PreviewProvider, TestablePreview { let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) } diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift index bf81d5f2d..6206c2e45 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift @@ -121,13 +121,10 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) } diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift index df75027f4..2e11c403a 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift @@ -253,13 +253,10 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview { static func makeViewModel(roomSummaryProvider: RoomSummaryProviderProtocol) -> HomeScreenViewModel { let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: roomSummaryProvider)))) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), notificationManager: NotificationManagerMock(), userIndicatorController: UserIndicatorControllerMock.default) } diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift index 1a5356d93..8beb985fb 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift @@ -16,7 +16,7 @@ struct LocationSharingScreenCoordinatorParameters { let timelineController: TimelineControllerProtocol let liveLocationManager: LiveLocationManagerProtocol let appMediator: AppMediatorProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol let mediaProvider: MediaProviderProtocol } diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift index b5c17be7d..a3db3f3cc 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift @@ -17,7 +17,7 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati private let roomProxy: JoinedRoomProxyProtocol private let timelineController: TimelineControllerProtocol private let liveLocationManager: LiveLocationManagerProtocol - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private let notificationCenter: NotificationCenter @@ -36,7 +36,7 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati roomProxy: JoinedRoomProxyProtocol, timelineController: TimelineControllerProtocol, liveLocationManager: LiveLocationManagerProtocol, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol, mediaProvider: MediaProviderProtocol, notificationCenter: NotificationCenter = .default) { @@ -389,15 +389,12 @@ extension LocationSharingScreenViewModel { let roomProxy = JoinedRoomProxyMock(.init(members: .allMembers, ownUserID: RoomMemberProxyMock.mockMe.userID)) roomProxy.makeLiveLocationServiceReturnValue = liveLocationServiceMock - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return LocationSharingScreenViewModel(interactionMode: interactionMode, - mapURLBuilder: appSettings.mapTilerConfiguration, + mapURLBuilder: AppSettings().mapTilerConfiguration, roomProxy: roomProxy, timelineController: MockTimelineController(), liveLocationManager: LiveLocationManagerMock(), - analytics: analytics, + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), mediaProvider: MediaProviderMock(configuration: .init())) } diff --git a/ElementX/Sources/Screens/ManageRoomMemberSheet/ManageRoomMemberSheetViewModel.swift b/ElementX/Sources/Screens/ManageRoomMemberSheet/ManageRoomMemberSheetViewModel.swift index eb353a3b2..9c38224c0 100644 --- a/ElementX/Sources/Screens/ManageRoomMemberSheet/ManageRoomMemberSheetViewModel.swift +++ b/ElementX/Sources/Screens/ManageRoomMemberSheet/ManageRoomMemberSheetViewModel.swift @@ -15,7 +15,7 @@ typealias ManageRoomMemberSheetViewModelType = StateStoreViewModelV2 = .init() @@ -27,7 +27,7 @@ class ManageRoomMemberSheetViewModel: ManageRoomMemberSheetViewModelType, Manage permissions: ManageRoomMemberPermissions, roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, mediaProvider: MediaProviderProtocol) { self.userIndicatorController = userIndicatorController self.roomProxy = roomProxy diff --git a/ElementX/Sources/Screens/ManageRoomMemberSheet/View/ManageRoomMemberSheetView.swift b/ElementX/Sources/Screens/ManageRoomMemberSheet/View/ManageRoomMemberSheetView.swift index b1205d78e..741d4b24c 100644 --- a/ElementX/Sources/Screens/ManageRoomMemberSheet/View/ManageRoomMemberSheetView.swift +++ b/ElementX/Sources/Screens/ManageRoomMemberSheet/View/ManageRoomMemberSheetView.swift @@ -120,7 +120,7 @@ private extension ManageRoomMemberSheetViewModel { ownPowerLevel: powerLevel), roomProxy: JoinedRoomProxyMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - analyticsService: .mock(), + analyticsService: AnalyticsServiceMock.default(), mediaProvider: MediaProviderMock(configuration: .init())) } } diff --git a/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift b/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift index 39db9e099..f523126f0 100644 --- a/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift +++ b/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift @@ -17,7 +17,7 @@ struct MediaEventsTimelineScreenCoordinatorParameters { let mediaPlayerProvider: MediaPlayerProviderProtocol let appMediator: AppMediatorProtocol let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let emojiProvider: EmojiProviderProtocol let linkMetadataProvider: LinkMetadataProviderProtocol let userIndicatorController: UserIndicatorControllerProtocol diff --git a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/MediaEventsTimelineScreen.swift b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/MediaEventsTimelineScreen.swift index d227c7a9b..c5dc46da9 100644 --- a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/MediaEventsTimelineScreen.swift +++ b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/MediaEventsTimelineScreen.swift @@ -311,8 +311,6 @@ struct MediaEventsTimelineScreen_Previews: PreviewProvider, TestablePreview { } let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")), timelineController: timelineController, userSession: UserSessionMock(.init()), @@ -320,7 +318,7 @@ struct MediaEventsTimelineScreen_Previews: PreviewProvider, TestablePreview { userIndicatorController: UserIndicatorControllerMock(), appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) diff --git a/ElementX/Sources/Screens/Onboarding/AnalyticsPromptScreen/AnalyticsPromptScreenCoordinator.swift b/ElementX/Sources/Screens/Onboarding/AnalyticsPromptScreen/AnalyticsPromptScreenCoordinator.swift index 7006c4236..16e4f98bc 100644 --- a/ElementX/Sources/Screens/Onboarding/AnalyticsPromptScreen/AnalyticsPromptScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Onboarding/AnalyticsPromptScreen/AnalyticsPromptScreenCoordinator.swift @@ -14,7 +14,7 @@ enum AnalyticsPromptScreenCoordinatorAction { } final class AnalyticsPromptScreenCoordinator: CoordinatorProtocol { - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private var viewModel: AnalyticsPromptScreenViewModelProtocol private let actionsSubject: PassthroughSubject = .init() private var cancellables = Set() @@ -23,7 +23,7 @@ final class AnalyticsPromptScreenCoordinator: CoordinatorProtocol { actionsSubject.eraseToAnyPublisher() } - init(analytics: AnalyticsService, termsURL: URL?) { + init(analytics: AnalyticsServiceProtocol, termsURL: URL?) { self.analytics = analytics viewModel = AnalyticsPromptScreenViewModel(termsURL: termsURL) } diff --git a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift index e34e872b3..d0e5ab3fb 100644 --- a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift +++ b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift @@ -16,7 +16,7 @@ struct PinnedEventsTimelineScreenCoordinatorParameters { let mediaPlayerProvider: MediaPlayerProviderProtocol let appMediator: AppMediatorProtocol let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let emojiProvider: EmojiProviderProtocol let linkMetadataProvider: LinkMetadataProviderProtocol let timelineControllerFactory: TimelineControllerFactoryProtocol diff --git a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenViewModel.swift b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenViewModel.swift index 75cf1868f..0ef821136 100644 --- a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenViewModel.swift +++ b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenViewModel.swift @@ -15,7 +15,7 @@ class PinnedEventsTimelineScreenViewModel: PinnedEventsTimelineScreenViewModelTy private let roomProxy: JoinedRoomProxyProtocol private let userIndicatorController: UserIndicatorControllerProtocol private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let actionsSubject: PassthroughSubject = .init() var actionsPublisher: AnyPublisher { @@ -25,7 +25,7 @@ class PinnedEventsTimelineScreenViewModel: PinnedEventsTimelineScreenViewModelTy init(roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, appSettings: AppSettings, - analyticsService: AnalyticsService) { + analyticsService: AnalyticsServiceProtocol) { self.roomProxy = roomProxy self.userIndicatorController = userIndicatorController self.appSettings = appSettings diff --git a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/View/PinnedEventsTimelineScreen.swift b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/View/PinnedEventsTimelineScreen.swift index d2c73c65a..954bcf0ea 100644 --- a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/View/PinnedEventsTimelineScreen.swift +++ b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/View/PinnedEventsTimelineScreen.swift @@ -69,15 +69,13 @@ struct PinnedEventsTimelineScreen_Previews: PreviewProvider, TestablePreview { static let viewModel = PinnedEventsTimelineScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()), userIndicatorController: UserIndicatorControllerMock(), appSettings: AppSettings(), - analyticsService: .mock()) + analyticsService: AnalyticsServiceMock.default()) static let emptyTimelineViewModel: TimelineViewModel = { let timelineController = MockTimelineController(timelineKind: .pinned) timelineController.timelineItems = [] let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")), timelineController: timelineController, userSession: UserSessionMock(.init()), @@ -85,7 +83,7 @@ struct PinnedEventsTimelineScreen_Previews: PreviewProvider, TestablePreview { userIndicatorController: UserIndicatorControllerMock(), appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) diff --git a/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenCoordinator.swift b/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenCoordinator.swift index 3fa28741e..259022bb7 100644 --- a/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenCoordinator.swift @@ -14,7 +14,7 @@ struct RoomChangePermissionsScreenCoordinatorParameters { let permissions: RoomPermissions let roomProxy: JoinedRoomProxyProtocol let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum RoomChangePermissionsScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenViewModel.swift b/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenViewModel.swift index 5f5d1d6be..a11226bb1 100644 --- a/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenViewModel.swift @@ -15,7 +15,7 @@ typealias RoomChangePermissionsScreenViewModelType = StateStoreViewModelV2 = .init() var actionsPublisher: AnyPublisher { @@ -26,7 +26,7 @@ class RoomChangePermissionsScreenViewModel: RoomChangePermissionsScreenViewModel ownPowerLevel: RoomPowerLevel, roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analytics: AnalyticsService) { + analytics: AnalyticsServiceProtocol) { self.roomProxy = roomProxy self.userIndicatorController = userIndicatorController self.analytics = analytics diff --git a/ElementX/Sources/Screens/RoomChangePermissionsScreen/View/RoomChangePermissionsScreen.swift b/ElementX/Sources/Screens/RoomChangePermissionsScreen/View/RoomChangePermissionsScreen.swift index bedfa48ee..8e3f1350a 100644 --- a/ElementX/Sources/Screens/RoomChangePermissionsScreen/View/RoomChangePermissionsScreen.swift +++ b/ElementX/Sources/Screens/RoomChangePermissionsScreen/View/RoomChangePermissionsScreen.swift @@ -91,6 +91,6 @@ struct RoomChangePermissionsScreen_Previews: PreviewProvider, TestablePreview { ownPowerLevel: ownPowerLevel, roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)), userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenCoordinator.swift b/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenCoordinator.swift index 33b0d9d19..4af27b12b 100644 --- a/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenCoordinator.swift @@ -14,7 +14,7 @@ struct RoomChangeRolesScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol let mediaProvider: MediaProviderProtocol let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum RoomChangeRolesScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenViewModel.swift b/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenViewModel.swift index 401399c78..bb2029b4c 100644 --- a/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomChangeRolesScreen/RoomChangeRolesScreenViewModel.swift @@ -14,7 +14,7 @@ typealias RoomChangeRolesScreenViewModelType = StateStoreViewModelV2 = .init() var actionsPublisher: AnyPublisher { @@ -25,7 +25,7 @@ class RoomChangeRolesScreenViewModel: RoomChangeRolesScreenViewModelType, RoomCh roomProxy: JoinedRoomProxyProtocol, mediaProvider: MediaProviderProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analytics: AnalyticsService) { + analytics: AnalyticsServiceProtocol) { guard mode != .user || mode != .creator else { fatalError("Invalid screen configuration: \(mode)") } self.roomProxy = roomProxy diff --git a/ElementX/Sources/Screens/RoomChangeRolesScreen/View/RoomChangeRolesScreen.swift b/ElementX/Sources/Screens/RoomChangeRolesScreen/View/RoomChangeRolesScreen.swift index e1598d29e..93bb13944 100644 --- a/ElementX/Sources/Screens/RoomChangeRolesScreen/View/RoomChangeRolesScreen.swift +++ b/ElementX/Sources/Screens/RoomChangeRolesScreen/View/RoomChangeRolesScreen.swift @@ -151,6 +151,6 @@ struct RoomChangeRolesScreen_Previews: PreviewProvider, TestablePreview { roomProxy: JoinedRoomProxyMock(.init(members: members)), mediaProvider: MediaProviderMock(configuration: .init()), userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift index 908b9c714..20ead18e0 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift @@ -12,7 +12,7 @@ import SwiftUI struct RoomDetailsScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol let userSession: UserSessionProtocol - let analyticsService: AnalyticsService + let analyticsService: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol let notificationSettings: NotificationSettingsProxyProtocol let attributedStringBuilder: AttributedStringBuilderProtocol diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift index 60bfb3a37..be18cf34b 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift @@ -14,7 +14,7 @@ typealias RoomDetailsScreenViewModelType = StateStoreViewModelV2 RoomDetailsScreenViewModel { @@ -449,16 +446,13 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return .init(roomProxy: roomProxy, userSession: UserSessionMock(.init()), - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxy, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) } private static func makeDMViewModel(verificationState: UserIdentityVerificationState) -> RoomDetailsScreenViewModel { @@ -490,15 +484,12 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init()) - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return .init(roomProxy: roomProxy, userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxy, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) } } diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenCoordinator.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenCoordinator.swift index b93653641..a9d6285ad 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenCoordinator.swift @@ -14,7 +14,7 @@ struct RoomMemberDetailsScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let appSettings: AppSettings } diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift index d2ab70763..1fb09ceeb 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/RoomMemberDetailsScreenViewModel.swift @@ -15,7 +15,7 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro private let roomProxy: JoinedRoomProxyProtocol private let userSession: UserSessionProtocol private let userIndicatorController: UserIndicatorControllerProtocol - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let appSettings: AppSettings private var actionsSubject: PassthroughSubject = .init() @@ -30,7 +30,7 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro roomProxy: JoinedRoomProxyProtocol, userSession: UserSessionProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, appSettings: AppSettings) { self.roomProxy = roomProxy self.userSession = userSession diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift index 11302ec8a..07fd5a596 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift @@ -236,14 +236,11 @@ struct RoomMemberDetailsScreen_Previews: PreviewProvider, TestablePreview { clientProxyMock.directRoomForUserIDReturnValue = .success("roomID") } - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return RoomMemberDetailsScreenViewModel(userID: member.userID, roomProxy: roomProxyMock, userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userIndicatorController: UserIndicatorControllerMock.default, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) } } diff --git a/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenCoordinator.swift b/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenCoordinator.swift index 2679ac756..8860516f5 100644 --- a/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenCoordinator.swift @@ -13,7 +13,7 @@ struct RoomMembersListScreenCoordinatorParameters { let userSession: UserSessionProtocol let roomProxy: JoinedRoomProxyProtocol let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum RoomMembersListScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenViewModel.swift b/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenViewModel.swift index 7148115a3..1963916a0 100644 --- a/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomMemberListScreen/RoomMembersListScreenViewModel.swift @@ -15,7 +15,7 @@ class RoomMembersListScreenViewModel: RoomMembersListScreenViewModelType, RoomMe private let userSession: UserSessionProtocol private let roomProxy: JoinedRoomProxyProtocol private let userIndicatorController: UserIndicatorControllerProtocol - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private var members: [RoomMemberProxyProtocol] = [] private var currentUserProxy: RoomMemberProxyProtocol? @@ -30,7 +30,7 @@ class RoomMembersListScreenViewModel: RoomMembersListScreenViewModelType, RoomMe userSession: UserSessionProtocol, roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analytics: AnalyticsService) { + analytics: AnalyticsServiceProtocol) { self.userSession = userSession self.roomProxy = roomProxy self.userIndicatorController = userIndicatorController diff --git a/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreen.swift b/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreen.swift index e6e2e21cd..aee4c28e3 100644 --- a/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreen.swift +++ b/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreen.swift @@ -262,6 +262,6 @@ struct RoomMembersListScreen_Previews: PreviewProvider, TestablePreview { ownUserID: ownUserID, powerLevelsConfiguration: .init(canUserInvite: false))), userIndicatorController: UserIndicatorControllerMock.default, - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreenMemberCell.swift b/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreenMemberCell.swift index 840543f70..cb9fc5bf4 100644 --- a/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreenMemberCell.swift +++ b/ElementX/Sources/Screens/RoomMemberListScreen/View/RoomMembersListScreenMemberCell.swift @@ -132,7 +132,7 @@ struct RoomMembersListMemberCell_Previews: PreviewProvider, TestablePreview { static let viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), roomProxy: JoinedRoomProxyMock(.init(name: "Some room", members: [])), userIndicatorController: UserIndicatorControllerMock.default, - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) static var previews: some View { VStack(spacing: 0) { Section("Invited/Joined") { diff --git a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenCoordinator.swift b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenCoordinator.swift index 3b8a2185a..8cec8b8e6 100644 --- a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenCoordinator.swift @@ -12,7 +12,7 @@ import SwiftUI struct RoomRolesAndPermissionsScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol let userIndicatorController: UserIndicatorControllerProtocol - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum RoomRolesAndPermissionsScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenViewModel.swift b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenViewModel.swift index 87f7b1696..b10f8f2e9 100644 --- a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/RoomRolesAndPermissionsScreenViewModel.swift @@ -14,7 +14,7 @@ typealias RoomRolesAndPermissionsScreenViewModelType = StateStoreViewModelV2 = .init() @@ -22,7 +22,7 @@ class RoomRolesAndPermissionsScreenViewModel: RoomRolesAndPermissionsScreenViewM actionsSubject.eraseToAnyPublisher() } - init(initialPermissions: RoomPermissions? = nil, roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, analytics: AnalyticsService) { + init(initialPermissions: RoomPermissions? = nil, roomProxy: JoinedRoomProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol, analytics: AnalyticsServiceProtocol) { self.roomProxy = roomProxy self.userIndicatorController = userIndicatorController self.analytics = analytics diff --git a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/View/RoomRolesAndPermissionsScreen.swift b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/View/RoomRolesAndPermissionsScreen.swift index 7b1e7d5ed..d28755085 100644 --- a/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/View/RoomRolesAndPermissionsScreen.swift +++ b/ElementX/Sources/Screens/RoomRolesAndPermissionsScreen/View/RoomRolesAndPermissionsScreen.swift @@ -121,12 +121,12 @@ struct RoomRolesAndPermissionsScreen_Previews: PreviewProvider, TestablePreview static let viewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock), roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsAdmin)), userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) static let creatorViewModel = RoomRolesAndPermissionsScreenViewModel(initialPermissions: RoomPermissions(powerLevels: .mock), roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsCreator)), userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) static var previews: some View { ElementNavigationStack { RoomRolesAndPermissionsScreen(context: viewModel.context) diff --git a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift index 545e8fdbc..97395d88d 100644 --- a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift @@ -20,7 +20,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool private let wysiwygViewModel: WysiwygComposerViewModel private let completionSuggestionService: CompletionSuggestionServiceProtocol private let roomProxy: JoinedRoomProxyProtocol - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let draftService: ComposerDraftServiceProtocol private var identityPinningViolations = [String: RoomMemberProxyProtocol]() @@ -52,7 +52,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool mediaProvider: MediaProviderProtocol, mentionDisplayHelper: MentionDisplayHelper, appSettings: AppSettings, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, composerDraftService: ComposerDraftServiceProtocol) { self.initialText = initialText self.wysiwygViewModel = wysiwygViewModel @@ -820,17 +820,14 @@ extension ComposerToolbarViewModel { roomProxy.identityStatusChangesPublisher = .init([.init(userId: RoomMemberProxyMock.mockAlice.userID, changedTo: .verificationViolation)]) } - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - let wysiwygViewModel = WysiwygComposerViewModel() let viewModel = ComposerToolbarViewModel(roomProxy: roomProxy, wysiwygViewModel: wysiwygViewModel, completionSuggestionService: CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions)), mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, - appSettings: appSettings, - analyticsService: analytics, + appSettings: AppSettings(), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: ComposerDraftServiceMock(.init())) viewModel.state.bindings.composerFocused = focused viewModel.state.bindings.plainComposerText = NSAttributedString(string: message) diff --git a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/RoomAttachmentPicker.swift b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/RoomAttachmentPicker.swift index 65a8d0c8e..4435f52f7 100644 --- a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/RoomAttachmentPicker.swift +++ b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/RoomAttachmentPicker.swift @@ -89,7 +89,7 @@ struct RoomAttachmentPicker_Previews: PreviewProvider, TestablePreview { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: ComposerDraftServiceMock(.init())) } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index 36c1eb19c..47caa6db4 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -26,7 +26,7 @@ struct RoomScreenCoordinatorParameters { let appMediator: AppMediatorProtocol let appSettings: AppSettings let appHooks: AppHooks - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let composerDraftService: ComposerDraftServiceProtocol let timelineControllerFactory: TimelineControllerFactoryProtocol let userIndicatorController: UserIndicatorControllerProtocol diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index ad32d15a5..8839c1540 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -18,7 +18,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol private let clientProxy: ClientProxyProtocol private let roomProxy: JoinedRoomProxyProtocol private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private var initialSelectedPinnedEventID: String? @@ -56,7 +56,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol ongoingCallRoomIDPublisher: CurrentValuePublisher, appSettings: AppSettings, appHooks: AppHooks, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol) { clientProxy = userSession.clientProxy self.roomProxy = roomProxy @@ -457,17 +457,14 @@ extension RoomScreenViewModel { static func mock(roomProxyMock: JoinedRoomProxyMock, clientProxyMock: ClientProxyMock = ClientProxyMock(.init()), appHooks: AppHooks = AppHooks()) -> RoomScreenViewModel { - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - - return RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), - roomProxy: roomProxyMock, - initialSelectedPinnedEventID: nil, - ongoingCallRoomIDPublisher: .init(.init(nil)), - appSettings: appSettings, - appHooks: appHooks, - analyticsService: analytics, - userIndicatorController: UserIndicatorControllerMock.default) + RoomScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), + roomProxy: roomProxyMock, + initialSelectedPinnedEventID: nil, + ongoingCallRoomIDPublisher: .init(.init(nil)), + appSettings: AppSettings(), + appHooks: appHooks, + analyticsService: AnalyticsServiceMock.default(), + userIndicatorController: UserIndicatorControllerMock.default) } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index b82c5a650..07bee8733 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -258,8 +258,6 @@ struct RoomScreen_Previews: PreviewProvider, TestablePreview { let roomViewModel = RoomScreenViewModel.mock(roomProxyMock: roomProxyMock) let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - let timelineViewModel = TimelineViewModel(roomProxy: roomProxyMock, timelineController: MockTimelineController(), userSession: UserSessionMock(.init()), @@ -267,7 +265,7 @@ struct RoomScreen_Previews: PreviewProvider, TestablePreview { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) diff --git a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenCoordinator.swift b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenCoordinator.swift index 1f99d3278..822961070 100644 --- a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenCoordinator.swift @@ -11,7 +11,7 @@ import SwiftUI struct AdvancedSettingsScreenCoordinatorParameters { let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol let clientProxy: ClientProxyProtocol let userIndicatorController: UserIndicatorControllerProtocol } diff --git a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenViewModel.swift b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenViewModel.swift index beda45a54..5dce5c05b 100644 --- a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenViewModel.swift +++ b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/AdvancedSettingsScreenViewModel.swift @@ -12,7 +12,7 @@ import SwiftUI typealias AdvancedSettingsScreenViewModelType = StateStoreViewModelV2 class AdvancedSettingsScreenViewModel: AdvancedSettingsScreenViewModelType, AdvancedSettingsScreenViewModelProtocol { - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let clientProxy: ClientProxyProtocol private let userIndicatorController: UserIndicatorControllerProtocol @@ -20,7 +20,7 @@ class AdvancedSettingsScreenViewModel: AdvancedSettingsScreenViewModelType, Adva private var hideInviteAvatarsTask: Task? init(advancedSettings: AdvancedSettingsProtocol, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, clientProxy: ClientProxyProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.analytics = analytics diff --git a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/View/AdvancedSettingsScreen.swift b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/View/AdvancedSettingsScreen.swift index 96a4764f9..d99c96b9b 100644 --- a/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/View/AdvancedSettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/AdvancedSettingsScreen/View/AdvancedSettingsScreen.swift @@ -164,7 +164,7 @@ struct AdvancedSettingsScreen_Previews: PreviewProvider, TestablePreview { AppSettings.resetAllSettings() let appSettings = AppSettings() return AdvancedSettingsScreenViewModel(advancedSettings: appSettings, - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), clientProxy: ClientProxyMock(.init()), userIndicatorController: UserIndicatorControllerMock.default) }() diff --git a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenCoordinator.swift b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenCoordinator.swift index 379449fcd..559fdb9c6 100644 --- a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenCoordinator.swift @@ -11,7 +11,7 @@ import SwiftUI struct AnalyticsSettingsScreenCoordinatorParameters { let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } final class AnalyticsSettingsScreenCoordinator: CoordinatorProtocol { diff --git a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenViewModel.swift b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenViewModel.swift index 954ec8fa4..909a0d1b3 100644 --- a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenViewModel.swift +++ b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/AnalyticsSettingsScreenViewModel.swift @@ -12,9 +12,9 @@ import SwiftUI typealias AnalyticsSettingsScreenViewModelType = StateStoreViewModelV2 class AnalyticsSettingsScreenViewModel: AnalyticsSettingsScreenViewModelType, AnalyticsSettingsScreenViewModelProtocol { - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol - init(appSettings: AppSettings, analytics: AnalyticsService) { + init(appSettings: AppSettings, analytics: AnalyticsServiceProtocol) { self.analytics = analytics let strings = AnalyticsSettingsScreenStrings(termsURL: appSettings.analyticsTermsURL) diff --git a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/View/AnalyticsSettingsScreen.swift b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/View/AnalyticsSettingsScreen.swift index a39e70762..955f620d0 100644 --- a/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/View/AnalyticsSettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/AnalyticsSettingsScreen/View/AnalyticsSettingsScreen.swift @@ -40,9 +40,8 @@ struct AnalyticsSettingsScreen: View { struct AnalyticsSettingsScreen_Previews: PreviewProvider, TestablePreview { static var previews: some View { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings, - analytics: analytics) + analytics: AnalyticsServiceMock.default()) AnalyticsSettingsScreen(context: viewModel.context) } } diff --git a/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift b/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift index b57f9d9a5..f20e2bb72 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift @@ -126,20 +126,17 @@ struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview { static let userViewModel = makeViewModel(members: .allMembers) static func makeViewModel(members: [RoomMemberProxyMock]) -> RoomDetailsScreenViewModel { - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - - return RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space", - avatarURL: .mockMXCAvatar, - isSpace: true, - canonicalAlias: "#space:matrix.org", - members: members)), - userSession: UserSessionMock(.init()), - analyticsService: analytics, - userIndicatorController: UserIndicatorControllerMock.default, - notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), - attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + RoomDetailsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space", + avatarURL: .mockMXCAvatar, + isSpace: true, + canonicalAlias: "#space:matrix.org", + members: members)), + userSession: UserSessionMock(.init()), + analyticsService: AnalyticsServiceMock.default(), + userIndicatorController: UserIndicatorControllerMock.default, + notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), + attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), + appSettings: AppSettings()) } static var previews: some View { diff --git a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift index e6701b206..b4d2afa6e 100644 --- a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift +++ b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenCoordinator.swift @@ -14,7 +14,7 @@ struct StartChatScreenCoordinatorParameters { let userDiscoveryService: UserDiscoveryServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol let appSettings: AppSettings - let analytics: AnalyticsService + let analytics: AnalyticsServiceProtocol } enum StartChatScreenCoordinatorAction { diff --git a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift index 63dc76426..92714fdf6 100644 --- a/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift +++ b/ElementX/Sources/Screens/StartChatScreen/StartChatScreenViewModel.swift @@ -14,7 +14,7 @@ typealias StartChatScreenViewModelType = StateStoreViewModel = .init() @@ -27,7 +27,7 @@ class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScr isPresentedModally: Bool, userSession: UserSessionProtocol, userIndicatorController: UserIndicatorControllerProtocol, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, appSettings: AppSettings) { self.userSession = userSession self.userIndicatorController = userIndicatorController diff --git a/ElementX/Sources/Screens/UserProfileScreen/View/UserProfileScreen.swift b/ElementX/Sources/Screens/UserProfileScreen/View/UserProfileScreen.swift index 2880b3a73..6a04340a6 100644 --- a/ElementX/Sources/Screens/UserProfileScreen/View/UserProfileScreen.swift +++ b/ElementX/Sources/Screens/UserProfileScreen/View/UserProfileScreen.swift @@ -143,14 +143,11 @@ struct UserProfileScreen_Previews: PreviewProvider, TestablePreview { clientProxyMock.directRoomForUserIDReturnValue = .success("roomID") } - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - return UserProfileScreenViewModel(userID: userID, isPresentedModally: false, userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), userIndicatorController: UserIndicatorControllerMock.default, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) } } diff --git a/ElementX/Sources/Services/Analytics/AnalyticsService.swift b/ElementX/Sources/Services/Analytics/AnalyticsService.swift index d76f60b80..bb55ea75d 100644 --- a/ElementX/Sources/Services/Analytics/AnalyticsService.swift +++ b/ElementX/Sources/Services/Analytics/AnalyticsService.swift @@ -10,26 +10,11 @@ import AnalyticsEvents import Combine import PostHog -/// A class responsible for managing a variety of analytics clients -/// and sending events through these clients. -/// -/// Events may include user activity, or app health data such as crashes, -/// non-fatal issues and performance. `Analytics` class serves as a façade -/// to all these use cases. -/// -/// ## Creating Analytics Events -/// -/// Events are managed in a shared repo for all Element clients https://github.com/matrix-org/matrix-analytics-events -/// To add a new event create a PR to that repo with the new/updated schema. Once merged -/// into `main`, update the AnalyticsEvents Swift package in `project.yml`. -/// -class AnalyticsService { +class AnalyticsService: AnalyticsServiceProtocol { /// The analytics client to send events with. private let client: AnalyticsClientProtocol private let appSettings: AppSettings - /// A signpost client for performance testing the app. This client doesn't respect the - /// `isRunning` state or behave any differently when `start`/`reset` are called. let signpost = Signposter() init(client: AnalyticsClientProtocol, appSettings: AppSettings) { @@ -37,7 +22,6 @@ class AnalyticsService { self.appSettings = appSettings } - /// Whether to show the user the analytics opt in prompt. var shouldShowAnalyticsPrompt: Bool { // Only show the prompt once, and when analytics are enabled in BuildSettings. appSettings.analyticsConsentState == .unknown && appSettings.canPromptForAnalytics @@ -47,13 +31,11 @@ class AnalyticsService { appSettings.analyticsConsentState == .optedIn } - /// Opts in to analytics tracking with the supplied user session. func optIn() { appSettings.analyticsConsentState = .optedIn startIfEnabled() } - /// Stops analytics tracking and calls `reset` to clear any IDs and event queues. func optOut() { appSettings.analyticsConsentState = .optedOut @@ -64,7 +46,6 @@ class AnalyticsService { MXLog.info("Stopped.") } - /// Starts the analytics client if the user has opted in, otherwise does nothing. func startIfEnabled() { guard isEnabled, !client.isRunning, let configuration = appSettings.analyticsConfiguration else { return } @@ -76,16 +57,11 @@ class AnalyticsService { MXLog.info("Started.") } - /// Resets the any IDs and event queues in the analytics client. This method should - /// be called on sign-out to maintain opt-in status, whilst ensuring the next - /// account used isn't associated with the previous one. - /// Note: **MUST** be called before stopping PostHog or the reset is ignored. func reset() { client.reset() MXLog.info("Reset.") } - /// Reset the consent state for analytics func resetConsentState() { MXLog.warning("Resetting consent state for analytics.") appSettings.analyticsConsentState = .unknown @@ -104,9 +80,6 @@ class AnalyticsService { // MARK: - Public tracking methods extension AnalyticsService { - /// Track the presentation of a screen - /// - Parameter screen: The screen that was shown - /// - Parameter duration: An optional value representing how long the screen was shown for in milliseconds. func track(screen: AnalyticsEvent.MobileScreen.ScreenName, duration milliseconds: Int? = nil) { MXLog.debug("\(screen)") let event = AnalyticsEvent.MobileScreen(durationMs: milliseconds, screenName: screen) @@ -117,12 +90,6 @@ extension AnalyticsService { capture(event: AnalyticsEvent.Interaction(index: index, interactionType: .Touch, name: name)) } - /// Track the presentation of a screen - /// - Parameter context: To provide additional context or description for the error - /// - Parameter domain: The domain to which the error belongs to. - /// - Parameter name: The name of the error - /// - Parameter timeToDecryptMillis: The time it took to decrypt the event in milliseconds, needs to be used only to track UTD errors, otherwise if the error is nort related to UTD it should be nil. - /// Can be found in `UnableToDecryptInfo`. In case the `UnableToDecryptInfo` contains the value as nil, pass it as `-1` func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int? = nil, @@ -145,19 +112,10 @@ extension AnalyticsService { wasVisibleToUser: wasVisibleToUser)) } - /// Track the creation of a room - /// - Parameter isDM: true if the created room is a direct message, false otherwise func trackCreatedRoom(isDM: Bool) { capture(event: AnalyticsEvent.CreatedRoom(isDM: isDM)) } - /// Track the composer - /// - Parameters: - /// - inThread: whether the composer is used in a Thread - /// - isEditing: whether the composer is used to edit a message - /// - isReply: whether the composer is used to reply a message - /// - messageType: the type of the message - /// - startsThread: whether the composer is used to start a new thread func trackComposer(inThread: Bool, isEditing: Bool, isReply: Bool, @@ -170,19 +128,10 @@ extension AnalyticsService { startsThread: startsThread)) } - /// Track the presentation of a room - /// - Parameters: - /// - isDM: whether the room is a direct message - /// - isSpace: whether the room is a space func trackViewRoom(isDM: Bool, isSpace: Bool) { capture(event: AnalyticsEvent.ViewRoom(activeSpace: nil, isDM: isDM, isSpace: isSpace, trigger: nil, viaKeyboard: nil)) } - /// Track the action of joining a room - /// - Parameters: - /// - isDM: whether the room is a direct message - /// - isSpace: whether the room is a space - /// - activeMemberCount: the number of active members in the room func trackJoinedRoom(isDM: Bool, isSpace: Bool, activeMemberCount: UInt) { guard let roomSize = AnalyticsEvent.JoinedRoom.RoomSize(memberCount: activeMemberCount) else { MXLog.error("invalid room size") @@ -191,27 +140,20 @@ extension AnalyticsService { capture(event: AnalyticsEvent.JoinedRoom(isDM: isDM, isSpace: isSpace, roomSize: roomSize, trigger: nil)) } - /// Track the action of creating a poll - /// - Parameters: - /// - isUndisclosed: whether the poll is undisclosed - /// - numberOfAnswers: the number of options in the poll func trackPollCreated(isUndisclosed: Bool, numberOfAnswers: Int) { capture(event: AnalyticsEvent.PollCreation(action: .Create, isUndisclosed: isUndisclosed, numberOfAnswers: numberOfAnswers)) } - /// Track the action of voting on a poll func trackPollVote() { capture(event: AnalyticsEvent.PollVote(doNotUse: nil)) } - /// Track the action of ending a poll func trackPollEnd() { capture(event: AnalyticsEvent.PollEnd(doNotUse: nil)) } - /// Track a room moderation action. func trackRoomModeration(action: AnalyticsEvent.RoomModeration.Action, role: RoomRole?) { let role = role.map(AnalyticsEvent.RoomModeration.Role.init) capture(event: AnalyticsEvent.RoomModeration(action: action, role: role)) diff --git a/ElementX/Sources/Services/Analytics/AnalyticsServiceProtocol.swift b/ElementX/Sources/Services/Analytics/AnalyticsServiceProtocol.swift new file mode 100644 index 000000000..9bd8e0026 --- /dev/null +++ b/ElementX/Sources/Services/Analytics/AnalyticsServiceProtocol.swift @@ -0,0 +1,160 @@ +// +// Copyright 2026 Element Creations Ltd. +// +// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. +// Please see LICENSE files in the repository root for full details. +// + +import AnalyticsEvents + +/// A service responsible for managing analytics clients and sending events through them. +/// +/// Events may include user activity, or app health data such as crashes, +/// non-fatal issues and performance. +/// +/// ## Creating Analytics Events +/// +/// Events are managed in a shared repo for all Element clients https://github.com/matrix-org/matrix-analytics-events +/// To add a new event create a PR to that repo with the new/updated schema. Once merged +/// into `main`, update the AnalyticsEvents Swift package in `project.yml`. +protocol AnalyticsServiceProtocol: AnyObject { + /// A signpost client for performance testing the app. This client doesn't respect the + /// `isRunning` state or behave any differently when `start`/`reset` are called. + var signpost: Signposter { get } + + /// Whether to show the user the analytics opt in prompt. + var shouldShowAnalyticsPrompt: Bool { get } + + /// Whether analytics tracking is currently enabled. + var isEnabled: Bool { get } + + /// Opts in to analytics tracking. + func optIn() + + /// Stops analytics tracking and calls `reset` to clear any IDs and event queues. + func optOut() + + /// Starts the analytics client if the user has opted in, otherwise does nothing. + func startIfEnabled() + + /// Resets any IDs and event queues in the analytics client. This method should + /// be called on sign-out to maintain opt-in status, whilst ensuring the next + /// account used isn't associated with the previous one. + /// Note: **MUST** be called before stopping PostHog or the reset is ignored. + func reset() + + /// Resets the consent state for analytics. + func resetConsentState() + + /// Track the presentation of a screen. + /// - Parameter screen: The screen that was shown. + /// - Parameter milliseconds: An optional value representing how long the screen was shown for in milliseconds. + func track(screen: AnalyticsEvent.MobileScreen.ScreenName, duration milliseconds: Int?) + func trackInteraction(index: Int?, name: AnalyticsEvent.Interaction.Name) + + /// Track an analytics error event. + /// - Parameter context: Additional context or description for the error. + /// - Parameter domain: The domain to which the error belongs. + /// - Parameter name: The name of the error. + /// - Parameter timeToDecryptMillis: The time it took to decrypt the event in milliseconds. Only used for UTD errors; pass `nil` otherwise. + /// Can be found in `UnableToDecryptInfo`. If `UnableToDecryptInfo` contains `nil` for this value, pass `-1`. + func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, + name: AnalyticsEvent.Error.Name, + timeToDecryptMillis: Int?, + eventLocalAgeMillis: Int?, + isFederated: Bool?, + isMatrixDotOrg: Bool?, + userTrustsOwnIdentity: Bool?, + wasVisibleToUser: Bool?) + + /// Track the creation of a room. + /// - Parameter isDM: `true` if the created room is a direct message, `false` otherwise. + func trackCreatedRoom(isDM: Bool) + + /// Track the composer. + /// - Parameters: + /// - inThread: Whether the composer is used in a thread. + /// - isEditing: Whether the composer is used to edit a message. + /// - isReply: Whether the composer is used to reply to a message. + /// - messageType: The type of the message. + /// - startsThread: Whether the composer is used to start a new thread. + func trackComposer(inThread: Bool, + isEditing: Bool, + isReply: Bool, + messageType: AnalyticsEvent.Composer.MessageType, + startsThread: Bool?) + + /// Track the presentation of a room. + /// - Parameters: + /// - isDM: Whether the room is a direct message. + /// - isSpace: Whether the room is a space. + func trackViewRoom(isDM: Bool, isSpace: Bool) + + /// Track the action of joining a room. + /// - Parameters: + /// - isDM: Whether the room is a direct message. + /// - isSpace: Whether the room is a space. + /// - activeMemberCount: The number of active members in the room. + func trackJoinedRoom(isDM: Bool, isSpace: Bool, activeMemberCount: UInt) + + /// Track the action of creating a poll. + /// - Parameters: + /// - isUndisclosed: Whether the poll is undisclosed. + /// - numberOfAnswers: The number of options in the poll. + func trackPollCreated(isUndisclosed: Bool, numberOfAnswers: Int) + + /// Track the action of voting on a poll. + func trackPollVote() + + /// Track the action of ending a poll. + func trackPollEnd() + + /// Track a room moderation action. + func trackRoomModeration(action: AnalyticsEvent.RoomModeration.Action, role: RoomRole?) + func trackSessionSecurityState(_ state: SessionSecurityState) + func updateUserProperties(_ userProperties: AnalyticsEvent.UserProperties) + func trackPinUnpinEvent(_ event: AnalyticsEvent.PinUnpinAction) +} + +// sourcery: AutoMockable +extension AnalyticsServiceProtocol { + func track(screen: AnalyticsEvent.MobileScreen.ScreenName) { + track(screen: screen, duration: nil) + } + + func trackInteraction(name: AnalyticsEvent.Interaction.Name) { + trackInteraction(index: nil, name: name) + } + + @_disfavoredOverload // make sure this doesn't cause infinite recursion + func trackError(context: String?, + domain: AnalyticsEvent.Error.Domain, + name: AnalyticsEvent.Error.Name, + timeToDecryptMillis: Int? = nil, + eventLocalAgeMillis: Int? = nil, + isFederated: Bool? = nil, + isMatrixDotOrg: Bool? = nil, + userTrustsOwnIdentity: Bool? = nil, + wasVisibleToUser: Bool? = nil) { + trackError(context: context, + domain: domain, + name: name, + timeToDecryptMillis: timeToDecryptMillis, + eventLocalAgeMillis: eventLocalAgeMillis, + isFederated: isFederated, + isMatrixDotOrg: isMatrixDotOrg, + userTrustsOwnIdentity: userTrustsOwnIdentity, + wasVisibleToUser: wasVisibleToUser) + } + + func trackComposer(inThread: Bool, + isEditing: Bool, + isReply: Bool, + startsThread: Bool?) { + trackComposer(inThread: inThread, + isEditing: isEditing, + isReply: isReply, + messageType: .Text, + startsThread: startsThread) + } +} diff --git a/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift b/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift index 96b9b4beb..8ecb274cd 100644 --- a/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift +++ b/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift @@ -9,5 +9,5 @@ import SwiftUI extension EnvironmentValues { - @Entry var analyticsService: AnalyticsService? + @Entry var analyticsService: AnalyticsServiceProtocol? } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index d978b5441..7dc6b9caf 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -17,7 +17,7 @@ class ClientProxy: ClientProxyProtocol { private let client: ClientProtocol private let networkMonitor: NetworkMonitorProtocol private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol let mediaLoader: MediaLoaderProtocol private let clientQueue: DispatchQueue @@ -202,7 +202,7 @@ class ClientProxy: ClientProxyProtocol { init(client: ClientProtocol, networkMonitor: NetworkMonitorProtocol, appSettings: AppSettings, - analyticsService: AnalyticsService) async throws { + analyticsService: AnalyticsServiceProtocol) async throws { self.client = client self.networkMonitor = networkMonitor self.appSettings = appSettings diff --git a/ElementX/Sources/Services/Polls/PollInteractionHandler.swift b/ElementX/Sources/Services/Polls/PollInteractionHandler.swift index 8eb232dd3..e6183cf16 100644 --- a/ElementX/Sources/Services/Polls/PollInteractionHandler.swift +++ b/ElementX/Sources/Services/Polls/PollInteractionHandler.swift @@ -9,10 +9,10 @@ import Foundation class PollInteractionHandler: PollInteractionHandlerProtocol { - let analyticsService: AnalyticsService + let analyticsService: AnalyticsServiceProtocol let timelineController: TimelineControllerProtocol - init(analyticsService: AnalyticsService, timelineController: TimelineControllerProtocol) { + init(analyticsService: AnalyticsServiceProtocol, timelineController: TimelineControllerProtocol) { self.analyticsService = analyticsService self.timelineController = timelineController } diff --git a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift index 9d480fc97..1c88ec87c 100644 --- a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift +++ b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift @@ -15,7 +15,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { private let roomListService: RoomListServiceProtocol private let room: RoomProtocol private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let eventStringBuilder: RoomEventStringBuilder // periphery:ignore - required for instance retention in the rust codebase @@ -79,7 +79,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { init(roomListService: RoomListServiceProtocol, room: RoomProtocol, appSettings: AppSettings, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, eventStringBuilder: RoomEventStringBuilder) async throws { self.roomListService = roomListService self.room = room diff --git a/ElementX/Sources/Services/UserSession/UserSessionStore.swift b/ElementX/Sources/Services/UserSession/UserSessionStore.swift index 8bcd97110..dd8ceb4e0 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStore.swift @@ -12,7 +12,7 @@ import MatrixRustSDK class UserSessionStore: UserSessionStoreProtocol { private let keychainController: KeychainControllerProtocol private let appSettings: AppSettings - private let analyticsService: AnalyticsService + private let analyticsService: AnalyticsServiceProtocol private let networkMonitor: NetworkMonitorProtocol private let appHooks: AppHooks @@ -32,7 +32,7 @@ class UserSessionStore: UserSessionStoreProtocol { init(keychainController: KeychainControllerProtocol, appSettings: AppSettings, - analyticsService: AnalyticsService, + analyticsService: AnalyticsServiceProtocol, appHooks: AppHooks, networkMonitor: NetworkMonitorProtocol) { self.keychainController = keychainController diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index 456fa43b4..ea79e1378 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -13,7 +13,7 @@ import UIKit class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate { private let appSettings: AppSettings - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private let navigationRootCoordinator: NavigationRootCoordinator @@ -42,7 +42,7 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate let analyticsClient = AnalyticsClientMock() analyticsClient.isRunning = false - analytics = .mock(analyticsClient, settings: appSettings) + analytics = AnalyticsServiceMock.default() userIndicatorController = UserIndicatorController() windowManager.delegate = self @@ -115,7 +115,7 @@ class MockScreen: Identifiable { let navigationRootCoordinator: NavigationRootCoordinator private let appSettings: AppSettings - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let userIndicatorController: UserIndicatorControllerProtocol private var client: UITestsSignalling.Client? @@ -127,7 +127,7 @@ class MockScreen: Identifiable { windowManager: SecureWindowManagerProtocol, navigationRootCoordinator: NavigationRootCoordinator, appSettings: AppSettings, - analytics: AnalyticsService, + analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.id = id self.windowManager = windowManager diff --git a/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift b/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift index 970c8cd86..19910293b 100644 --- a/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift +++ b/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift @@ -20,7 +20,9 @@ final class AnalyticsSettingsScreenViewModelTests { init() { AppSettings.resetAllSettings() appSettings = AppSettings() - analytics = .mock(settings: appSettings) + let client = AnalyticsClientMock() + client.isRunning = false + analytics = AnalyticsService(client: client, appSettings: appSettings) viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings, analytics: analytics) diff --git a/UnitTests/Sources/AnalyticsTests.swift b/UnitTests/Sources/AnalyticsTests.swift index a79c169a5..f079300c6 100644 --- a/UnitTests/Sources/AnalyticsTests.swift +++ b/UnitTests/Sources/AnalyticsTests.swift @@ -13,7 +13,7 @@ import Testing final class AnalyticsTests { private let appSettings: AppSettings - private let analytics: AnalyticsService + private let analytics: AnalyticsServiceProtocol private let analyticsClient: AnalyticsClientMock private var posthogMock: PHGPostHogMock @@ -24,7 +24,7 @@ final class AnalyticsTests { analyticsClient = AnalyticsClientMock() analyticsClient.isRunning = false - analytics = .mock(analyticsClient, settings: appSettings) + analytics = AnalyticsService(client: analyticsClient, appSettings: appSettings) posthogMock = PHGPostHogMock() posthogMock.configureMockBehavior() diff --git a/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift b/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift index 96bc0aafb..a7b8afcaa 100644 --- a/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift +++ b/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift @@ -32,8 +32,6 @@ struct ChatsTabFlowCoordinatorTests { init() async throws { let appSettings = AppSettings() - let analytics: AnalyticsService = .mock(settings: appSettings) - clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))) timelineControllerFactory = TimelineControllerFactoryMock(.init()) @@ -50,7 +48,7 @@ struct ChatsTabFlowCoordinatorTests { appMediator: AppMediatorMock.default, appSettings: appSettings, appHooks: AppHooks(), - analytics: analytics, + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), notificationManager: notificationManager, stateMachineFactory: stateMachineFactory) diff --git a/UnitTests/Sources/ComposerToolbarViewModelTests.swift b/UnitTests/Sources/ComposerToolbarViewModelTests.swift index 0e7003ba8..44d99c294 100644 --- a/UnitTests/Sources/ComposerToolbarViewModelTests.swift +++ b/UnitTests/Sources/ComposerToolbarViewModelTests.swift @@ -97,7 +97,7 @@ final class ComposerToolbarViewModelTests { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: draftServiceMock) #expect(viewModel.state.suggestions == suggestions) @@ -716,7 +716,7 @@ final class ComposerToolbarViewModelTests { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: draftServiceMock) var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false } @@ -763,7 +763,7 @@ final class ComposerToolbarViewModelTests { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: draftServiceMock) var fulfillment = deferFulfillment(viewModel.context.$viewState, message: "Composer is disabled") { $0.canSend == false } @@ -799,7 +799,7 @@ final class ComposerToolbarViewModelTests { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: draftServiceMock) let deferred = deferFulfillment(viewModel.context.$viewState, message: "Composer should be enabled") { $0.canSend == true } @@ -825,7 +825,7 @@ final class ComposerToolbarViewModelTests { mediaProvider: MediaProviderMock(configuration: .init()), mentionDisplayHelper: ComposerMentionDisplayHelper.mock, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), composerDraftService: draftServiceMock) viewModel.context.composerFormattingEnabled = true } diff --git a/UnitTests/Sources/CreateRoomViewModelTests.swift b/UnitTests/Sources/CreateRoomViewModelTests.swift index 0fad48c2c..05d93519a 100644 --- a/UnitTests/Sources/CreateRoomViewModelTests.swift +++ b/UnitTests/Sources/CreateRoomViewModelTests.swift @@ -18,7 +18,6 @@ final class CreateRoomScreenViewModelTests { var userSession: UserSessionMock! private let appSettings: AppSettings - private let analytics: AnalyticsService private let usersSubject = CurrentValueSubject<[UserProfileProxy], Never>([]) @@ -28,7 +27,6 @@ final class CreateRoomScreenViewModelTests { init() { appSettings = AppSettings() - analytics = .mock(settings: appSettings) } deinit { @@ -95,7 +93,7 @@ final class CreateRoomScreenViewModelTests { spaceSelectionMode: .none, shouldShowCancelButton: false, userSession: userSession, - analytics: analytics, + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), appSettings: appSettings) self.viewModel = viewModel @@ -345,7 +343,7 @@ final class CreateRoomScreenViewModelTests { spaceSelectionMode: spacesSelectionMode, shouldShowCancelButton: false, userSession: userSession, - analytics: analytics, + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), appSettings: appSettings) self.viewModel = viewModel diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index 5e8cf2508..f6d9659d1 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -21,16 +21,12 @@ final class HomeScreenViewModelTests { var roomSummaryProvider: RoomSummaryProviderMock! var notificationManager: NotificationManagerMock! private let appSettings: AppSettings - private let analytics: AnalyticsService - private let userIndicatorController: UserIndicatorControllerProtocol var cancellables = Set() init() { AppSettings.resetAllSettings() appSettings = AppSettings() - analytics = .mock(settings: appSettings) - userIndicatorController = UserIndicatorControllerMock.default } deinit { @@ -444,9 +440,9 @@ final class HomeScreenViewModelTests { viewModel = HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), notificationManager: notificationManager, - userIndicatorController: userIndicatorController) + userIndicatorController: UserIndicatorControllerMock.default) } } diff --git a/UnitTests/Sources/LocationSharingScreenViewModelTests.swift b/UnitTests/Sources/LocationSharingScreenViewModelTests.swift index 6c3c741ba..2cab502fa 100644 --- a/UnitTests/Sources/LocationSharingScreenViewModelTests.swift +++ b/UnitTests/Sources/LocationSharingScreenViewModelTests.swift @@ -401,7 +401,7 @@ struct LocationSharingScreenViewModelTests { roomProxy: roomProxyMock, timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())), liveLocationManager: LiveLocationManagerMock(.init()), - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), mediaProvider: MediaProviderMock(configuration: .init())) @@ -436,7 +436,7 @@ struct LocationSharingScreenViewModelTests { roomProxy: JoinedRoomProxyMock(.init(members: members)), timelineController: MockTimelineController(timelineProxy: timelineProxy), liveLocationManager: LiveLocationManagerMock(liveLocationManagerConfiguration), - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), mediaProvider: MediaProviderMock(configuration: .init())) viewModel.state.bindings.isLocationAuthorized = true @@ -451,7 +451,7 @@ struct LocationSharingScreenViewModelTests { roomProxy: JoinedRoomProxyMock(.init(members: members)), timelineController: MockTimelineController(timelineProxy: timelineProxy), liveLocationManager: liveLocationManagerMock, - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), mediaProvider: MediaProviderMock(configuration: .init())) viewModel.state.bindings.isLocationAuthorized = true @@ -473,7 +473,7 @@ struct LocationSharingScreenViewModelTests { roomProxy: roomProxyMock, timelineController: MockTimelineController(timelineProxy: TimelineProxyMock(.init())), liveLocationManager: LiveLocationManagerMock(.init()), - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), mediaProvider: MediaProviderMock(configuration: .init())) } diff --git a/UnitTests/Sources/LoginScreenViewModelTests.swift b/UnitTests/Sources/LoginScreenViewModelTests.swift index 7f740696e..2f97307ce 100644 --- a/UnitTests/Sources/LoginScreenViewModelTests.swift +++ b/UnitTests/Sources/LoginScreenViewModelTests.swift @@ -247,6 +247,6 @@ struct LoginScreenViewModelTests { loginHint: loginHint, userIndicatorController: UserIndicatorControllerMock(), appSettings: appSettings, - analytics: .mock(settings: appSettings)) + analytics: AnalyticsServiceMock.default()) } } diff --git a/UnitTests/Sources/ManageRoomMemberSheetViewModelTests.swift b/UnitTests/Sources/ManageRoomMemberSheetViewModelTests.swift index 804619093..bed89be51 100644 --- a/UnitTests/Sources/ManageRoomMemberSheetViewModelTests.swift +++ b/UnitTests/Sources/ManageRoomMemberSheetViewModelTests.swift @@ -32,7 +32,7 @@ struct ManageRoomMemberSheetViewModelTests { permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock(), - analyticsService: .mock(), + analyticsService: AnalyticsServiceMock.default(), mediaProvider: MediaProviderMock(configuration: .init())) let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil } @@ -64,7 +64,7 @@ struct ManageRoomMemberSheetViewModelTests { permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock(), - analyticsService: .mock(), + analyticsService: AnalyticsServiceMock.default(), mediaProvider: MediaProviderMock(configuration: .init())) let deferred = deferFulfillment(context.observe(\.viewState.bindings.alertInfo)) { $0 != nil } @@ -87,7 +87,7 @@ struct ManageRoomMemberSheetViewModelTests { permissions: .init(canKick: true, canBan: true, ownPowerLevel: RoomMemberProxyMock.mockAdmin.powerLevel), roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock(), - analyticsService: .mock(), + analyticsService: AnalyticsServiceMock.default(), mediaProvider: MediaProviderMock(configuration: .init())) let deferredAction = deferFulfillment(viewModel.actions) { action in diff --git a/UnitTests/Sources/PillContextTests.swift b/UnitTests/Sources/PillContextTests.swift index 896e7a5f6..8fbedcebd 100644 --- a/UnitTests/Sources/PillContextTests.swift +++ b/UnitTests/Sources/PillContextTests.swift @@ -16,7 +16,6 @@ struct PillContextTests { @Test func user() async { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let id = "@test:matrix.org" @@ -30,7 +29,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -51,7 +50,6 @@ struct PillContextTests { @Test func ownUser() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let id = "@test:matrix.org" @@ -65,7 +63,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -77,7 +75,6 @@ struct PillContextTests { @Test func allUsers() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let avatarURL = URL(string: "https://matrix.jpg") @@ -93,7 +90,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -106,7 +103,6 @@ struct PillContextTests { @Test func roomIDMention() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -121,7 +117,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -135,7 +131,6 @@ struct PillContextTests { @Test func roomIDMentionMissingRoom() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -148,7 +143,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -162,7 +157,6 @@ struct PillContextTests { @Test func roomAliasMention() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -179,7 +173,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -193,7 +187,6 @@ struct PillContextTests { @Test func roomAliasMentionMissingRoom() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -206,7 +199,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -220,7 +213,6 @@ struct PillContextTests { @Test func eventOnRoomIDMention() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -235,7 +227,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -249,7 +241,6 @@ struct PillContextTests { @Test func eventOnRoomIDMentionMissingRoom() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -262,7 +253,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -276,7 +267,6 @@ struct PillContextTests { @Test func eventOnRoomAliasMention() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -293,7 +283,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -307,7 +297,6 @@ struct PillContextTests { @Test func eventOnRoomAliasMentionMissingRoom() { let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let proxyMock = JoinedRoomProxyMock(.init()) @@ -320,7 +309,7 @@ struct PillContextTests { userIndicatorController: userIndicatorController, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: analytics, + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) diff --git a/UnitTests/Sources/PollFormScreenViewModelTests.swift b/UnitTests/Sources/PollFormScreenViewModelTests.swift index 176b06d31..f3dfdf907 100644 --- a/UnitTests/Sources/PollFormScreenViewModelTests.swift +++ b/UnitTests/Sources/PollFormScreenViewModelTests.swift @@ -179,7 +179,7 @@ struct PollFormScreenViewModelTests { private mutating func setupViewModel(mode: PollFormMode = .new) { viewModel = PollFormScreenViewModel(mode: mode, timelineController: MockTimelineController(timelineProxy: timelineProxy), - analytics: .mock(), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock()) } } diff --git a/UnitTests/Sources/RoomChangePermissionsScreenViewModelTests.swift b/UnitTests/Sources/RoomChangePermissionsScreenViewModelTests.swift index 7c7ca5847..0dfe574ee 100644 --- a/UnitTests/Sources/RoomChangePermissionsScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomChangePermissionsScreenViewModelTests.swift @@ -125,6 +125,6 @@ struct RoomChangePermissionsScreenViewModelTests { ownPowerLevel: ownPowerLevel, roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/UnitTests/Sources/RoomChangeRolesScreenViewModelTests.swift b/UnitTests/Sources/RoomChangeRolesScreenViewModelTests.swift index 9a6607bee..0b9835a1c 100644 --- a/UnitTests/Sources/RoomChangeRolesScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomChangeRolesScreenViewModelTests.swift @@ -197,6 +197,6 @@ struct RoomChangeRolesScreenViewModelTests { roomProxy: roomProxy, mediaProvider: MediaProviderMock(configuration: .init()), userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift b/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift index e3752da79..c051ae850 100644 --- a/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift @@ -26,33 +26,29 @@ struct RoomDetailsScreenViewModelTests { init() { AppSettings.resetAllSettings() - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - cancellables.removeAll() roomProxyMock = JoinedRoomProxyMock(.init(name: "Test")) notificationSettingsProxyMock = NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) } @Test mutating func leaveRoomTappedWhenPublic() async throws { - let appSettings = AppSettings() let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil } context.send(viewAction: .processTapLeave) @@ -64,17 +60,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func leaveRoomTappedWhenRoomNotPublic() async throws { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockBob, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState.bindings.leaveRoomAlertItem)) { $0 != nil } context.send(viewAction: .processTapLeave) @@ -87,17 +81,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func leaveRoomTappedWithLessThanTwoMembers() { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) context.send(viewAction: .processTapLeave) #expect(context.leaveRoomAlertItem?.state == .empty) @@ -146,18 +138,16 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func initialDMDetailsState() async throws { - let appSettings = AppSettings() - let recipient = RoomMemberProxyMock.mockDan let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } @@ -168,19 +158,17 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func ignoreSuccess() async throws { - let appSettings = AppSettings() - let recipient = RoomMemberProxyMock.mockDan let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } @@ -200,8 +188,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func ignoreFailure() async throws { - let appSettings = AppSettings() - let recipient = RoomMemberProxyMock.mockDan let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let clientProxy = ClientProxyMock(.init()) @@ -209,11 +195,11 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init(clientProxy: clientProxy)), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } @@ -234,18 +220,16 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func unignoreSuccess() async throws { - let appSettings = AppSettings() - let recipient = RoomMemberProxyMock.mockIgnored let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } @@ -265,8 +249,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func unignoreFailure() async throws { - let appSettings = AppSettings() - let recipient = RoomMemberProxyMock.mockIgnored let mockedMembers: [RoomMemberProxyMock] = [.mockMe, recipient] let clientProxy = ClientProxyMock(.init()) @@ -274,11 +256,11 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init(clientProxy: clientProxy)), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferredRecipient = deferFulfillment(viewModel.context.observe(\.viewState.dmRecipientInfo)) { $0 != nil } @@ -299,8 +281,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func cannotInvitePeople() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, @@ -308,11 +288,11 @@ struct RoomDetailsScreenViewModelTests { powerLevelsConfiguration: .init(canUserInvite: false))) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -321,17 +301,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func invitePeople() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -356,8 +334,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func canEditAvatar() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let configuration = JoinedRoomProxyMockConfiguration(name: "Test", @@ -381,11 +357,11 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -397,8 +373,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func canEditName() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let configuration = JoinedRoomProxyMockConfiguration(name: "Test", @@ -422,11 +396,11 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -438,8 +412,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func canEditTopic() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] let configuration = JoinedRoomProxyMockConfiguration(name: "Test", @@ -463,11 +435,11 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -479,17 +451,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func cannotEditRoom() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockBob, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -501,17 +471,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func cannotEditDirectRoom() async { - let appSettings = AppSettings() - let mockedMembers: [RoomMemberProxyMock] = [.mockMeAdmin, .mockBob, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()), attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) _ = await context.observe(\.viewState).debounce(for: .milliseconds(100)).first() @@ -522,16 +490,14 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func notificationLoadingSettingsFailure() async throws { - let appSettings = AppSettings() - notificationSettingsProxyMock.getNotificationSettingsRoomIdIsEncryptedIsOneToOneThrowableError = NotificationSettingsError.Generic(msg: "error") viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) var deferred = deferFulfillment(context.observe(\.viewState.notificationSettingsState)) { $0.isError } @@ -731,17 +697,15 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func knockRequestsCounter() async throws { - let appSettings = AppSettings() - let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState)) { state in state.knockRequestsCount == 2 && state.canSeeKnockingRequests @@ -755,16 +719,14 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func knockRequestsCounterIsLoading() async throws { - let appSettings = AppSettings() - roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loading, joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState)) { state in state.knockRequestsCount == 0 && state.canSeeKnockingRequests @@ -775,8 +737,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func knockRequestsCounterIsNotShownIfNoPermissions() async throws { - let appSettings = AppSettings() - let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, @@ -785,11 +745,11 @@ struct RoomDetailsScreenViewModelTests { powerLevelsConfiguration: .init(canUserInvite: false))) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState)) { state in state.knockRequestsCount == 2 && @@ -803,18 +763,16 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func knockRequestsCounterIsNotShownIfDM() async throws { - let appSettings = AppSettings() - let mockedRequests: [KnockRequestProxyMock] = [.init(), .init()] let mockedMembers: [RoomMemberProxyMock] = [.mockMe, .mockAlice] roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferred = deferFulfillment(context.observe(\.viewState)) { state in state.knockRequestsCount == 2 && @@ -830,8 +788,6 @@ struct RoomDetailsScreenViewModelTests { @Test mutating func historySharingPillDisplayed() async throws { - let appSettings = AppSettings() - let configuration = JoinedRoomProxyMockConfiguration(historyVisibility: .shared) let infoSubject = CurrentValueSubject(RoomInfoProxyMock(configuration)) let roomProxyMock = JoinedRoomProxyMock(configuration) @@ -839,11 +795,11 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationSettingsProxy: notificationSettingsProxyMock, attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()), - appSettings: appSettings) + appSettings: AppSettings()) let deferredShared = deferFulfillment(context.observe(\.viewState), message: "The pill should be shown for rooms with shared history visibility") { state in diff --git a/UnitTests/Sources/RoomFlowCoordinatorTests.swift b/UnitTests/Sources/RoomFlowCoordinatorTests.swift index 71d9add7a..24e8fbef6 100644 --- a/UnitTests/Sources/RoomFlowCoordinatorTests.swift +++ b/UnitTests/Sources/RoomFlowCoordinatorTests.swift @@ -490,7 +490,7 @@ final class RoomFlowCoordinatorTests { appMediator: AppMediatorMock.default, appSettings: appSettings, appHooks: AppHooks(), - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default, notificationManager: NotificationManagerMock(), stateMachineFactory: StateMachineFactory()) diff --git a/UnitTests/Sources/RoomMemberDetailsViewModelTests.swift b/UnitTests/Sources/RoomMemberDetailsViewModelTests.swift index cc66eb6f3..6a7b7db77 100644 --- a/UnitTests/Sources/RoomMemberDetailsViewModelTests.swift +++ b/UnitTests/Sources/RoomMemberDetailsViewModelTests.swift @@ -206,16 +206,13 @@ struct RoomMemberDetailsViewModelTests { .success(roomMemberProxyMock) } - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) - // swiftlint:disable:next force_unwrapping let userSession = clientProxy != nil ? UserSessionMock(.init(clientProxy: clientProxy!)) : UserSessionMock(.init()) viewModel = RoomMemberDetailsScreenViewModel(userID: roomMemberProxyMock.userID, roomProxy: roomProxyMock, userSession: userSession, userIndicatorController: UserIndicatorControllerMock.default, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) } } diff --git a/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift b/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift index 4136cf511..a7ab4340a 100644 --- a/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift +++ b/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift @@ -52,7 +52,6 @@ struct RoomMembersFlowCoordinatorTests { clientProxy.directRoomForUserIDReturnValue = .success(nil) let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), bugReportService: BugReportServiceMock(.init()), @@ -63,7 +62,7 @@ struct RoomMembersFlowCoordinatorTests { appMediator: AppMediatorMock.default, appSettings: appSettings, appHooks: AppHooks(), - analytics: analytics, + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), notificationManager: NotificationManagerMock(), stateMachineFactory: stateMachineFactory) diff --git a/UnitTests/Sources/RoomMembersListScreenViewModelTests.swift b/UnitTests/Sources/RoomMembersListScreenViewModelTests.swift index 98faab35e..44bf88b98 100644 --- a/UnitTests/Sources/RoomMembersListScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomMembersListScreenViewModelTests.swift @@ -278,7 +278,7 @@ struct RoomMembersListScreenViewModelTests { viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock.default, - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) let context = viewModel.context @@ -298,6 +298,6 @@ struct RoomMembersListScreenViewModelTests { viewModel = RoomMembersListScreenViewModel(userSession: UserSessionMock(.init()), roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock.default, - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/UnitTests/Sources/RoomRolesAndPermissionsScreenViewModelTests.swift b/UnitTests/Sources/RoomRolesAndPermissionsScreenViewModelTests.swift index c044b2026..83386f091 100644 --- a/UnitTests/Sources/RoomRolesAndPermissionsScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomRolesAndPermissionsScreenViewModelTests.swift @@ -84,6 +84,6 @@ struct RoomRolesAndPermissionsScreenViewModelTests { roomProxy = JoinedRoomProxyMock(.init(members: members)) viewModel = RoomRolesAndPermissionsScreenViewModel(roomProxy: roomProxy, userIndicatorController: UserIndicatorControllerMock(), - analytics: .mock()) + analytics: AnalyticsServiceMock.default()) } } diff --git a/UnitTests/Sources/RoomScreenViewModelTests.swift b/UnitTests/Sources/RoomScreenViewModelTests.swift index ea245f376..0dfa1030c 100644 --- a/UnitTests/Sources/RoomScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomScreenViewModelTests.swift @@ -50,7 +50,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -131,7 +131,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -192,7 +192,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -251,7 +251,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -288,7 +288,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: ongoingCallRoomIDSubject.asCurrentValuePublisher(), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel #expect(viewModel.state.shouldShowCallButton) @@ -333,7 +333,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel viewModel.stop() @@ -354,7 +354,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -388,7 +388,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -417,7 +417,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -437,7 +437,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel @@ -464,7 +464,7 @@ final class RoomScreenViewModelTests { ongoingCallRoomIDPublisher: .init(.init(nil)), appSettings: appSettings, appHooks: AppHooks(), - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock.default) self.viewModel = viewModel diff --git a/UnitTests/Sources/StartChatViewModelTests.swift b/UnitTests/Sources/StartChatViewModelTests.swift index 4257dcc23..f4dc92c28 100644 --- a/UnitTests/Sources/StartChatViewModelTests.swift +++ b/UnitTests/Sources/StartChatViewModelTests.swift @@ -27,7 +27,7 @@ struct StartChatScreenViewModelTests { userDiscoveryService.searchProfilesWithReturnValue = .success([]) let userSession = UserSessionMock(.init(clientProxy: clientProxy)) viewModel = StartChatScreenViewModel(userSession: userSession, - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: UserIndicatorControllerMock(), userDiscoveryService: userDiscoveryService, appSettings: appSettings) diff --git a/UnitTests/Sources/TimelineViewModelTests.swift b/UnitTests/Sources/TimelineViewModelTests.swift index 6a5f5e072..26bd2dfc5 100644 --- a/UnitTests/Sources/TimelineViewModelTests.swift +++ b/UnitTests/Sources/TimelineViewModelTests.swift @@ -316,7 +316,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -345,7 +345,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -372,7 +372,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -411,7 +411,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -450,7 +450,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -495,7 +495,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -526,7 +526,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) @@ -598,7 +598,7 @@ final class TimelineViewModelTests { userIndicatorController: UserIndicatorControllerMock.default, appMediator: AppMediatorMock.default, appSettings: appSettings, - analyticsService: .mock(settings: appSettings), + analyticsService: AnalyticsServiceMock.default(), emojiProvider: EmojiProvider(appSettings: appSettings), linkMetadataProvider: LinkMetadataProvider(), timelineControllerFactory: TimelineControllerFactoryMock(.init())) diff --git a/UnitTests/Sources/UserProfileScreenViewModelTests.swift b/UnitTests/Sources/UserProfileScreenViewModelTests.swift index acb6e23f2..39593acc2 100644 --- a/UnitTests/Sources/UserProfileScreenViewModelTests.swift +++ b/UnitTests/Sources/UserProfileScreenViewModelTests.swift @@ -13,8 +13,6 @@ import Testing struct UserProfileScreenViewModelTests { @Test func initialState() async throws { - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let profile = UserProfileProxy(userID: "@alice:matrix.org", displayName: "Alice", avatarURL: .mockMXCAvatar) @@ -25,8 +23,8 @@ struct UserProfileScreenViewModelTests { isPresentedModally: false, userSession: UserSessionMock(.init(clientProxy: clientProxy)), userIndicatorController: userIndicatorController, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) let context = viewModel.context let waitForMemberToLoad = deferFulfillment(context.observe(\.viewState.userProfile)) { $0 != nil } @@ -39,8 +37,6 @@ struct UserProfileScreenViewModelTests { @Test func initialStateAccountOwner() async throws { - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let profile = UserProfileProxy(userID: RoomMemberProxyMock.mockMe.userID, displayName: "Me", avatarURL: .mockMXCAvatar) @@ -51,8 +47,8 @@ struct UserProfileScreenViewModelTests { isPresentedModally: false, userSession: UserSessionMock(.init(clientProxy: clientProxy)), userIndicatorController: userIndicatorController, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) let context = viewModel.context let waitForMemberToLoad = deferFulfillment(context.observe(\.viewState.userProfile)) { $0 != nil } @@ -65,8 +61,6 @@ struct UserProfileScreenViewModelTests { @Test func startingDmWithUnknownUserFetchesIdentity() async throws { - let appSettings = AppSettings() - let analytics = AnalyticsService.mock(settings: appSettings) let userIndicatorController = UserIndicatorControllerMock.default let profile = UserProfileProxy.mockAlice @@ -79,8 +73,8 @@ struct UserProfileScreenViewModelTests { isPresentedModally: false, userSession: UserSessionMock(.init(clientProxy: clientProxy)), userIndicatorController: userIndicatorController, - analytics: analytics, - appSettings: appSettings) + analytics: AnalyticsServiceMock.default(), + appSettings: AppSettings()) let context = viewModel.context diff --git a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift index 7dad0fdb9..d862175d4 100644 --- a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift +++ b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift @@ -61,7 +61,7 @@ struct UserSessionFlowCoordinatorTests { appMediator: appMediator, appSettings: appSettings, appHooks: AppHooks(), - analytics: .mock(settings: appSettings), + analytics: AnalyticsServiceMock.default(), userIndicatorController: userIndicatorController, notificationManager: NotificationManagerMock(), stateMachineFactory: stateMachineFactory)