From 65bab49f39d363ede083affc129b6dc5c6517a06 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:20:00 +0100 Subject: [PATCH] Remove the CommonSettingsProtocol and use UserSession to carry multiple dependencies. (#6302) * Remove the CommonSettingsProtocol. * Replace multiple dependencies with the UserSession when it carries them. --- AGENTS.md | 5 ++- .../AppHooks/Hooks/RemoteSettingsHook.swift | 12 +++--- .../Sources/Application/AppCoordinator.swift | 1 - .../Application/FlowCoordinatorProtocol.swift | 1 - .../Application/Settings/AppSettings.swift | 20 --------- .../ChatsTabFlowCoordinator.swift | 1 - .../MediaEventsTimelineFlowCoordinator.swift | 1 - .../OnboardingFlowCoordinator.swift | 5 +-- .../PinnedEventsTimelineFlowCoordinator.swift | 9 ++-- .../RoomFlowCoordinator.swift | 31 ++++++-------- .../SettingsFlowCoordinator.swift | 26 ++++++------ .../SpaceFlowCoordinator.swift | 3 +- .../SpaceSettingsFlowCoordinator.swift | 6 +-- .../StartChatFlowCoordinator.swift | 1 - .../UserSessionFlowCoordinator.swift | 23 +++++----- .../Mocks/Generated/GeneratedMocks.swift | 12 +++--- ElementX/Sources/Mocks/UserSessionMock.swift | 3 +- .../CreateRoomScreenCoordinator.swift | 2 - .../CreateRoomScreenViewModel.swift | 5 +-- .../View/CreateRoomScreen.swift | 3 +- .../View/CreateRoomSpaceSelectionSheet.swift | 3 -- .../HomeScreen/HomeScreenCoordinator.swift | 2 - .../HomeScreen/HomeScreenViewModel.swift | 5 +-- .../Screens/HomeScreen/View/HomeScreen.swift | 1 - .../View/HomeScreenEmptyStateView.swift | 1 - .../View/HomeScreenInviteCell.swift | 1 - .../View/HomeScreenKnockedCell.swift | 1 - ...eScreenRecoveryKeyConfirmationBanner.swift | 1 - .../JoinRoomScreenCoordinator.swift | 2 - .../JoinRoomScreenViewModel.swift | 5 +-- .../JoinRoomScreen/View/JoinRoomScreen.swift | 3 -- .../LocationSharingScreenCoordinator.swift | 10 ++--- .../LocationSharingScreenViewModel.swift | 20 ++++----- ...MediaEventsTimelineScreenCoordinator.swift | 1 - ...SessionVerificationScreenCoordinator.swift | 6 +-- .../SessionVerificationScreenViewModel.swift | 7 ++-- .../View/SessionVerificationScreen.swift | 3 +- ...innedEventsTimelineScreenCoordinator.swift | 3 +- .../RoomDetailsScreenCoordinator.swift | 2 - .../RoomDetailsScreenViewModel.swift | 3 +- .../View/RoomDetailsScreen.swift | 3 -- .../SearchScreenCoordinator.swift | 10 ++--- .../SearchScreen/SearchScreenViewModel.swift | 12 +++--- .../SearchScreen/View/SearchScreen.swift | 37 ++++++---------- .../SecurityAndPrivacyScreenCoordinator.swift | 6 +-- .../SecurityAndPrivacyScreenViewModel.swift | 7 ++-- .../View/SecurityAndPrivacyScreen.swift | 42 +++++++------------ ...otificationSettingsScreenCoordinator.swift | 5 +-- .../SettingsScreenCoordinator.swift | 2 - .../SettingsScreenViewModel.swift | 4 +- .../SettingsScreen/View/SettingsScreen.swift | 10 ++--- .../View/SpaceSettingsScreen.swift | 1 - .../ThreadTimelineScreenCoordinator.swift | 5 +-- .../Services/Client/ClientFactory.swift | 6 +-- .../Client/ClientFactoryProtocol.swift | 2 +- .../UITests/UITestsAppCoordinator.swift | 7 +--- Enterprise | 2 +- .../CommonSettings+NotificationName.swift | 2 +- NSE/Sources/NSEUserSession.swift | 10 ++--- NSE/Sources/NotificationHandler.swift | 23 +++++----- .../NotificationServiceExtension.swift | 23 +++++----- .../ShareExtensionViewController.swift | 10 ++--- .../ChatsTabFlowCoordinatorTests.swift | 8 ++-- .../Sources/CreateRoomViewModelTests.swift | 6 +-- .../Sources/HomeScreenViewModelTests.swift | 3 +- .../JoinRoomScreenViewModelTests.swift | 3 +- .../LocationSharingScreenViewModelTests.swift | 22 ++++------ .../RoomDetailsScreenViewModelTests.swift | 22 ---------- .../Sources/RoomFlowCoordinatorTests.swift | 3 +- .../RoomMembersFlowCoordinatorTests.swift | 7 ++-- .../Sources/SearchScreenViewModelTests.swift | 6 +-- ...curityAndPrivacyScreenViewModelTests.swift | 9 ++-- .../SessionVerificationViewModelTests.swift | 3 +- .../SettingsScreenViewModelTests.swift | 3 +- .../UserSessionFlowCoordinatorTests.swift | 7 ++-- 75 files changed, 212 insertions(+), 369 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1f288f317..75d33b7e1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -273,7 +273,10 @@ Services = where product-level opinions live (Rust SDK stays spec-faithful). - Inject via `init` parameters. - Screen coordinators get `Parameters` struct with specific dependencies. - `CommonFlowParameters` flow-coordinator-only. -- `ServiceLocator` **deprecated** — never use services directly. Always inject from above. +- `UserSession` = per-account dependency container (`clientProxy`, `userSettings`, `mediaProvider`…). + - Need 2+ from it? Pass `userSession` down. Need 1? Pass that one direct. + - Receiver may store only pieces it need (e.g. `clientProxy`, `userSettings`). + - Never pass `userSession` plus value it already owns (e.g. `userSession` + `userSettings`). --- diff --git a/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift b/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift index 7bcb6bfdc..76ba60e1b 100644 --- a/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift +++ b/ElementX/Sources/AppHooks/Hooks/RemoteSettingsHook.swift @@ -15,11 +15,11 @@ enum RemoteSettingsError: Error { protocol RemoteSettingsHookProtocol: Sendable { #if IS_MAIN_APP - @MainActor func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result + @MainActor func initializeCache(using client: ClientProtocol, applyingTo appSettings: AppSettings) async -> Result func updateCache(using client: ClientProtocol) async - @MainActor func reset(_ appSettings: CommonSettingsProtocol) + @MainActor func reset(_ appSettings: AppSettings) #endif - @MainActor func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol) + @MainActor func loadCache(forHomeserver homeserver: String, applyingTo appSettings: AppSettings) } struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol { @@ -27,7 +27,7 @@ struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol { /// A best effort implementation to let Element X advertise to users when they should be using /// Element Pro. In an ideal world the backend would be able to validate the client's requests /// instead of relying on it to check a well-known file for this. - func initializeCache(using client: ClientProtocol, applyingTo appSettings: CommonSettingsProtocol) async -> Result { + func initializeCache(using client: ClientProtocol, applyingTo appSettings: AppSettings) async -> Result { guard case let .success(wellKnownData) = await client.elementWellKnown() else { // Nothing to check, carry on as normal. return .success(()) @@ -49,10 +49,10 @@ struct DefaultRemoteSettingsHook: RemoteSettingsHookProtocol { } func updateCache(using client: ClientProtocol) async { } - func reset(_ appSettings: any CommonSettingsProtocol) { } + func reset(_ appSettings: AppSettings) { } #endif - func loadCache(forHomeserver homeserver: String, applyingTo appSettings: CommonSettingsProtocol) { } + func loadCache(forHomeserver homeserver: String, applyingTo appSettings: AppSettings) { } } private struct ElementWellKnown: Decodable { diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 05e3e4f1e..10148177a 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -799,7 +799,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: appMediator, - userSettings: userSession.userSettings, // TODO: @pixlwave Remove this in favour of the userSession. appHooks: appHooks, analytics: analyticsService, userIndicatorController: userIndicatorController, diff --git a/ElementX/Sources/Application/FlowCoordinatorProtocol.swift b/ElementX/Sources/Application/FlowCoordinatorProtocol.swift index ca0929577..936c8b0b2 100644 --- a/ElementX/Sources/Application/FlowCoordinatorProtocol.swift +++ b/ElementX/Sources/Application/FlowCoordinatorProtocol.swift @@ -31,7 +31,6 @@ struct CommonFlowParameters { let emojiProvider: EmojiProviderProtocol let linkMetadataProvider: LinkMetadataProviderProtocol let appMediator: AppMediatorProtocol - let userSettings: UserSettings let appHooks: AppHooks let analytics: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol diff --git a/ElementX/Sources/Application/Settings/AppSettings.swift b/ElementX/Sources/Application/Settings/AppSettings.swift index 37262ad3b..e2290d800 100644 --- a/ElementX/Sources/Application/Settings/AppSettings.swift +++ b/ElementX/Sources/Application/Settings/AppSettings.swift @@ -15,24 +15,6 @@ import Foundation import Macros import SwiftUI -/// Common settings between app and NSE -nonisolated protocol CommonSettingsProtocol: AnyObject, Sendable { - var lastNotificationBootTime: TimeInterval? { get set } - var selectedNotificationTone: NotificationTone? { get set } - var lastKnownBadgeCount: Int { get set } - - var logLevel: LogLevel { get } - var traceLogPacks: Set { get } - var bugReportRageshakeURL: RemotePreference { get } - var contentScannerURL: RemotePreference { get } - var forceDisableE2EE: RemotePreference { get } - var mapTilerConfiguration: RemotePreference { get } - - var enableOnlySignedDeviceIsolationMode: Bool { get } - var threadsEnabled: Bool { get } - var hideQuietNotificationAlerts: Bool { get } -} - nonisolated enum AppBuildType { case debug case nightly @@ -475,5 +457,3 @@ final nonisolated class AppSettings: @unchecked Sendable { AppSettings(store: VolatileUserDefaults()) } } - -nonisolated extension AppSettings: CommonSettingsProtocol { } diff --git a/ElementX/Sources/FlowCoordinators/ChatsTabFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/ChatsTabFlowCoordinator.swift index 9c819da62..9c385f4a7 100644 --- a/ElementX/Sources/FlowCoordinators/ChatsTabFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/ChatsTabFlowCoordinator.swift @@ -377,7 +377,6 @@ class ChatsTabFlowCoordinator: FlowCoordinatorProtocol { let parameters = HomeScreenCoordinatorParameters(userSession: userSession, bugReportService: flowParameters.bugReportService, selectedRoomPublisher: selectedRoomSubject.asCurrentValuePublisher(), - userSettings: flowParameters.userSettings, analyticsService: flowParameters.analytics, notificationManager: flowParameters.notificationManager, userIndicatorController: flowParameters.userIndicatorController) diff --git a/ElementX/Sources/FlowCoordinators/MediaEventsTimelineFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/MediaEventsTimelineFlowCoordinator.swift index 4ffa0796d..42532d29b 100644 --- a/ElementX/Sources/FlowCoordinators/MediaEventsTimelineFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/MediaEventsTimelineFlowCoordinator.swift @@ -84,7 +84,6 @@ class MediaEventsTimelineFlowCoordinator: FlowCoordinatorProtocol { userSession: userSession, mediaPlayerProvider: MediaPlayerProvider(), appMediator: flowParameters.appMediator, - userSettings: flowParameters.userSettings, analytics: flowParameters.analytics, emojiProvider: flowParameters.emojiProvider, linkMetadataProvider: flowParameters.linkMetadataProvider, diff --git a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift index 2ccdddfbd..1014a980e 100644 --- a/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/OnboardingFlowCoordinator.swift @@ -69,7 +69,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol { self.appLockService = appLockService analyticsService = flowParameters.analytics appMediator = flowParameters.appMediator - userSettings = flowParameters.userSettings + userSettings = flowParameters.userSession.userSettings appHooks = flowParameters.appHooks notificationManager = flowParameters.notificationManager userIndicatorController = flowParameters.userIndicatorController @@ -281,8 +281,7 @@ class OnboardingFlowCoordinator: FlowCoordinatorProtocol { let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationController, flow: .deviceInitiator, - userSettings: userSettings, - mediaProvider: userSession.mediaProvider) + userSession: userSession) let coordinator = SessionVerificationScreenCoordinator(parameters: parameters) diff --git a/ElementX/Sources/FlowCoordinators/PinnedEventsTimelineFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/PinnedEventsTimelineFlowCoordinator.swift index 32d9d959d..139596cf9 100644 --- a/ElementX/Sources/FlowCoordinators/PinnedEventsTimelineFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/PinnedEventsTimelineFlowCoordinator.swift @@ -69,7 +69,6 @@ class PinnedEventsTimelineFlowCoordinator: FlowCoordinatorProtocol { userSession: userSession, mediaPlayerProvider: MediaPlayerProvider(), appMediator: flowParameters.appMediator, - userSettings: flowParameters.userSettings, analytics: flowParameters.analytics, emojiProvider: flowParameters.emojiProvider, linkMetadataProvider: flowParameters.linkMetadataProvider, @@ -107,15 +106,13 @@ class PinnedEventsTimelineFlowCoordinator: FlowCoordinatorProtocol { let stackCoordinator = NavigationStackCoordinator() let params = LocationSharingScreenCoordinatorParameters(interactionMode: interactionMode, - mapURLBuilder: flowParameters.userSettings.app.mapTilerConfiguration.publisher.value, + mapURLBuilder: userSession.userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: roomProxy, timelineController: timelineController, - liveLocationManager: flowParameters.userSession.liveLocationManager, - userSettings: flowParameters.userSettings, + userSession: userSession, appMediator: flowParameters.appMediator, analytics: flowParameters.analytics, - userIndicatorController: flowParameters.userIndicatorController, - mediaProvider: flowParameters.userSession.mediaProvider) + userIndicatorController: flowParameters.userIndicatorController) let coordinator = LocationSharingScreenCoordinator(parameters: params) coordinator.actions.sink { [weak self] action in diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index 996dfd061..1fe18f22f 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -238,7 +238,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { defer { hideLoadingIndicator() } switch await roomProxy.loadOrFetchEventDetails(for: eventID) { case .success(let event): - if flowParameters.userSettings.app.threadsEnabled, let threadRootEventID = event.threadRootEventId() { + if userSession.userSettings.app.threadsEnabled, let threadRootEventID = event.threadRootEventId() { if case .thread(threadRootEventID: threadRootEventID, _) = stateMachine.state, let threadCoordinator = childThreadScreenCoordinators.last { threadCoordinator.focusOnEvent(eventID: eventID) } else { @@ -318,7 +318,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { // Otherwise check if the focussed event exists to handle a possible error or theaded event. switch await roomProxy.loadOrFetchEventDetails(for: focusEvent.eventID) { case .success(let event): - if flowParameters.userSettings.app.threadsEnabled, let threadRootEventID = event.threadRootEventId() { + if userSession.userSettings.app.threadsEnabled, let threadRootEventID = event.threadRootEventId() { stateMachine.tryEvent(.presentRoom(presentationAction: .thread(rootEventID: threadRootEventID, focusEvent: .init(eventID: focusEvent.eventID, shouldSetPin: focusEvent.shouldSetPin))), @@ -798,7 +798,6 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { linkMetadataProvider: flowParameters.linkMetadataProvider, completionSuggestionService: completionSuggestionService, appMediator: flowParameters.appMediator, - userSettings: flowParameters.userSettings, analytics: flowParameters.analytics, composerDraftService: composerDraftService, timelineControllerFactory: flowParameters.timelineControllerFactory, @@ -855,8 +854,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { private func presentJoinRoomScreen(via: [String], animated: Bool) { let coordinator = JoinRoomScreenCoordinator(parameters: .init(source: .generic(roomID: roomID, via: via), userSession: userSession, - userIndicatorController: flowParameters.userIndicatorController, - userSettings: flowParameters.userSettings)) + userIndicatorController: flowParameters.userIndicatorController)) joinRoomScreenCoordinator = coordinator @@ -939,7 +937,6 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { private func presentRoomDetails(isRoot: Bool, animated: Bool) async { let params = RoomDetailsScreenCoordinatorParameters(roomProxy: roomProxy, userSession: userSession, - userSettings: flowParameters.userSettings, appHooks: flowParameters.appHooks, analyticsService: flowParameters.analytics, userIndicatorController: flowParameters.userIndicatorController, @@ -1019,7 +1016,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { let roomDetailsEditParameters = RoomDetailsEditScreenCoordinatorParameters(roomProxy: roomProxy, userSession: userSession, - mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: flowParameters.userSettings), + mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: userSession.userSettings), navigationStackCoordinator: stackCoordinator, userIndicatorController: flowParameters.userIndicatorController, orientationManager: flowParameters.appMediator.windowManager) @@ -1119,9 +1116,9 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { let parameters = MediaUploadPreviewScreenCoordinatorParameters(mediaURLs: mediaURLs, caption: caption, title: title, - shouldShowCaptionWarning: flowParameters.userSettings.app.shouldShowMediaCaptionWarning, - galleryEnabled: flowParameters.userSettings.app.galleryEnabled, - mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: flowParameters.userSettings), + shouldShowCaptionWarning: userSession.userSettings.app.shouldShowMediaCaptionWarning, + galleryEnabled: userSession.userSettings.app.galleryEnabled, + mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: userSession.userSettings), timelineController: timelineController, clientProxy: userSession.clientProxy, userIndicatorController: flowParameters.userIndicatorController) @@ -1176,15 +1173,13 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { let stackCoordinator = NavigationStackCoordinator() let params = LocationSharingScreenCoordinatorParameters(interactionMode: interactionMode, - mapURLBuilder: flowParameters.userSettings.app.mapTilerConfiguration.publisher.value, + mapURLBuilder: userSession.userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: roomProxy, timelineController: timelineController, - liveLocationManager: flowParameters.userSession.liveLocationManager, - userSettings: flowParameters.userSettings, + userSession: userSession, appMediator: flowParameters.appMediator, analytics: flowParameters.analytics, - userIndicatorController: flowParameters.userIndicatorController, - mediaProvider: flowParameters.userSession.mediaProvider) + userIndicatorController: flowParameters.userIndicatorController) let coordinator = LocationSharingScreenCoordinator(parameters: params) coordinator.actions.sink { [weak self] action in @@ -1324,8 +1319,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { userSession: userSession, userNotificationCenter: UNUserNotificationCenter.current(), userIndicatorController: flowParameters.userIndicatorController, - isModallyPresented: true, - userSettings: flowParameters.userSettings) + isModallyPresented: true) let coordinator = NotificationSettingsScreenCoordinator(parameters: parameters) coordinator.actions.sink { [weak self] action in switch action { @@ -1418,9 +1412,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { private func presentSecurityAndPrivacyScreen() { let coordinator = SecurityAndPrivacyScreenCoordinator(parameters: .init(roomProxy: roomProxy, - clientProxy: userSession.clientProxy, + userSession: userSession, userIndicatorController: flowParameters.userIndicatorController, - appSetting: flowParameters.userSettings, appHooks: flowParameters.appHooks)) coordinator.actionsPublisher.sink { [weak self] action in diff --git a/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift index a7ed0cafe..1df3020c4 100644 --- a/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift @@ -23,6 +23,10 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { private let navigationStackCoordinator: NavigationStackCoordinator private let flowParameters: CommonFlowParameters + private var userSettings: UserSettings { + flowParameters.userSession.userSettings + } + // periphery:ignore - retaining purpose private var appLockSetupFlowCoordinator: AppLockSetupFlowCoordinator? private var bugReportFlowCoordinator: BugReportFlowCoordinator? @@ -73,7 +77,6 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { private func presentSettingsScreen(animated: Bool) { let settingsScreenCoordinator = SettingsScreenCoordinator(parameters: .init(userSession: flowParameters.userSession, - userSettings: flowParameters.userSettings, isBugReportServiceEnabled: flowParameters.bugReportService.isEnabled, isInSecondaryWindow: isInSecondaryWindow, userIndicatorController: flowParameters.userIndicatorController)) @@ -139,7 +142,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { } private func presentLabs() { - let coordinator = LabsScreenCoordinator(parameters: .init(userSettings: flowParameters.userSettings)) + let coordinator = LabsScreenCoordinator(parameters: .init(userSettings: userSettings)) coordinator.actions .sink { [weak self] action in switch action { @@ -190,7 +193,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { private func presentUserDetailsEditScreen() { let coordinator = UserDetailsEditScreenCoordinator(parameters: .init(orientationManager: flowParameters.windowManager, userSession: flowParameters.userSession, - mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: flowParameters.userSettings), + mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: userSettings), navigationStackCoordinator: navigationStackCoordinator, userIndicatorController: flowParameters.userIndicatorController)) coordinator.actions @@ -234,7 +237,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { } private func presentAnalyticsScreen() { - let coordinator = AnalyticsSettingsScreenCoordinator(parameters: .init(userSettings: flowParameters.userSettings, + let coordinator = AnalyticsSettingsScreenCoordinator(parameters: .init(userSettings: userSettings, analytics: flowParameters.analytics)) navigationStackCoordinator.push(coordinator) } @@ -260,11 +263,11 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { } private func presentLegalInformationScreen() { - navigationStackCoordinator.push(LegalInformationScreenCoordinator(userSettings: flowParameters.userSettings)) + navigationStackCoordinator.push(LegalInformationScreenCoordinator(userSettings: userSettings)) } private func presentBlockedUsersScreen() { - let coordinator = BlockedUsersScreenCoordinator(parameters: .init(hideProfiles: flowParameters.userSettings.app.hideIgnoredUserProfiles, + let coordinator = BlockedUsersScreenCoordinator(parameters: .init(hideProfiles: userSettings.app.hideIgnoredUserProfiles, userSession: flowParameters.userSession, userIndicatorController: flowParameters.userIndicatorController)) navigationStackCoordinator.push(coordinator) @@ -275,8 +278,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { userSession: flowParameters.userSession, userNotificationCenter: UNUserNotificationCenter.current(), userIndicatorController: flowParameters.userIndicatorController, - isModallyPresented: false, - userSettings: flowParameters.userSettings) + isModallyPresented: false) let coordinator = NotificationSettingsScreenCoordinator(parameters: notificationParameters) navigationStackCoordinator.push(coordinator) } @@ -300,20 +302,20 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { } private func presentMediaUploadQualitySettings() { - let parameters = MediaUploadQualitySettingsScreenCoordinatorParameters(userSettings: flowParameters.userSettings, + let parameters = MediaUploadQualitySettingsScreenCoordinatorParameters(userSettings: userSettings, analytics: flowParameters.analytics) let coordinator = MediaUploadQualitySettingsScreenCoordinator(parameters: parameters) navigationStackCoordinator.push(coordinator) } private func presentLocationSharingSettings() { - let parameters = LocationSharingSettingsScreenCoordinatorParameters(userSettings: flowParameters.userSettings) + let parameters = LocationSharingSettingsScreenCoordinatorParameters(userSettings: userSettings) let coordinator = LocationSharingSettingsScreenCoordinator(parameters: parameters) navigationStackCoordinator.push(coordinator) } private func presentDeveloperOptions() { - let coordinator = DeveloperOptionsScreenCoordinator(appSettings: flowParameters.userSettings.app, + let coordinator = DeveloperOptionsScreenCoordinator(appSettings: userSettings.app, appHooks: flowParameters.appHooks, clientProxy: flowParameters.userSession.clientProxy) @@ -359,7 +361,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol { accountSettingsPresenter = OAuthAccountSettingsPresenter(accountURL: url, presentationAnchor: flowParameters.windowManager.mainWindow, appMediator: flowParameters.appMediator, - userSettings: flowParameters.userSettings, + userSettings: userSettings, appHooks: flowParameters.appHooks, continuation: continuation) accountSettingsPresenter?.start() diff --git a/ElementX/Sources/FlowCoordinators/SpaceFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/SpaceFlowCoordinator.swift index aa63e11fe..d1d7481ef 100644 --- a/ElementX/Sources/FlowCoordinators/SpaceFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/SpaceFlowCoordinator.swift @@ -399,8 +399,7 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol { let parameters = JoinRoomScreenCoordinatorParameters(source: .space(spaceServiceRoom), userSession: flowParameters.userSession, - userIndicatorController: flowParameters.userIndicatorController, - userSettings: flowParameters.userSettings) + userIndicatorController: flowParameters.userIndicatorController) let coordinator = JoinRoomScreenCoordinator(parameters: parameters) coordinator.actionsPublisher .sink { [weak self] action in diff --git a/ElementX/Sources/FlowCoordinators/SpaceSettingsFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/SpaceSettingsFlowCoordinator.swift index 84d250c2a..702756561 100644 --- a/ElementX/Sources/FlowCoordinators/SpaceSettingsFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/SpaceSettingsFlowCoordinator.swift @@ -211,7 +211,6 @@ final class SpaceSettingsFlowCoordinator: FlowCoordinatorProtocol { private func presentSpaceSettings(animated: Bool) { let coordinator = RoomDetailsScreenCoordinator(parameters: .init(roomProxy: roomProxy, userSession: flowParameters.userSession, - userSettings: flowParameters.userSettings, appHooks: flowParameters.appHooks, analyticsService: flowParameters.analytics, userIndicatorController: flowParameters.userIndicatorController, @@ -252,7 +251,7 @@ final class SpaceSettingsFlowCoordinator: FlowCoordinatorProtocol { let stackCoordinator = NavigationStackCoordinator() let parameters = RoomDetailsEditScreenCoordinatorParameters(roomProxy: roomProxy, userSession: flowParameters.userSession, - mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: flowParameters.userSettings), + mediaUploadingPreprocessor: MediaUploadingPreprocessor(userSettings: flowParameters.userSession.userSettings), navigationStackCoordinator: stackCoordinator, userIndicatorController: flowParameters.userIndicatorController, orientationManager: flowParameters.appMediator.windowManager) @@ -276,9 +275,8 @@ final class SpaceSettingsFlowCoordinator: FlowCoordinatorProtocol { private func presentSecurityAndPrivacyScreen() { let coordinator = SecurityAndPrivacyScreenCoordinator(parameters: .init(roomProxy: roomProxy, - clientProxy: flowParameters.userSession.clientProxy, + userSession: flowParameters.userSession, userIndicatorController: flowParameters.userIndicatorController, - appSetting: flowParameters.userSettings, appHooks: flowParameters.appHooks)) coordinator.actionsPublisher.sink { [weak self] action in diff --git a/ElementX/Sources/FlowCoordinators/StartChatFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/StartChatFlowCoordinator.swift index 8b26ad51e..2f1094660 100644 --- a/ElementX/Sources/FlowCoordinators/StartChatFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/StartChatFlowCoordinator.swift @@ -214,7 +214,6 @@ class StartChatFlowCoordinator: FlowCoordinatorProtocol { shouldShowCancelButton: isRoot, userSession: flowParameters.userSession, userIndicatorController: flowParameters.userIndicatorController, - userSettings: flowParameters.userSettings, analytics: flowParameters.analytics, appHooks: flowParameters.appHooks) let coordinator = CreateRoomScreenCoordinator(parameters: createParameters) diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index 308891c7f..e55ae1f45 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -82,29 +82,27 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { self.appLockService = appLockService self.flowParameters = flowParameters presenceService = PresenceService(clientProxy: flowParameters.userSession.clientProxy, - userSettings: flowParameters.userSettings) + userSettings: flowParameters.userSession.userSettings) navigationTabCoordinator = NavigationTabCoordinator() navigationRootCoordinator.setRootCoordinator(navigationTabCoordinator) - let chatsSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator(hideBrandChrome: flowParameters.userSettings.app.hideBrandChrome)) + let chatsSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator(hideBrandChrome: flowParameters.userSession.userSettings.app.hideBrandChrome)) chatsTabFlowCoordinator = ChatsTabFlowCoordinator(navigationSplitCoordinator: chatsSplitCoordinator, flowParameters: flowParameters) chatsTabDetails = .init(tag: HomeTab.chats, title: L10n.screenHomeTabChats, icon: \.chat, selectedIcon: \.chatSolid) chatsTabDetails.navigationSplitCoordinator = chatsSplitCoordinator - let spacesSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator(hideBrandChrome: flowParameters.userSettings.app.hideBrandChrome)) + let spacesSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator(hideBrandChrome: flowParameters.userSession.userSettings.app.hideBrandChrome)) spacesTabFlowCoordinator = SpacesTabFlowCoordinator(navigationSplitCoordinator: spacesSplitCoordinator, flowParameters: flowParameters) spacesTabDetails = .init(tag: HomeTab.spaces, title: L10n.screenHomeTabSpaces, icon: \.space, selectedIcon: \.spaceSolid) spacesTabDetails.navigationSplitCoordinator = spacesSplitCoordinator - if flowParameters.userSettings.app.globalSearchEnabled, #available(iOS 26.0, *) { + if flowParameters.userSession.userSettings.app.globalSearchEnabled, #available(iOS 26.0, *) { let searchCoordinator = SearchScreenCoordinator(parameters: .init(roomSummaryProvider: flowParameters.userSession.clientProxy.alternateRoomSummaryProvider, - clientProxy: flowParameters.userSession.clientProxy, - mediaProvider: flowParameters.userSession.mediaProvider, - userIndicatorController: flowParameters.userIndicatorController, - userSettings: flowParameters.userSettings)) + userSession: flowParameters.userSession, + userIndicatorController: flowParameters.userIndicatorController)) let searchStackCoordinator = NavigationStackCoordinator() searchStackCoordinator.setRootCoordinator(searchCoordinator) @@ -426,8 +424,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationController, flow: flow, - userSettings: flowParameters.userSettings, - mediaProvider: userSession.mediaProvider) + userSession: userSession) let coordinator = SessionVerificationScreenCoordinator(parameters: parameters) @@ -464,8 +461,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { presentCallScreen(configuration: .init(roomProxy: roomProxy, clientProxy: userSession.clientProxy, clientID: InfoPlistReader.main.bundleIdentifier, - elementCallBaseURL: flowParameters.userSettings.app.elementCallBaseURL, - elementCallBaseURLOverride: flowParameters.userSettings.app.elementCallBaseURLOverride, + elementCallBaseURL: userSession.userSettings.app.elementCallBaseURL, + elementCallBaseURLOverride: userSession.userSettings.app.elementCallBaseURLOverride, voiceOnly: voiceOnly, colorScheme: colorScheme)) } @@ -487,7 +484,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { let callScreenCoordinator = CallScreenCoordinator(parameters: .init(elementCallService: flowParameters.elementCallService, configuration: configuration, allowPictureInPicture: true, - userSettings: flowParameters.userSettings, + userSettings: userSession.userSettings, analytics: flowParameters.analytics)) callScreenCoordinator.actions diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index d0b4a4cef..2c0660d82 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -2357,14 +2357,14 @@ nonisolated class ClientFactoryMock: ClientFactoryProtocol, @unchecked Sendable return makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksCallsCount > 0 } private let makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedArgumentsLock = NSLock() - private nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedArguments: (credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: CommonSettingsProtocol, appHooks: AppHooks)? - var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedArguments: (credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: CommonSettingsProtocol, appHooks: AppHooks)? { + private nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedArguments: (credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: UserSettings, appHooks: AppHooks)? + var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedArguments: (credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: UserSettings, appHooks: AppHooks)? { get { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedArgumentsLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedArguments } } set { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedArgumentsLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedArguments = newValue } } } private let makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedInvocationsLock = NSLock() - private nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedInvocations: [(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: CommonSettingsProtocol, appHooks: AppHooks)] = [] - var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedInvocations: [(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: CommonSettingsProtocol, appHooks: AppHooks)] { + private nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedInvocations: [(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: UserSettings, appHooks: AppHooks)] = [] + var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedInvocations: [(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: UserSettings, appHooks: AppHooks)] { get { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedInvocationsLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedInvocations } } set { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReceivedInvocationsLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReceivedInvocations = newValue } } } @@ -2375,9 +2375,9 @@ nonisolated class ClientFactoryMock: ClientFactoryProtocol, @unchecked Sendable get { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReturnValueLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReturnValue } } set { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksReturnValueLock.withLock { makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksUnderlyingReturnValue = newValue } } } - nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksClosure: ((KeychainCredentials, String, ClientSessionDelegate, CommonSettingsProtocol, AppHooks) async throws -> ClientProtocol)? + nonisolated(unsafe) var makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksClosure: ((KeychainCredentials, String, ClientSessionDelegate, UserSettings, AppHooks) async throws -> ClientProtocol)? - @concurrent func makeNSEClient(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: CommonSettingsProtocol, appHooks: AppHooks) async throws -> ClientProtocol { + @concurrent func makeNSEClient(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, userSettings: UserSettings, appHooks: AppHooks) async throws -> ClientProtocol { if let error = makeNSEClientCredentialsRoomIDClientSessionDelegateUserSettingsAppHooksThrowableError { throw error } diff --git a/ElementX/Sources/Mocks/UserSessionMock.swift b/ElementX/Sources/Mocks/UserSessionMock.swift index 8518aa144..c18b50cae 100644 --- a/ElementX/Sources/Mocks/UserSessionMock.swift +++ b/ElementX/Sources/Mocks/UserSessionMock.swift @@ -13,6 +13,7 @@ struct UserSessionMockConfiguration { var clientProxy: ClientProxyProtocol = ClientProxyMock(.init()) var userSettings: UserSettings = .mock() var contentScannerService: ContentScannerServiceProtocol? + var liveLocationManager: LiveLocationManagerProtocol = LiveLocationManagerMock(.init()) } @MainActor extension UserSessionMock { @@ -28,6 +29,6 @@ struct UserSessionMockConfiguration { sessionSecurityStatePublisher = CurrentValueSubject(.init(verificationState: .verified, recoveryState: .enabled)).asCurrentValuePublisher() - liveLocationManager = LiveLocationManagerMock(.init()) + liveLocationManager = configuration.liveLocationManager } } diff --git a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift index f3fe00890..7e43a5eb3 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenCoordinator.swift @@ -15,7 +15,6 @@ struct CreateRoomScreenCoordinatorParameters { let shouldShowCancelButton: Bool let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol - let userSettings: UserSettings let analytics: AnalyticsServiceProtocol let appHooks: AppHooks } @@ -42,7 +41,6 @@ final class CreateRoomScreenCoordinator: CoordinatorProtocol { userSession: parameters.userSession, analytics: parameters.analytics, userIndicatorController: parameters.userIndicatorController, - userSettings: parameters.userSettings, appHooks: parameters.appHooks) } diff --git a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift index 323b421b5..c16f5e600 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/CreateRoomScreenViewModel.swift @@ -33,10 +33,9 @@ class CreateRoomScreenViewModel: CreateRoomScreenViewModelType, CreateRoomScreen userSession: UserSessionProtocol, analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol, - userSettings: UserSettings, appHooks: AppHooks) { self.userSession = userSession - mediaUploadingPreprocessor = MediaUploadingPreprocessor(userSettings: userSettings) + mediaUploadingPreprocessor = MediaUploadingPreprocessor(userSettings: userSession.userSettings) self.analytics = analytics self.userIndicatorController = userIndicatorController @@ -64,7 +63,7 @@ class CreateRoomScreenViewModel: CreateRoomScreenViewModelType, CreateRoomScreen shouldShowCancelButton: shouldShowCancelButton, roomName: "", serverName: userSession.clientProxy.userIDServerName ?? "", - isKnockingFeatureEnabled: userSettings.app.knockingEnabled, + isKnockingFeatureEnabled: userSession.userSettings.app.knockingEnabled, canSelectSpace: canSelectSpace, aliasLocalPart: roomAliasNameFromRoomDisplayName(roomName: ""), bindings: bindings) diff --git a/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomScreen.swift b/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomScreen.swift index 4fab4ee1b..98cf307bb 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomScreen.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomScreen.swift @@ -459,7 +459,7 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview { clientProxy.isAliasAvailableReturnValue = .success(isAliasAvailable) let spaces = [SpaceServiceRoom].mockJoinedSpaces2 clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: spaces)) - let userSession = UserSessionMock(.init(clientProxy: clientProxy)) + let userSession = UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)) return CreateRoomScreenViewModel(isSpace: isSpace, spaceSelectionMode: selectionMode, @@ -467,7 +467,6 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview { userSession: userSession, analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) } } diff --git a/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomSpaceSelectionSheet.swift b/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomSpaceSelectionSheet.swift index 43e12c563..c82d00289 100644 --- a/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomSpaceSelectionSheet.swift +++ b/ElementX/Sources/Screens/CreateRoomScreen/View/CreateRoomSpaceSelectionSheet.swift @@ -65,15 +65,12 @@ struct CreateRoomSpaceSelectionSheet_Previews: PreviewProvider, TestablePreview clientProxy.spaceService = SpaceServiceProxyMock(.init(editableSpaces: .mockJoinedSpaces2)) let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let userSettings = UserSettings.mock() - return CreateRoomScreenViewModel(isSpace: false, spaceSelectionMode: .editableSpacesList(preSelectedSpace: nil), shouldShowCancelButton: false, userSession: userSession, analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift index 70e904f8f..e9bfe4300 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift @@ -13,7 +13,6 @@ struct HomeScreenCoordinatorParameters { let userSession: UserSessionProtocol let bugReportService: BugReportServiceProtocol let selectedRoomPublisher: CurrentValuePublisher - let userSettings: UserSettings let analyticsService: AnalyticsServiceProtocol let notificationManager: NotificationManagerProtocol let userIndicatorController: UserIndicatorControllerProtocol @@ -50,7 +49,6 @@ final class HomeScreenCoordinator: CoordinatorProtocol { init(parameters: HomeScreenCoordinatorParameters) { viewModel = HomeScreenViewModel(userSession: parameters.userSession, selectedRoomPublisher: parameters.selectedRoomPublisher, - userSettings: parameters.userSettings, analyticsService: parameters.analyticsService, bugReportService: parameters.bugReportService, notificationManager: parameters.notificationManager, diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 8e2e325d3..9f84d29b8 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -32,7 +32,6 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol // swiftlint:disable:next function_body_length init(userSession: UserSessionProtocol, selectedRoomPublisher: CurrentValuePublisher, - userSettings: UserSettings, analyticsService: AnalyticsServiceProtocol, bugReportService: BugReportServiceProtocol, notificationManager: NotificationManagerProtocol, @@ -40,7 +39,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol self.userSession = userSession self.analyticsService = analyticsService self.bugReportService = bugReportService - self.userSettings = userSettings + userSettings = userSession.userSettings self.notificationManager = notificationManager self.userIndicatorController = userIndicatorController @@ -49,7 +48,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol roomSummaryProvider = userSession.clientProxy.roomSummaryProvider super.init(initialViewState: .init(userProfile: userSession.clientProxy.userProfilePublisher.value, - bindings: .init(filtersState: .init(userSettings: userSettings))), + bindings: .init(filtersState: .init(userSettings: userSession.userSettings))), mediaProvider: userSession.mediaProvider) if userSettings.app.globalSearchEnabled, #available(iOS 26.0, *) { diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index e68f4c32a..afa685a1e 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -237,7 +237,6 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview { return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: .mock(), analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: NotificationManagerMock(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift index dd7c40acf..b69c527fb 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift @@ -145,7 +145,6 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview { roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))))))) return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: .mock(), analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: NotificationManagerMock(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift index aafa02359..e6e5097d9 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift @@ -201,7 +201,6 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview { return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: .mock(), analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: NotificationManagerMock(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift index 35f1ebd37..9d056bd0b 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenKnockedCell.swift @@ -133,7 +133,6 @@ struct HomeScreenKnockedCell_Previews: PreviewProvider, TestablePreview { return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: .mock(), analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: NotificationManagerMock(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift index b0959d2b7..95b3629ea 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift @@ -122,7 +122,6 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab return HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: .mock(), analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: NotificationManagerMock(), diff --git a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenCoordinator.swift b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenCoordinator.swift index 7447741d9..9bc628ebc 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenCoordinator.swift @@ -13,7 +13,6 @@ struct JoinRoomScreenCoordinatorParameters { let source: JoinRoomScreenSource let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol - let userSettings: UserSettings } enum JoinRoomScreenSource { @@ -53,7 +52,6 @@ final class JoinRoomScreenCoordinator: CoordinatorProtocol { init(parameters: JoinRoomScreenCoordinatorParameters) { viewModel = JoinRoomScreenViewModel(source: parameters.source, - userSettings: parameters.userSettings, userSession: parameters.userSession, userIndicatorController: parameters.userIndicatorController) } diff --git a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift index 3a2d27615..acc8fc0fa 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift @@ -30,11 +30,10 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo } init(source: JoinRoomScreenSource, - userSettings: UserSettings, userSession: UserSessionProtocol, userIndicatorController: UserIndicatorControllerProtocol) { self.source = source - self.userSettings = userSettings + userSettings = userSession.userSettings clientProxy = userSession.clientProxy self.userIndicatorController = userIndicatorController @@ -49,7 +48,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo context.$viewState.map(\.mode) .removeDuplicates() - .sink { mode in + .sink { [userSettings = self.userSettings] mode in switch mode { case .invited: userSettings.app.seenInvites.insert(roomID) diff --git a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift index 7b85c1849..02940f891 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift @@ -402,8 +402,6 @@ struct JoinRoomScreenPreviewWrapper: Identifiable { self.isSpace = isSpace self.customPreviewName = customPreviewName - let userSettings = UserSettings.mock() - let clientProxy = ClientProxyMock(.init(hideInviteAvatars: hideInviteAvatars)) clientProxy.canJoinRoomWithReturnValue = canJoinRoom @@ -455,7 +453,6 @@ struct JoinRoomScreenPreviewWrapper: Identifiable { } viewModel = JoinRoomScreenViewModel(source: source, - userSettings: userSettings, userSession: UserSessionMock(.init(clientProxy: clientProxy)), userIndicatorController: UserIndicatorControllerMock()) } diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift index 305d54747..a0f3ef225 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenCoordinator.swift @@ -14,12 +14,10 @@ struct LocationSharingScreenCoordinatorParameters { let mapURLBuilder: MapTilerURLBuilderProtocol let roomProxy: JoinedRoomProxyProtocol let timelineController: TimelineControllerProtocol - let liveLocationManager: LiveLocationManagerProtocol - let userSettings: UserSettings + let userSession: UserSessionProtocol let appMediator: AppMediatorProtocol let analytics: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol - let mediaProvider: MediaProviderProtocol } enum LocationSharingScreenCoordinatorAction { @@ -44,11 +42,9 @@ final class LocationSharingScreenCoordinator: CoordinatorProtocol { mapURLBuilder: parameters.mapURLBuilder, roomProxy: parameters.roomProxy, timelineController: parameters.timelineController, - liveLocationManager: parameters.liveLocationManager, - userSettings: parameters.userSettings, + userSession: parameters.userSession, analytics: parameters.analytics, - userIndicatorController: parameters.userIndicatorController, - mediaProvider: parameters.mediaProvider) + userIndicatorController: parameters.userIndicatorController) } // MARK: - Public diff --git a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift index 3e97eb9ad..44a88e34c 100644 --- a/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift +++ b/ElementX/Sources/Screens/LocationSharing/LocationSharingScreenViewModel.swift @@ -36,16 +36,14 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati mapURLBuilder: MapTilerURLBuilderProtocol, roomProxy: JoinedRoomProxyProtocol, timelineController: TimelineControllerProtocol, - liveLocationManager: LiveLocationManagerProtocol, - userSettings: UserSettings, + userSession: UserSessionProtocol, analytics: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol, - mediaProvider: MediaProviderProtocol, notificationCenter: NotificationCenter = .default) { self.roomProxy = roomProxy self.timelineController = timelineController - self.liveLocationManager = liveLocationManager - self.userSettings = userSettings + liveLocationManager = userSession.liveLocationManager + userSettings = userSession.userSettings self.analytics = analytics self.userIndicatorController = userIndicatorController self.notificationCenter = notificationCenter @@ -53,7 +51,7 @@ class LocationSharingScreenViewModel: LocationSharingScreenViewModelType, Locati super.init(initialViewState: .init(interactionMode: interactionMode, mapURLBuilder: mapURLBuilder, ownUserID: roomProxy.ownUserID), - mediaProvider: mediaProvider) + mediaProvider: userSession.mediaProvider) updateUserProfiles(members: roomProxy.membersPublisher.value) setupSubscriptions() @@ -432,16 +430,14 @@ extension LocationSharingScreenViewModel { let roomProxy = JoinedRoomProxyMock(.init(members: .allMembers, ownUserID: RoomMemberProxyMock.mockMe.userID)) roomProxy.makeLiveLocationServiceReturnValue = liveLocationServiceMock - let userSettings = UserSettings.mock() + let userSession = UserSessionMock(.init()) return LocationSharingScreenViewModel(interactionMode: interactionMode, - mapURLBuilder: userSettings.app.mapTilerConfiguration.publisher.value, + mapURLBuilder: userSession.userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: roomProxy, timelineController: TimelineControllerMock(.init()), - liveLocationManager: LiveLocationManagerMock(), - userSettings: userSettings, + userSession: userSession, analytics: AnalyticsServiceMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - mediaProvider: MediaProviderMock(.init())) + userIndicatorController: UserIndicatorControllerMock()) } } diff --git a/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift b/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift index acb809315..8f98cfc78 100644 --- a/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift +++ b/ElementX/Sources/Screens/MediaEventsTimelineScreen/MediaEventsTimelineScreenCoordinator.swift @@ -16,7 +16,6 @@ struct MediaEventsTimelineScreenCoordinatorParameters { let userSession: UserSessionProtocol let mediaPlayerProvider: MediaPlayerProviderProtocol let appMediator: AppMediatorProtocol - let userSettings: UserSettings let analytics: AnalyticsServiceProtocol let emojiProvider: EmojiProviderProtocol let linkMetadataProvider: LinkMetadataProviderProtocol diff --git a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenCoordinator.swift b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenCoordinator.swift index b269fdd63..48c98320f 100644 --- a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenCoordinator.swift @@ -33,8 +33,7 @@ enum SessionVerificationScreenFlow { struct SessionVerificationScreenCoordinatorParameters { let sessionVerificationControllerProxy: SessionVerificationControllerProxyProtocol let flow: SessionVerificationScreenFlow - let userSettings: UserSettings - let mediaProvider: MediaProviderProtocol + let userSession: UserSessionProtocol } final class SessionVerificationScreenCoordinator: CoordinatorProtocol { @@ -50,8 +49,7 @@ final class SessionVerificationScreenCoordinator: CoordinatorProtocol { init(parameters: SessionVerificationScreenCoordinatorParameters) { viewModel = SessionVerificationScreenViewModel(sessionVerificationControllerProxy: parameters.sessionVerificationControllerProxy, flow: parameters.flow, - userSettings: parameters.userSettings, - mediaProvider: parameters.mediaProvider) + userSession: parameters.userSession) } // MARK: - Public diff --git a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenViewModel.swift b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenViewModel.swift index 185e7c8b4..31dc41a53 100644 --- a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenViewModel.swift +++ b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/SessionVerificationScreenViewModel.swift @@ -25,8 +25,7 @@ class SessionVerificationScreenViewModel: SessionVerificationViewModelType, Sess init(sessionVerificationControllerProxy: SessionVerificationControllerProxyProtocol, flow: SessionVerificationScreenFlow, - userSettings: UserSettings, - mediaProvider: MediaProviderProtocol, + userSession: UserSessionProtocol, verificationState: SessionVerificationScreenStateMachine.State = .initial) { self.sessionVerificationControllerProxy = sessionVerificationControllerProxy self.flow = flow @@ -34,9 +33,9 @@ class SessionVerificationScreenViewModel: SessionVerificationViewModelType, Sess stateMachine = SessionVerificationScreenStateMachine(state: verificationState) super.init(initialViewState: .init(flow: flow, - learnMoreURL: userSettings.app.encryptionURL, + learnMoreURL: userSession.userSettings.app.encryptionURL, verificationState: verificationState), - mediaProvider: mediaProvider) + mediaProvider: userSession.mediaProvider) setupStateMachine() diff --git a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/View/SessionVerificationScreen.swift b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/View/SessionVerificationScreen.swift index 788822e80..3bbdfa6f3 100644 --- a/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/View/SessionVerificationScreen.swift +++ b/ElementX/Sources/Screens/Onboarding/SessionVerificationScreen/View/SessionVerificationScreen.swift @@ -289,8 +289,7 @@ struct SessionVerification_Previews: PreviewProvider, TestablePreview { flow: SessionVerificationScreenFlow = .deviceInitiator) -> some View { let viewModel = SessionVerificationScreenViewModel(sessionVerificationControllerProxy: SessionVerificationControllerProxyMock.configureMock(), flow: flow, - userSettings: .mock(), - mediaProvider: MediaProviderMock(.init()), + userSession: UserSessionMock(.init()), verificationState: state) return SessionVerificationScreen(context: viewModel.context) diff --git a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift index aa9d4418e..dc6a6d8cb 100644 --- a/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift +++ b/ElementX/Sources/Screens/PinnedEventsTimelineScreen/PinnedEventsTimelineScreenCoordinator.swift @@ -15,7 +15,6 @@ struct PinnedEventsTimelineScreenCoordinatorParameters { let userSession: UserSessionProtocol let mediaPlayerProvider: MediaPlayerProviderProtocol let appMediator: AppMediatorProtocol - let userSettings: UserSettings let analytics: AnalyticsServiceProtocol let emojiProvider: EmojiProviderProtocol let linkMetadataProvider: LinkMetadataProviderProtocol @@ -46,7 +45,7 @@ final class PinnedEventsTimelineScreenCoordinator: CoordinatorProtocol { init(parameters: PinnedEventsTimelineScreenCoordinatorParameters) { viewModel = PinnedEventsTimelineScreenViewModel(roomProxy: parameters.roomProxy, userIndicatorController: parameters.userIndicatorController, - userSettings: parameters.userSettings, + userSettings: parameters.userSession.userSettings, analyticsService: parameters.analytics) timelineViewModel = TimelineViewModel(roomProxy: parameters.roomProxy, timelineController: parameters.timelineController, diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift index b03307008..16774e69e 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenCoordinator.swift @@ -12,7 +12,6 @@ import SwiftUI struct RoomDetailsScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol let userSession: UserSessionProtocol - let userSettings: UserSettings let appHooks: AppHooks let analyticsService: AnalyticsServiceProtocol let userIndicatorController: UserIndicatorControllerProtocol @@ -54,7 +53,6 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol { isSpace = parameters.roomProxy.infoPublisher.value.isSpace viewModel = RoomDetailsScreenViewModel(roomProxy: parameters.roomProxy, userSession: parameters.userSession, - userSettings: parameters.userSettings, appHooks: parameters.appHooks, analyticsService: parameters.analyticsService, userIndicatorController: parameters.userIndicatorController, diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift index e5cc5a961..737bfa1e4 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/RoomDetailsScreenViewModel.swift @@ -45,7 +45,6 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr init(roomProxy: JoinedRoomProxyProtocol, userSession: UserSessionProtocol, - userSettings: UserSettings, appHooks: AppHooks, analyticsService: AnalyticsServiceProtocol, userIndicatorController: UserIndicatorControllerProtocol, @@ -68,7 +67,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr topicSummary: topic?.unattributedStringByReplacingNewlinesWithSpaces(), joinedMembersCount: roomProxy.infoPublisher.value.joinedMembersCount, notificationSettingsState: .loading, - isNativeCallingEnabled: userSettings.app.nativeCallEnabled, + isNativeCallingEnabled: userSession.userSettings.app.nativeCallEnabled, bindings: .init()) super.init(initialViewState: appHooks.roomDetailsScreenHook.update(viewState), mediaProvider: userSession.mediaProvider) diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift index ad28c803c..deab8f0ef 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift @@ -445,7 +445,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { return .init(roomProxy: roomProxy, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -474,7 +473,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { return .init(roomProxy: roomProxy, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -513,7 +511,6 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview { return .init(roomProxy: roomProxy, userSession: UserSessionMock(.init(clientProxy: clientProxyMock)), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/ElementX/Sources/Screens/SearchScreen/SearchScreenCoordinator.swift b/ElementX/Sources/Screens/SearchScreen/SearchScreenCoordinator.swift index d8ff736d4..0ed043a1d 100644 --- a/ElementX/Sources/Screens/SearchScreen/SearchScreenCoordinator.swift +++ b/ElementX/Sources/Screens/SearchScreen/SearchScreenCoordinator.swift @@ -10,10 +10,8 @@ import SwiftUI struct SearchScreenCoordinatorParameters { let roomSummaryProvider: RoomSummaryProviderProtocol - let clientProxy: ClientProxyProtocol - let mediaProvider: MediaProviderProtocol + let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol - let userSettings: UserSettings } enum SearchScreenCoordinatorAction { @@ -33,10 +31,8 @@ final class SearchScreenCoordinator: CoordinatorProtocol { init(parameters: SearchScreenCoordinatorParameters) { viewModel = SearchScreenViewModel(roomSummaryProvider: parameters.roomSummaryProvider, - clientProxy: parameters.clientProxy, - mediaProvider: parameters.mediaProvider, - userIndicatorController: parameters.userIndicatorController, - userSettings: parameters.userSettings) + userSession: parameters.userSession, + userIndicatorController: parameters.userIndicatorController) } func start() { diff --git a/ElementX/Sources/Screens/SearchScreen/SearchScreenViewModel.swift b/ElementX/Sources/Screens/SearchScreen/SearchScreenViewModel.swift index a361176a8..74907ada3 100644 --- a/ElementX/Sources/Screens/SearchScreen/SearchScreenViewModel.swift +++ b/ElementX/Sources/Screens/SearchScreen/SearchScreenViewModel.swift @@ -33,20 +33,18 @@ class SearchScreenViewModel: SearchScreenViewModelType, SearchScreenViewModelPro } init(roomSummaryProvider: RoomSummaryProviderProtocol, - clientProxy: ClientProxyProtocol, - mediaProvider: MediaProviderProtocol, + userSession: UserSessionProtocol, userIndicatorController: UserIndicatorControllerProtocol, - userSettings: UserSettings, initialSearchQuery: String = "", initialSearchMode: SearchScreenMode = .rooms) { self.roomSummaryProvider = roomSummaryProvider - self.clientProxy = clientProxy - searchService = clientProxy.searchService + clientProxy = userSession.clientProxy + searchService = userSession.clientProxy.searchService self.userIndicatorController = userIndicatorController - self.userSettings = userSettings + userSettings = userSession.userSettings super.init(initialViewState: SearchScreenViewState(bindings: .init(searchQuery: initialSearchQuery, searchMode: initialSearchMode)), - mediaProvider: mediaProvider) + mediaProvider: userSession.mediaProvider) roomSummaryProvider.roomListPublisher .receive(on: DispatchQueue.main) diff --git a/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift b/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift index 414b089d1..2e54d79e8 100644 --- a/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift +++ b/ElementX/Sources/Screens/SearchScreen/View/SearchScreen.swift @@ -626,46 +626,35 @@ private final class KeyNavigatingSearchTextField: UISearchTextField { struct SearchScreen_Previews: PreviewProvider, TestablePreview { static let emptyViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))), - clientProxy: makeClientProxy(), - mediaProvider: MediaProviderMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - userSettings: UserSettings.mock()) + userSession: UserSessionMock(.init(clientProxy: makeClientProxy())), + userIndicatorController: UserIndicatorControllerMock()) static let noResultsViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))), - clientProxy: makeClientProxy(), - mediaProvider: MediaProviderMock(.init()), + userSession: UserSessionMock(.init(clientProxy: makeClientProxy())), userIndicatorController: UserIndicatorControllerMock(), - userSettings: UserSettings.mock(), initialSearchQuery: "John Doe") static let roomsViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), - clientProxy: makeClientProxy(), - mediaProvider: MediaProviderMock(.init()), + userSession: UserSessionMock(.init(clientProxy: makeClientProxy())), userIndicatorController: UserIndicatorControllerMock(), - userSettings: UserSettings.mock(), initialSearchQuery: "Foundation") static let messagesViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))), - clientProxy: makeClientProxy(searchService: makeSearchService(results: .mockResults)), - mediaProvider: MediaProviderMock(.init()), + userSession: UserSessionMock(.init(clientProxy: makeClientProxy(searchService: makeSearchService(results: .mockResults)))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: UserSettings.mock(), initialSearchQuery: "Foundation", initialSearchMode: .messages) static let loadingMessagesViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))), - clientProxy: makeClientProxy(searchService: makeSearchService(paginationState: .loading)), - mediaProvider: MediaProviderMock(.init()), + userSession: UserSessionMock(.init(clientProxy: makeClientProxy(searchService: makeSearchService(paginationState: .loading)))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: UserSettings.mock(), initialSearchQuery: "Foundation", initialSearchMode: .messages) static let breadcrumbsViewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))), - clientProxy: makeClientProxy(), - mediaProvider: MediaProviderMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - userSettings: makeUserSettings(breadcrumbs: [.room(roomID: "!room1:matrix.org"), - .query("Bob"), - .room(roomID: "!room5:matrix.org"), - .query("Element HR"), - .query("Alice")])) + userSession: UserSessionMock(.init(clientProxy: makeClientProxy(), + userSettings: makeUserSettings(breadcrumbs: [.room(roomID: "!room1:matrix.org"), + .query("Bob"), + .room(roomID: "!room5:matrix.org"), + .query("Element HR"), + .query("Alice")]))), + userIndicatorController: UserIndicatorControllerMock()) static var previews: some View { ElementNavigationStack { diff --git a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenCoordinator.swift b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenCoordinator.swift index 7d9947b2c..9a72fd795 100644 --- a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenCoordinator.swift +++ b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenCoordinator.swift @@ -11,9 +11,8 @@ import SwiftUI struct SecurityAndPrivacyScreenCoordinatorParameters { let roomProxy: JoinedRoomProxyProtocol - let clientProxy: ClientProxyProtocol + let userSession: UserSessionProtocol let userIndicatorController: UserIndicatorControllerProtocol - let appSetting: UserSettings let appHooks: AppHooks } @@ -35,9 +34,8 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol { init(parameters: SecurityAndPrivacyScreenCoordinatorParameters) { viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy, - clientProxy: parameters.clientProxy, + userSession: parameters.userSession, userIndicatorController: parameters.userIndicatorController, - userSettings: parameters.appSetting, appHooks: parameters.appHooks) } diff --git a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModel.swift b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModel.swift index 72eabd104..fcc6eda01 100644 --- a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModel.swift +++ b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/SecurityAndPrivacyScreenViewModel.swift @@ -24,14 +24,13 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType, } init(roomProxy: JoinedRoomProxyProtocol, - clientProxy: ClientProxyProtocol, + userSession: UserSessionProtocol, userIndicatorController: UserIndicatorControllerProtocol, - userSettings: UserSettings, appHooks: AppHooks) { self.roomProxy = roomProxy - self.clientProxy = clientProxy + clientProxy = userSession.clientProxy self.userIndicatorController = userIndicatorController - self.userSettings = userSettings + userSettings = userSession.userSettings let viewState = SecurityAndPrivacyScreenViewState(accessType: roomProxy.infoPublisher.value.joinRule.toSecurityAndPrivacyRoomAccessType, isEncryptionEnabled: roomProxy.infoPublisher.value.isEncrypted, diff --git a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/View/SecurityAndPrivacyScreen.swift b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/View/SecurityAndPrivacyScreen.swift index 5bc46139c..5d792b384 100644 --- a/ElementX/Sources/Screens/SecurityAndPrivacyScreen/View/SecurityAndPrivacyScreen.swift +++ b/ElementX/Sources/Screens/SecurityAndPrivacyScreen/View/SecurityAndPrivacyScreen.swift @@ -233,9 +233,8 @@ struct SecurityAndPrivacyScreen: View { struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { static let inviteOnlyViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(members: .allMembersAsCreator, joinRule: .invite)), - clientProxy: ClientProxyMock(.init()), + userSession: UserSessionMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - userSettings: .mock(), appHooks: AppHooks()) static let publicViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false, @@ -243,22 +242,18 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .public, isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: .mock(), appHooks: AppHooks()) static let publicNoAddressViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false, members: .allMembersAsCreator, joinRule: .public)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: .mock(), appHooks: AppHooks()) static let singleSpaceMembersViewModel = { - let userSettings = UserSettings.mock() - let space = [SpaceServiceRoom].mockSingleRoom[0] return SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false, @@ -266,16 +261,13 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .restricted(rules: [.roomMembership(roomID: space.id)]), isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(joinedParentSpaces: [space]))), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", + spaceServiceConfiguration: .init(joinedParentSpaces: [space]))))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() static let multipleSpacesMembersViewModel = { - let userSettings = UserSettings.mock() - let spaces = [SpaceServiceRoom].mockJoinedSpaces return SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false, @@ -283,10 +275,9 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .restricted(rules: spaces.map { .roomMembership(roomID: $0.id) }), isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(joinedParentSpaces: spaces))), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", + spaceServiceConfiguration: .init(joinedParentSpaces: spaces))))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() @@ -299,9 +290,9 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .knock, isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")), + userSettings: userSettings)), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() @@ -316,10 +307,10 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .knockRestricted(rules: [.roomMembership(roomID: space.id)]), isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(joinedParentSpaces: [space]))), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", + spaceServiceConfiguration: .init(joinedParentSpaces: [space]))), + userSettings: userSettings)), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() @@ -334,10 +325,10 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .knockRestricted(rules: spaces.map { .roomMembership(roomID: $0.id) }), isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(joinedParentSpaces: spaces))), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", + spaceServiceConfiguration: .init(joinedParentSpaces: spaces))), + userSettings: userSettings)), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) }() @@ -347,9 +338,8 @@ struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview { members: .allMembersAsCreator, joinRule: .public, isVisibleInPublicDirectory: true)), - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")), + userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")))), userIndicatorController: UserIndicatorControllerMock(), - userSettings: .mock(), appHooks: AppHooks()) static var previews: some View { diff --git a/ElementX/Sources/Screens/Settings/NotificationSettingsScreen/NotificationSettingsScreenCoordinator.swift b/ElementX/Sources/Screens/Settings/NotificationSettingsScreen/NotificationSettingsScreenCoordinator.swift index fdcf43959..5873307be 100644 --- a/ElementX/Sources/Screens/Settings/NotificationSettingsScreen/NotificationSettingsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/NotificationSettingsScreen/NotificationSettingsScreenCoordinator.swift @@ -15,7 +15,6 @@ struct NotificationSettingsScreenCoordinatorParameters { let userNotificationCenter: UserNotificationCenterProtocol let userIndicatorController: UserIndicatorControllerProtocol let isModallyPresented: Bool - let userSettings: UserSettings } enum NotificationSettingsScreenCoordinatorAction { @@ -39,9 +38,9 @@ final class NotificationSettingsScreenCoordinator: CoordinatorProtocol { init(parameters: NotificationSettingsScreenCoordinatorParameters) { self.parameters = parameters - viewModel = NotificationSettingsScreenViewModel(userSettings: parameters.userSettings, + viewModel = NotificationSettingsScreenViewModel(userSettings: parameters.userSession.userSettings, userNotificationCenter: parameters.userNotificationCenter, - notificationToneManager: NotificationToneManager(userSettings: parameters.userSettings), + notificationToneManager: NotificationToneManager(userSettings: parameters.userSession.userSettings), notificationSettingsProxy: parameters.userSession.clientProxy.notificationSettings, userIndicatorController: parameters.userIndicatorController, isModallyPresented: parameters.isModallyPresented) diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenCoordinator.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenCoordinator.swift index 622d116a8..0f0b99669 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenCoordinator.swift @@ -11,7 +11,6 @@ import SwiftUI struct SettingsScreenCoordinatorParameters { let userSession: UserSessionProtocol - let userSettings: UserSettings let isBugReportServiceEnabled: Bool let isInSecondaryWindow: Bool let userIndicatorController: UserIndicatorControllerProtocol @@ -59,7 +58,6 @@ final class SettingsScreenCoordinator: CoordinatorProtocol { init(parameters: SettingsScreenCoordinatorParameters) { viewModel = SettingsScreenViewModel(userSession: parameters.userSession, - userSettings: parameters.userSettings, isBugReportServiceEnabled: parameters.isBugReportServiceEnabled, isInSecondaryWindow: parameters.isInSecondaryWindow, userIndicatorController: parameters.userIndicatorController) diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift index 9d410ade5..540cbdcf8 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift @@ -22,8 +22,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo actionsSubject.eraseToAnyPublisher() } - init(userSession: UserSessionProtocol, userSettings: UserSettings, isBugReportServiceEnabled: Bool, isInSecondaryWindow: Bool, userIndicatorController: UserIndicatorControllerProtocol) { - self.userSettings = userSettings + init(userSession: UserSessionProtocol, isBugReportServiceEnabled: Bool, isInSecondaryWindow: Bool, userIndicatorController: UserIndicatorControllerProtocol) { + userSettings = userSession.userSettings clientProxy = userSession.clientProxy self.userIndicatorController = userIndicatorController diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift index fe3138d4f..da1f8600b 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift @@ -313,15 +313,15 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview { } static func makeViewModel(isBugReportServiceEnabled: Bool = true) -> SettingsScreenViewModel { - let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com", - deviceID: "AAAAAAAAAAA", - displayName: "Alice Liddell", - status: .mockFocussing)))) let userSettings = UserSettings.mock() userSettings.app.multiAccountEnabled = true userSettings.app.linkNewDeviceEnabled = true + let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com", + deviceID: "AAAAAAAAAAA", + displayName: "Alice Liddell", + status: .mockFocussing)), + userSettings: userSettings)) return SettingsScreenViewModel(userSession: userSession, - userSettings: userSettings, isBugReportServiceEnabled: isBugReportServiceEnabled, isInSecondaryWindow: false, userIndicatorController: UserIndicatorControllerMock()) diff --git a/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift b/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift index f39301a97..0a864ab1d 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceSettingsScreen/View/SpaceSettingsScreen.swift @@ -132,7 +132,6 @@ struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview { canonicalAlias: "#space:matrix.org", members: members)), userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/ElementX/Sources/Screens/ThreadTimelineScreen/ThreadTimelineScreenCoordinator.swift b/ElementX/Sources/Screens/ThreadTimelineScreen/ThreadTimelineScreenCoordinator.swift index 042d09a47..7f3c17676 100644 --- a/ElementX/Sources/Screens/ThreadTimelineScreen/ThreadTimelineScreenCoordinator.swift +++ b/ElementX/Sources/Screens/ThreadTimelineScreen/ThreadTimelineScreenCoordinator.swift @@ -21,7 +21,6 @@ struct ThreadTimelineScreenCoordinatorParameters { let linkMetadataProvider: LinkMetadataProviderProtocol let completionSuggestionService: CompletionSuggestionServiceProtocol let appMediator: AppMediatorProtocol - let userSettings: UserSettings let analytics: AnalyticsServiceProtocol let composerDraftService: ComposerDraftServiceProtocol let timelineControllerFactory: TimelineControllerFactoryProtocol @@ -56,7 +55,7 @@ final class ThreadTimelineScreenCoordinator: CoordinatorProtocol { } init(parameters: ThreadTimelineScreenCoordinatorParameters) { - userSettings = parameters.userSettings + userSettings = parameters.userSession.userSettings viewModel = ThreadTimelineScreenViewModel(roomProxy: parameters.roomProxy, userSession: parameters.userSession) @@ -83,7 +82,7 @@ final class ThreadTimelineScreenCoordinator: CoordinatorProtocol { completionSuggestionService: parameters.completionSuggestionService, mediaProvider: parameters.userSession.mediaProvider, mentionDisplayHelper: ComposerMentionDisplayHelper(timelineContext: timelineViewModel.context), - userSettings: parameters.userSettings, + userSettings: parameters.userSession.userSettings, analyticsService: parameters.analytics, composerDraftService: parameters.composerDraftService) } diff --git a/ElementX/Sources/Services/Client/ClientFactory.swift b/ElementX/Sources/Services/Client/ClientFactory.swift index 942a86956..5743398fe 100644 --- a/ElementX/Sources/Services/Client/ClientFactory.swift +++ b/ElementX/Sources/Services/Client/ClientFactory.swift @@ -81,7 +81,7 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { func makeNSEClient(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, - userSettings: CommonSettingsProtocol, + userSettings: UserSettings, appHooks: AppHooks) async throws -> ClientProtocol { let homeserverURL = credentials.restorationToken.session.homeserverUrl @@ -90,10 +90,10 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { discoverSlidingSync: false, sessionDelegate: clientSessionDelegate, appHooks: appHooks, - enableOnlySignedDeviceIsolationMode: userSettings.enableOnlySignedDeviceIsolationMode, + enableOnlySignedDeviceIsolationMode: userSettings.app.enableOnlySignedDeviceIsolationMode, requestTimeout: 15000, maxRequestRetryTime: 5000, - threadsEnabled: userSettings.threadsEnabled) + threadsEnabled: userSettings.app.threadsEnabled) .systemIsMemoryConstrained() .sqliteStore(config: .init(dataPath: credentials.restorationToken.sessionDirectories.dataPath, cachePath: credentials.restorationToken.sessionDirectories.cachePath) diff --git a/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift b/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift index 59d430963..550d0dcd5 100644 --- a/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift @@ -36,6 +36,6 @@ nonisolated protocol ClientFactoryProtocol { func makeNSEClient(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, - userSettings: CommonSettingsProtocol, + userSettings: UserSettings, appHooks: AppHooks) async throws -> ClientProtocol } diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index 081fca962..4cb577993 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -597,8 +597,7 @@ class MockScreen: Identifiable { requestDelay: .seconds(5)) let parameters = SessionVerificationScreenCoordinatorParameters(sessionVerificationControllerProxy: sessionVerificationControllerProxy, flow: .deviceInitiator, - userSettings: .mock(), - mediaProvider: MediaProviderMock(.init())) + userSession: UserSessionMock(.init())) return SessionVerificationScreenCoordinator(parameters: parameters) case .userSessionScreen, .userSessionScreenReply, .userSessionSpacesFlow: let userID = "@mock:client.com" @@ -647,7 +646,6 @@ class MockScreen: Identifiable { emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: appMediator, - userSettings: userSession.userSettings, appHooks: AppHooks(), analytics: analytics, userIndicatorController: UserIndicatorControllerMock(), @@ -700,7 +698,6 @@ class MockScreen: Identifiable { emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSession.userSettings, appHooks: AppHooks(), analytics: analytics, userIndicatorController: UserIndicatorControllerMock(), @@ -801,7 +798,6 @@ class MockScreen: Identifiable { emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSession.userSettings, appHooks: AppHooks(), analytics: analytics, userIndicatorController: UserIndicatorControllerMock(), @@ -858,7 +854,6 @@ class MockScreen: Identifiable { emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSession.userSettings, appHooks: AppHooks(), analytics: analytics, userIndicatorController: UserIndicatorControllerMock(), diff --git a/Enterprise b/Enterprise index 5792d2c63..8ff9415f2 160000 --- a/Enterprise +++ b/Enterprise @@ -1 +1 @@ -Subproject commit 5792d2c63df5f3f9d2d465148db4360d8591c638 +Subproject commit 8ff9415f262e66cf530b63a6415d74b6ea080242 diff --git a/NSE/Sources/CommonSettings+NotificationName.swift b/NSE/Sources/CommonSettings+NotificationName.swift index 41d427c0f..ec3a4c9a2 100644 --- a/NSE/Sources/CommonSettings+NotificationName.swift +++ b/NSE/Sources/CommonSettings+NotificationName.swift @@ -7,7 +7,7 @@ import UserNotifications -nonisolated extension CommonSettingsProtocol { +nonisolated extension AppSettings { /// The sound name to use in outgoing notifications. /// Falls back to the default Element X tone if no custom tone has been selected. var notificationSoundName: UNNotificationSoundName { diff --git a/NSE/Sources/NSEUserSession.swift b/NSE/Sources/NSEUserSession.swift index fac2dd94a..3765affe3 100644 --- a/NSE/Sources/NSEUserSession.swift +++ b/NSE/Sources/NSEUserSession.swift @@ -17,7 +17,7 @@ nonisolated protocol NSEUserSessionProtocol { } final nonisolated class NSEUserSession: NSEUserSessionProtocol { - private let userSettings: CommonSettingsProtocol + let userSettings: UserSettings private let baseClient: ClientProtocol private let notificationClient: NotificationClient private let userID: String @@ -49,17 +49,17 @@ final nonisolated class NSEUserSession: NSEUserSessionProtocol { } var threadsEnabled: Bool { - userSettings.threadsEnabled + userSettings.app.threadsEnabled } init(credentials: KeychainCredentials, roomID: String, clientSessionDelegate: ClientSessionDelegate, clientFactory: ClientFactoryProtocol = ClientFactory(), - userSettings: CommonSettingsProtocol, + appSettings: AppSettings, appHooks: AppHooks) async throws { userID = credentials.userID - self.userSettings = userSettings + userSettings = appSettings.userSettings(for: credentials.userID) baseClient = try await clientFactory.makeNSEClient(credentials: credentials, roomID: roomID, @@ -75,7 +75,7 @@ final nonisolated class NSEUserSession: NSEUserSessionProtocol { delegateHandle = try baseClient.setDelegate(delegate: ClientDelegateWrapper()) // Inject the content scanner so the SDK gates the media it downloads whilst building the notification. - if let contentScannerURL = userSettings.contentScannerURL.publisher.value { + if let contentScannerURL = userSettings.app.contentScannerURL.publisher.value { let contentScanner = ContentScanner(scannerUrl: contentScannerURL.absoluteString) await baseClient.setContentScanner(contentScanner: contentScanner) } diff --git a/NSE/Sources/NotificationHandler.swift b/NSE/Sources/NotificationHandler.swift index 5473a1009..c4b5bb365 100644 --- a/NSE/Sources/NotificationHandler.swift +++ b/NSE/Sources/NotificationHandler.swift @@ -13,7 +13,6 @@ import UserNotifications nonisolated class NotificationHandler { private let userSession: NSEUserSession - private let settings: CommonSettingsProtocol private let contentHandler: (UNNotificationContent) -> Void private var notificationContent: UNMutableNotificationContent private let tag: String @@ -23,13 +22,15 @@ nonisolated class NotificationHandler { /// Whether this handler has already counted its notification towards the app icon badge. private var hasCountedTowardsBadge = false + private var userSettings: UserSettings { + userSession.userSettings + } + init(userSession: NSEUserSession, - settings: CommonSettingsProtocol, contentHandler: @escaping (UNNotificationContent) -> Void, notificationContent: UNMutableNotificationContent, tag: String) { self.userSession = userSession - self.settings = settings self.contentHandler = contentHandler self.notificationContent = notificationContent self.tag = tag @@ -38,7 +39,7 @@ nonisolated class NotificationHandler { style: .plain) notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: eventStringBuilder, - notificationSoundName: settings.notificationSoundName, + notificationSoundName: userSession.userSettings.app.notificationSoundName, userSession: userSession) } @@ -55,7 +56,7 @@ nonisolated class NotificationHandler { case .processedShouldDiscard, .unsupportedShouldDiscard: discardNotification() case .shouldDisplay: - if settings.hideQuietNotificationAlerts, !notificationItemProxy.isNoisy { + if userSettings.app.hideQuietNotificationAlerts, !notificationItemProxy.isNoisy { discardNotification() return } @@ -79,20 +80,20 @@ nonisolated class NotificationHandler { private func deliverNotification() { notificationContent.badge = NSNumber(value: incrementBadgeCount()) - MXLog.info("\(tag) Delivering notification, new badge value: \(settings.lastKnownBadgeCount)") + MXLog.info("\(tag) Delivering notification, new badge value: \(userSettings.app.lastKnownBadgeCount)") contentHandler(notificationContent) } private func incrementBadgeCount() -> Int { // `handleTimeExpiration` can deliver a notification this handler already delivered. guard !hasCountedTowardsBadge else { - return settings.lastKnownBadgeCount + return userSettings.app.lastKnownBadgeCount } hasCountedTowardsBadge = true - settings.lastKnownBadgeCount += 1 + userSettings.app.lastKnownBadgeCount += 1 - return settings.lastKnownBadgeCount + return userSettings.app.lastKnownBadgeCount } private func discardNotification() { @@ -100,7 +101,7 @@ nonisolated class NotificationHandler { let content = UNMutableNotificationContent() // Nothing new is shown to the user, so leave the badge where the app last put it. - content.badge = NSNumber(value: settings.lastKnownBadgeCount) + content.badge = NSNumber(value: userSettings.app.lastKnownBadgeCount) MXLog.info("\(tag) New badge value: \(content.badge?.stringValue ?? "nil")") contentHandler(content) @@ -135,7 +136,7 @@ nonisolated class NotificationHandler { if let targetNotification = deliveredNotifications.first(where: { $0.request.content.eventID == redactedEventID }) { UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [targetNotification.request.identifier]) - settings.lastKnownBadgeCount = max(0, settings.lastKnownBadgeCount - 1) + userSettings.app.lastKnownBadgeCount = max(0, userSettings.app.lastKnownBadgeCount - 1) } return .processedShouldDiscard diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index 5f024bc2f..70a204f57 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -63,7 +63,7 @@ actor NotificationServiceExtensionActor { private static let firstNotificationThreshold: TimeInterval = 15 * 60 - private let settings: CommonSettingsProtocol + private let appSettings: AppSettings private let appHooks: AppHooks /// This is nonisolated just because the expire function needs to be served ASAP so we should not call it from a Task, however this is @@ -82,7 +82,7 @@ actor NotificationServiceExtensionActor { guard let userDefaults = TrackedUserDefaults(suiteName: AppSettings.suiteName) else { fatalError("Catastrophic error retrieving user defaults for \(AppSettings.suiteName)") } - settings = AppSettings(store: userDefaults) + appSettings = AppSettings(store: userDefaults) appHooks = AppHooks() appHooks.setUp() @@ -96,10 +96,10 @@ actor NotificationServiceExtensionActor { if !BootDetectionManager.isDeviceLockedAfterReboot(containerURL: URL.appGroupContainerDirectory) { Self.targetConfiguration.withLock { state in guard state == nil else { return } - state = Target.nse.configure(logLevel: settings.logLevel, - traceLogPacks: settings.traceLogPacks, + state = Target.nse.configure(logLevel: appSettings.logLevel, + traceLogPacks: appSettings.traceLogPacks, sentryURL: nil, - rageshakeURL: settings.bugReportRageshakeURL, + rageshakeURL: appSettings.bugReportRageshakeURL, appHooks: appHooks) } } @@ -161,7 +161,7 @@ actor NotificationServiceExtensionActor { } let homeserverURL = credentials.restorationToken.session.homeserverUrl - await appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: settings) + await appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings) guard let mutableContent = request.content.mutableCopy() as? UNMutableNotificationContent else { return contentHandler(request.content) @@ -177,11 +177,10 @@ actor NotificationServiceExtensionActor { let userSession = try await NSEUserSession(credentials: credentials, roomID: roomID, clientSessionDelegate: keychainController, - userSettings: settings, + appSettings: appSettings, appHooks: appHooks) notificationHandler = NotificationHandler(userSession: userSession, - settings: settings, contentHandler: contentHandler, notificationContent: mutableContent, tag: tag) @@ -221,10 +220,10 @@ actor NotificationServiceExtensionActor { return false } - guard let lastKnownBootTime = settings.lastNotificationBootTime else { + guard let lastKnownBootTime = appSettings.lastNotificationBootTime else { // Assume a missing boot time indicates a fresh installation… // So store the current boot time but let the notification through. - settings.lastNotificationBootTime = currentBootTime + appSettings.lastNotificationBootTime = currentBootTime return false } @@ -233,7 +232,7 @@ actor NotificationServiceExtensionActor { } // This is the first notification since boot, store the boot time. - settings.lastNotificationBootTime = currentBootTime + appSettings.lastNotificationBootTime = currentBootTime // At this point it becomes a trade-off. Once the device has been powered on for a long enough amount // of time it is a reasonable assumption that the device has now connected to a network and that any @@ -258,7 +257,7 @@ actor NotificationServiceExtensionActor { let content = UNMutableNotificationContent() content.body = L10n.notificationReceivedWhileOfflineIos - content.sound = settings.notificationSound + content.sound = appSettings.notificationSound let request = UNNotificationRequest(identifier: Self.receivedWhileOfflineNotificationID, content: content, trigger: nil) UNUserNotificationCenter.current().add(request) diff --git a/ShareExtension/Sources/ShareExtensionViewController.swift b/ShareExtension/Sources/ShareExtensionViewController.swift index df30f5b72..b04b064a7 100644 --- a/ShareExtension/Sources/ShareExtensionViewController.swift +++ b/ShareExtension/Sources/ShareExtensionViewController.swift @@ -12,7 +12,7 @@ import SwiftUI class ShareExtensionViewController: UIViewController { private static var targetConfiguration: Target.ConfigurationResult? - private let userSettings: CommonSettingsProtocol = { + private let appSettings: AppSettings = { guard let userDefaults = TrackedUserDefaults(suiteName: AppSettings.suiteName) else { fatalError("Catastrophic error retrieving user defaults for \(AppSettings.suiteName)") } @@ -33,10 +33,10 @@ class ShareExtensionViewController: UIViewController { appHooks.setUp() if Self.targetConfiguration == nil { - Self.targetConfiguration = Target.shareExtension.configure(logLevel: userSettings.logLevel, - traceLogPacks: userSettings.traceLogPacks, + Self.targetConfiguration = Target.shareExtension.configure(logLevel: appSettings.logLevel, + traceLogPacks: appSettings.traceLogPacks, sentryURL: nil, - rageshakeURL: userSettings.bugReportRageshakeURL, + rageshakeURL: appSettings.bugReportRageshakeURL, appHooks: appHooks) } @@ -50,7 +50,7 @@ class ShareExtensionViewController: UIViewController { if let credentials = keychainController.restorationTokens().first { let homeserverURL = credentials.restorationToken.session.homeserverUrl - appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: userSettings) + appHooks.remoteSettingsHook.loadCache(forHomeserver: homeserverURL, applyingTo: appSettings) } else { // We should really show a different state when there isn't a logged in user, but for now this is fine. MXLog.error("Not logged in, launching app to show the authentication flow.") diff --git a/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift b/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift index e707ce810..7b04a580a 100644 --- a/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift +++ b/UnitTests/Sources/ChatsTabFlowCoordinatorTests.swift @@ -29,8 +29,6 @@ struct ChatsTabFlowCoordinatorTests { } init() async throws { - let userSettings = UserSettings.mock() - clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))) timelineControllerFactory = TimelineControllerFactoryMock(.init()) @@ -38,14 +36,14 @@ struct ChatsTabFlowCoordinatorTests { notificationManager = NotificationManagerMock() - let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), + let userSession = UserSessionMock(.init(clientProxy: clientProxy)) + let flowParameters = CommonFlowParameters(userSession: userSession, bugReportService: BugReportServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()), timelineControllerFactory: timelineControllerFactory, - emojiProvider: EmojiProvider(userSettings: userSettings), + emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSettings, appHooks: AppHooks(), analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/UnitTests/Sources/CreateRoomViewModelTests.swift b/UnitTests/Sources/CreateRoomViewModelTests.swift index 99faf6aec..425353aa1 100644 --- a/UnitTests/Sources/CreateRoomViewModelTests.swift +++ b/UnitTests/Sources/CreateRoomViewModelTests.swift @@ -84,7 +84,7 @@ final class CreateRoomScreenViewModelTests { userID: "@a:b.com", spaceServiceConfiguration: .init(spaceRoomLists: ["1": .init()]))) clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) } - userSession = UserSessionMock(.init(clientProxy: clientProxy)) + userSession = UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)) userSettings.app.knockingEnabled = true let viewModel = CreateRoomScreenViewModel(isSpace: true, spaceSelectionMode: .none, @@ -92,7 +92,6 @@ final class CreateRoomScreenViewModelTests { userSession: userSession, analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) self.viewModel = viewModel @@ -335,7 +334,7 @@ final class CreateRoomScreenViewModelTests { userID: "@a:b.com")) clientProxy.spaceService = spaceService clientProxy.roomForIdentifierClosure = { roomID in .joined(JoinedRoomProxyMock(.init(id: roomID))) } - userSession = UserSessionMock(.init(clientProxy: clientProxy)) + userSession = UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)) userSettings.app.knockingEnabled = true let viewModel = CreateRoomScreenViewModel(isSpace: isSpace, spaceSelectionMode: spacesSelectionMode, @@ -343,7 +342,6 @@ final class CreateRoomScreenViewModelTests { userSession: userSession, analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) self.viewModel = viewModel } diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index 63b65d162..e696a7649 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -588,7 +588,7 @@ final class HomeScreenViewModelTests { break } - let userSession = UserSessionMock(.init(clientProxy: clientProxy)) + let userSession = UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)) if let securityStatePublisher { userSession.sessionSecurityStatePublisher = securityStatePublisher } @@ -597,7 +597,6 @@ final class HomeScreenViewModelTests { viewModel = HomeScreenViewModel(userSession: userSession, selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - userSettings: userSettings, analyticsService: AnalyticsServiceMock(.init()), bugReportService: BugReportServiceMock(.init()), notificationManager: notificationManager, diff --git a/UnitTests/Sources/JoinRoomScreenViewModelTests.swift b/UnitTests/Sources/JoinRoomScreenViewModelTests.swift index 9375f5185..1f0f06d86 100644 --- a/UnitTests/Sources/JoinRoomScreenViewModelTests.swift +++ b/UnitTests/Sources/JoinRoomScreenViewModelTests.swift @@ -237,8 +237,7 @@ final class JoinRoomScreenViewModelTests { } viewModel = JoinRoomScreenViewModel(source: .generic(roomID: "1", via: []), - userSettings: userSettings, - userSession: UserSessionMock(.init(clientProxy: clientProxy)), + userSession: UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)), userIndicatorController: UserIndicatorControllerMock()) } } diff --git a/UnitTests/Sources/LocationSharingScreenViewModelTests.swift b/UnitTests/Sources/LocationSharingScreenViewModelTests.swift index 43241129c..dced69a3c 100644 --- a/UnitTests/Sources/LocationSharingScreenViewModelTests.swift +++ b/UnitTests/Sources/LocationSharingScreenViewModelTests.swift @@ -417,17 +417,15 @@ struct LocationSharingScreenViewModelTests { let roomProxyMock = JoinedRoomProxyMock(.init(members: .allMembers)) roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock - let userSettings = UserSettings.mock() + let userSession = UserSessionMock(.init()) viewModel = LocationSharingScreenViewModel(interactionMode: .viewLive(sender: nil, initialLiveLocationShare: nil), - mapURLBuilder: userSettings.app.mapTilerConfiguration.publisher.value, + mapURLBuilder: userSession.userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: roomProxyMock, timelineController: TimelineControllerMock(.init(timelineProxy: TimelineProxyMock(.init()))), - liveLocationManager: LiveLocationManagerMock(.init()), - userSettings: userSettings, + userSession: userSession, analytics: AnalyticsServiceMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - mediaProvider: MediaProviderMock(.init())) + userIndicatorController: UserIndicatorControllerMock()) // Initially no annotations and no map center since sender and share are both nil. #expect(context.viewState.annotations.isEmpty) @@ -636,11 +634,9 @@ struct LocationSharingScreenViewModelTests { mapURLBuilder: userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: JoinedRoomProxyMock(.init(members: members)), timelineController: TimelineControllerMock(.init(timelineProxy: timelineProxy)), - liveLocationManager: liveLocationManagerMock, - userSettings: userSettings, + userSession: UserSessionMock(.init(userSettings: userSettings, liveLocationManager: liveLocationManagerMock)), analytics: AnalyticsServiceMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - mediaProvider: MediaProviderMock(.init())) + userIndicatorController: UserIndicatorControllerMock()) viewModel.state.bindings.isLocationAuthorized = true } @@ -664,11 +660,9 @@ struct LocationSharingScreenViewModelTests { mapURLBuilder: userSettings.app.mapTilerConfiguration.publisher.value, roomProxy: roomProxyMock, timelineController: TimelineControllerMock(.init(timelineProxy: TimelineProxyMock(.init()))), - liveLocationManager: LiveLocationManagerMock(.init()), - userSettings: userSettings, + userSession: UserSessionMock(.init(userSettings: userSettings)), analytics: AnalyticsServiceMock(.init()), - userIndicatorController: UserIndicatorControllerMock(), - mediaProvider: MediaProviderMock(.init())) + userIndicatorController: UserIndicatorControllerMock()) } private func makeLiveLocationShare(userID: String, latitude: Double = 0.0, longitude: Double = 0.0) -> LiveLocationShare { diff --git a/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift b/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift index c109fffa3..9ebbfeb77 100644 --- a/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomDetailsScreenViewModelTests.swift @@ -30,7 +30,6 @@ struct RoomDetailsScreenViewModelTests { notificationSettingsProxyMock = NotificationSettingsProxyMock(with: NotificationSettingsProxyMockConfiguration()) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -44,7 +43,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -65,7 +63,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -87,7 +84,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -146,7 +142,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -168,7 +163,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -201,7 +195,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init(clientProxy: clientProxy)), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -233,7 +226,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -266,7 +258,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, isEncrypted: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init(clientProxy: clientProxy)), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -300,7 +291,6 @@ struct RoomDetailsScreenViewModelTests { powerLevelsConfiguration: .init(canUserInvite: false))) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -318,7 +308,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", members: mockedMembers, joinRule: .public)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -367,7 +356,6 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -403,7 +391,6 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -439,7 +426,6 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -460,7 +446,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -481,7 +466,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -500,7 +484,6 @@ struct RoomDetailsScreenViewModelTests { notificationSettingsProxyMock.getNotificationSettingsRoomIdIsEncryptedIsOneToOneThrowableError = NotificationSettingsError.Generic(msg: "error") viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -709,7 +692,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -731,7 +713,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: false, knockRequestsState: .loading, joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -755,7 +736,6 @@ struct RoomDetailsScreenViewModelTests { powerLevelsConfiguration: .init(canUserInvite: false))) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -779,7 +759,6 @@ struct RoomDetailsScreenViewModelTests { roomProxyMock = JoinedRoomProxyMock(.init(name: "Test", isDirect: true, members: mockedMembers, knockRequestsState: .loaded(mockedRequests), joinRule: .knock)) viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), @@ -807,7 +786,6 @@ struct RoomDetailsScreenViewModelTests { viewModel = RoomDetailsScreenViewModel(roomProxy: roomProxyMock, userSession: UserSessionMock(.init()), - userSettings: UserSettings.mock(), appHooks: AppHooks(), analyticsService: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/UnitTests/Sources/RoomFlowCoordinatorTests.swift b/UnitTests/Sources/RoomFlowCoordinatorTests.swift index 9b530216b..177295440 100644 --- a/UnitTests/Sources/RoomFlowCoordinatorTests.swift +++ b/UnitTests/Sources/RoomFlowCoordinatorTests.swift @@ -522,14 +522,13 @@ final class RoomFlowCoordinatorTests { "1" } - let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), + let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)), bugReportService: BugReportServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()), timelineControllerFactory: timelineControllerFactory, emojiProvider: EmojiProvider(userSettings: userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSettings, appHooks: AppHooks(), analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift b/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift index f89fb52ee..a69c063e5 100644 --- a/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift +++ b/UnitTests/Sources/RoomMembersFlowCoordinatorTests.swift @@ -51,16 +51,15 @@ struct RoomMembersFlowCoordinatorTests { let clientProxy = ClientProxyMock(.init()) clientProxy.directRoomForUserIDReturnValue = .success(nil) - let userSettings = UserSettings.mock() + let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), + let flowParameters = CommonFlowParameters(userSession: userSession, bugReportService: BugReportServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()), - emojiProvider: EmojiProvider(userSettings: userSettings), + emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: AppMediatorMock(.init()), - userSettings: userSettings, appHooks: AppHooks(), analytics: AnalyticsServiceMock(.init()), userIndicatorController: UserIndicatorControllerMock(), diff --git a/UnitTests/Sources/SearchScreenViewModelTests.swift b/UnitTests/Sources/SearchScreenViewModelTests.swift index 3364acc97..f0a1f5bb9 100644 --- a/UnitTests/Sources/SearchScreenViewModelTests.swift +++ b/UnitTests/Sources/SearchScreenViewModelTests.swift @@ -57,10 +57,8 @@ struct SearchScreenViewModelTests { userSettings = UserSettings.mock() viewModel = SearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), - clientProxy: clientProxy, - mediaProvider: MediaProviderMock(.init()), - userIndicatorController: userIndicatorController, - userSettings: userSettings) + userSession: UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)), + userIndicatorController: userIndicatorController) } @Test diff --git a/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift b/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift index 2a3a16509..cfdb6282e 100644 --- a/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift +++ b/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift @@ -468,12 +468,13 @@ final class SecurityAndPrivacyScreenViewModelTests { roomProxy.updateJoinRuleReturnValue = .success(()) roomProxy.updateRoomDirectoryVisibilityReturnValue = .success(()) + let clientProxy = ClientProxyMock(.init(userIDServerName: "matrix.org", + spaceServiceConfiguration: .init(topLevelSpaces: topLevelSpaces, + joinedParentSpaces: joinedParentSpaces))) + viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: roomProxy, - clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(topLevelSpaces: topLevelSpaces, - joinedParentSpaces: joinedParentSpaces))), + userSession: UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)), userIndicatorController: UserIndicatorControllerMock(), - userSettings: userSettings, appHooks: AppHooks()) } } diff --git a/UnitTests/Sources/SessionVerificationViewModelTests.swift b/UnitTests/Sources/SessionVerificationViewModelTests.swift index 3fb7be9e2..147a6a953 100644 --- a/UnitTests/Sources/SessionVerificationViewModelTests.swift +++ b/UnitTests/Sources/SessionVerificationViewModelTests.swift @@ -21,8 +21,7 @@ struct SessionVerificationViewModelTests { sessionVerificationController = SessionVerificationControllerProxyMock.configureMock() viewModel = SessionVerificationScreenViewModel(sessionVerificationControllerProxy: sessionVerificationController, flow: .deviceInitiator, - userSettings: .mock(), - mediaProvider: MediaProviderMock(.init())) + userSession: UserSessionMock(.init())) context = viewModel.context } diff --git a/UnitTests/Sources/SettingsScreenViewModelTests.swift b/UnitTests/Sources/SettingsScreenViewModelTests.swift index 5e6dbcde1..16da6c2ce 100644 --- a/UnitTests/Sources/SettingsScreenViewModelTests.swift +++ b/UnitTests/Sources/SettingsScreenViewModelTests.swift @@ -202,8 +202,7 @@ struct SettingsScreenViewModelTests { private mutating func setupViewModel(status: UserStatus = .init(), userSettings: UserSettings = .mock()) { clientProxy = ClientProxyMock(.init(userID: "", status: status)) - viewModel = SettingsScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxy)), - userSettings: userSettings, + viewModel = SettingsScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxy, userSettings: userSettings)), isBugReportServiceEnabled: true, isInSecondaryWindow: false, userIndicatorController: UserIndicatorControllerMock()) diff --git a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift index f3d1c661b..783fbc708 100644 --- a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift +++ b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift @@ -48,16 +48,15 @@ struct UserSessionFlowCoordinatorTests { appMediator.networkMonitor = networkMonitor userIndicatorController = UserIndicatorControllerMock() - let userSettings = UserSettings.mock() + let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - let flowParameters = CommonFlowParameters(userSession: UserSessionMock(.init(clientProxy: clientProxy)), + let flowParameters = CommonFlowParameters(userSession: userSession, bugReportService: BugReportServiceMock(.init()), elementCallService: ElementCallServiceMock(.init()), timelineControllerFactory: TimelineControllerFactoryMock(.init()), - emojiProvider: EmojiProvider(userSettings: userSettings), + emojiProvider: EmojiProvider(userSettings: userSession.userSettings), linkMetadataProvider: LinkMetadataProvider(), appMediator: appMediator, - userSettings: userSettings, appHooks: AppHooks(), analytics: AnalyticsServiceMock(.init()), userIndicatorController: userIndicatorController,