mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
feat(healthchat): advertise the account status in settings
Pending approval and an incomplete profile were only visible in the members tab, which a new user has no reason to open.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
|
||||
"action_complete_profile" = "Profil vervollständigen";
|
||||
"action_refresh" = "Aktualisieren";
|
||||
"common_academic_title" = "Titel";
|
||||
"common_address" = "Adresse";
|
||||
@@ -11,6 +12,7 @@
|
||||
"common_last_name" = "Nachname";
|
||||
"common_postal_code" = "PLZ";
|
||||
"common_practice_name" = "Praxisname / Firmenname";
|
||||
"common_profile_incomplete" = "Profil unvollständig";
|
||||
"common_specialty" = "Fachgebiet";
|
||||
"common_street" = "Strasse";
|
||||
"common_website" = "Webseite";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
|
||||
"action_complete_profile" = "Complete profile";
|
||||
"action_refresh" = "Refresh";
|
||||
"common_academic_title" = "Title";
|
||||
"common_address" = "Address";
|
||||
@@ -11,6 +12,7 @@
|
||||
"common_last_name" = "Last name";
|
||||
"common_postal_code" = "Postal code";
|
||||
"common_practice_name" = "Practice name";
|
||||
"common_profile_incomplete" = "Profile incomplete";
|
||||
"common_specialty" = "Speciality";
|
||||
"common_street" = "Street";
|
||||
"common_website" = "Website";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
|
||||
"action_complete_profile" = "Compléter le profil";
|
||||
"action_refresh" = "Actualiser";
|
||||
"common_academic_title" = "Titre";
|
||||
"common_address" = "Adresse";
|
||||
@@ -11,6 +12,7 @@
|
||||
"common_last_name" = "Nom";
|
||||
"common_postal_code" = "Code postal";
|
||||
"common_practice_name" = "Nom de l’entreprise";
|
||||
"common_profile_incomplete" = "Profil incomplet";
|
||||
"common_specialty" = "Spécialisation";
|
||||
"common_street" = "Rue";
|
||||
"common_website" = "Site web";
|
||||
|
||||
@@ -15,6 +15,7 @@ final nonisolated class AppHooks: AppHooksProtocol {
|
||||
func configure(with userSession: UserSessionProtocol?) async {
|
||||
await userSessionHook.configure(with: userSession)
|
||||
await extendedProfileSectionHook.configure(with: userSession)
|
||||
await settingsScreenHook.configure(with: userSession)
|
||||
}
|
||||
|
||||
@AppHook(default: DefaultAppSettingsHook())
|
||||
@@ -50,6 +51,9 @@ final nonisolated class AppHooks: AppHooksProtocol {
|
||||
@AppHook(default: DefaultHomeTabsHook())
|
||||
var homeTabsHook: HomeTabsHookProtocol
|
||||
|
||||
@AppHook(default: DefaultSettingsScreenHook())
|
||||
var settingsScreenHook: SettingsScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultUserDetailsEditScreenHook())
|
||||
var userDetailsEditScreenHook: UserDetailsEditScreenHookProtocol
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright 2026 Novaloop AG
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
/// Loads the own account's status for the banners that advertise it.
|
||||
@Observable
|
||||
final class HealthChatAccountStatusLoader {
|
||||
private(set) var status: HealthChatAccountStatus = .unknown
|
||||
|
||||
/// The load kicked off on creation — await this in tests before asserting.
|
||||
@ObservationIgnored private(set) var loadingTask: Task<Void, Never>?
|
||||
|
||||
init(apiService: HealthChatAPIServiceProtocol) {
|
||||
loadingTask = Task { await load(from: apiService) }
|
||||
}
|
||||
|
||||
/// Creates a loader with a fixed status, for previews.
|
||||
init(status: HealthChatAccountStatus) {
|
||||
self.status = status
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func load(from apiService: HealthChatAPIServiceProtocol) async {
|
||||
// Every failure below leaves the status unknown: a banner must not report an error.
|
||||
guard case let .success(profile) = await apiService.ownProfile() else {
|
||||
return
|
||||
}
|
||||
|
||||
guard profile.isApproved else {
|
||||
status = .pendingApproval
|
||||
return
|
||||
}
|
||||
|
||||
guard case let .success(completeness) = await apiService.profileCompleteness() else {
|
||||
return
|
||||
}
|
||||
|
||||
// The server words the hint itself; without one there is nothing to show.
|
||||
guard !completeness.isComplete, let message = completeness.message else {
|
||||
status = .ok
|
||||
return
|
||||
}
|
||||
|
||||
status = .incompleteProfile(message: message)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright 2026 Novaloop AG
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
/// The account status advertised in the app's settings. Renders nothing while loading,
|
||||
/// for approved accounts with a complete profile, and when the status can't be read.
|
||||
///
|
||||
/// Neither banner is dismissible — both resolve server-side.
|
||||
struct HealthChatAccountStatusSection: View {
|
||||
// Owned by the hook, not the view: the settings screen rebuilds this section on
|
||||
// every body pass, and a view-owned loader would fire a request each time.
|
||||
private let loader: HealthChatAccountStatusLoader
|
||||
private let completeProfileAction: () -> Void
|
||||
|
||||
init(loader: HealthChatAccountStatusLoader, completeProfileAction: @escaping () -> Void = { }) {
|
||||
self.loader = loader
|
||||
self.completeProfileAction = completeProfileAction
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
switch loader.status {
|
||||
case .unknown, .ok:
|
||||
EmptyView()
|
||||
case .pendingApproval:
|
||||
Section {
|
||||
ListRow(label: .default(title: HealthChatL10n.screenMemberDirectoryPendingTitle,
|
||||
description: HealthChatL10n.screenMemberDirectoryPendingApproval,
|
||||
icon: \.time),
|
||||
kind: .label)
|
||||
}
|
||||
case .incompleteProfile(let message):
|
||||
Section {
|
||||
ListRow(label: .default(title: HealthChatL10n.commonProfileIncomplete,
|
||||
description: message,
|
||||
icon: \.info),
|
||||
kind: .label)
|
||||
|
||||
ListRow(label: .action(title: HealthChatL10n.actionCompleteProfile, icon: \.userProfile),
|
||||
kind: .button(action: completeProfileAction))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct HealthChatAccountStatusSection_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
Form {
|
||||
HealthChatAccountStatusSection(loader: .init(status: .pendingApproval))
|
||||
}
|
||||
.compoundList()
|
||||
.previewDisplayName("Pending approval")
|
||||
|
||||
Form {
|
||||
HealthChatAccountStatusSection(loader: .init(status: .incompleteProfile(message: "Bitte vervollständigen Sie Ihr Profil, bevor Sie die Benutzersuche verwenden")))
|
||||
}
|
||||
.compoundList()
|
||||
.previewDisplayName("Incomplete profile")
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ extension AppHooks {
|
||||
registerCompoundHook(HealthChatCompoundHook())
|
||||
registerExtendedProfileSectionHook(HealthChatExtendedProfileSectionHook())
|
||||
registerHomeTabsHook(HealthChatHomeTabsHook())
|
||||
registerSettingsScreenHook(HealthChatSettingsScreenHook())
|
||||
registerUserDetailsEditScreenHook(HealthChatUserDetailsEditScreenHook())
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright 2026 Novaloop AG
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
#if IS_MAIN_APP
|
||||
// Conforming to the nonisolated hook protocol would infer nonisolated, but the
|
||||
// service is main-actor state — the hook's requirements are all @MainActor anyway.
|
||||
@MainActor
|
||||
final class HealthChatSettingsScreenHook: SettingsScreenHookProtocol {
|
||||
/// One load per session — the settings screen asks for this section on every body pass.
|
||||
private var statusLoader: HealthChatAccountStatusLoader?
|
||||
|
||||
// Constructed during hook registration, before the main actor is reachable.
|
||||
nonisolated init() { }
|
||||
|
||||
func configure(with userSession: UserSessionProtocol?) async {
|
||||
statusLoader = userSession.map {
|
||||
let apiService = HealthChatAPIService(tokenProvider: HealthChatOpenIDTokenProvider(clientProxy: $0.clientProxy))
|
||||
return HealthChatAccountStatusLoader(apiService: apiService)
|
||||
}
|
||||
}
|
||||
|
||||
func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView? {
|
||||
guard let statusLoader else {
|
||||
return nil
|
||||
}
|
||||
return AnyView(HealthChatAccountStatusSection(loader: statusLoader,
|
||||
completeProfileAction: completeProfileAction))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
nonisolated protocol SettingsScreenHookProtocol: Sendable {
|
||||
@MainActor func configure(with userSession: UserSessionProtocol?) async
|
||||
|
||||
/// An extra Form section rendered between the user and the account sections,
|
||||
/// advertising whatever is holding the account back.
|
||||
/// - Parameter completeProfileAction: Opens the own profile editor.
|
||||
@MainActor func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView?
|
||||
}
|
||||
|
||||
struct DefaultSettingsScreenHook: SettingsScreenHookProtocol {
|
||||
func configure(with userSession: UserSessionProtocol?) async { }
|
||||
|
||||
func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView? {
|
||||
nil
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ class SettingsFlowCoordinator: FlowCoordinatorProtocol {
|
||||
private func presentSettingsScreen(animated: Bool) {
|
||||
let settingsScreenCoordinator = SettingsScreenCoordinator(parameters: .init(userSession: flowParameters.userSession,
|
||||
appSettings: flowParameters.appSettings,
|
||||
appHooks: flowParameters.appHooks,
|
||||
isBugReportServiceEnabled: flowParameters.bugReportService.isEnabled,
|
||||
isInSecondaryWindow: isInSecondaryWindow,
|
||||
userIndicatorController: flowParameters.userIndicatorController))
|
||||
|
||||
@@ -10,6 +10,8 @@ import Foundation
|
||||
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
internal nonisolated enum HealthChatL10n {
|
||||
/// Complete profile
|
||||
internal static var actionCompleteProfile: String { return HealthChatL10n.tr("HealthChat", "action_complete_profile") }
|
||||
/// Refresh
|
||||
internal static var actionRefresh: String { return HealthChatL10n.tr("HealthChat", "action_refresh") }
|
||||
/// Title
|
||||
@@ -34,6 +36,8 @@ internal nonisolated enum HealthChatL10n {
|
||||
internal static var commonPostalCode: String { return HealthChatL10n.tr("HealthChat", "common_postal_code") }
|
||||
/// Practice name
|
||||
internal static var commonPracticeName: String { return HealthChatL10n.tr("HealthChat", "common_practice_name") }
|
||||
/// Profile incomplete
|
||||
internal static var commonProfileIncomplete: String { return HealthChatL10n.tr("HealthChat", "common_profile_incomplete") }
|
||||
/// Speciality
|
||||
internal static var commonSpecialty: String { return HealthChatL10n.tr("HealthChat", "common_specialty") }
|
||||
/// Street
|
||||
|
||||
@@ -55,6 +55,7 @@ enum TestablePreviewsDictionary {
|
||||
"FormattingToolbar_Previews" : FormattingToolbar_Previews.self,
|
||||
"FullscreenDialog_Previews" : FullscreenDialog_Previews.self,
|
||||
"GalleryRoomTimelineView_Previews" : GalleryRoomTimelineView_Previews.self,
|
||||
"HealthChatAccountStatusSection_Previews" : HealthChatAccountStatusSection_Previews.self,
|
||||
"HealthChatExtendedProfileSection_Previews" : HealthChatExtendedProfileSection_Previews.self,
|
||||
"HealthChatInviteMemberScreen_Previews" : HealthChatInviteMemberScreen_Previews.self,
|
||||
"HealthChatMemberDirectoryScreen_Previews" : HealthChatMemberDirectoryScreen_Previews.self,
|
||||
|
||||
@@ -11,6 +11,8 @@ import SwiftUI
|
||||
|
||||
struct SettingsScreenCoordinatorParameters {
|
||||
let userSession: UserSessionProtocol
|
||||
let appSettings: AppSettings
|
||||
let appHooks: AppHooks
|
||||
let isBugReportServiceEnabled: Bool
|
||||
let isInSecondaryWindow: Bool
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
@@ -18,30 +20,22 @@ struct SettingsScreenCoordinatorParameters {
|
||||
|
||||
enum SettingsScreenCoordinatorAction {
|
||||
case dismiss
|
||||
|
||||
case logout
|
||||
case secureBackup
|
||||
case userDetails
|
||||
case userStatusEmojiPicker(EmojiPickerScreenContinuation)
|
||||
|
||||
case addAccount
|
||||
|
||||
case manageAccount(url: URL)
|
||||
case linkNewDevice
|
||||
case notifications
|
||||
case secureBackup
|
||||
case moderationAndSafety
|
||||
case bugReport
|
||||
|
||||
case logout
|
||||
case deactivateAccount
|
||||
|
||||
case mediaUploadQuality
|
||||
case appLock
|
||||
case locationSharing
|
||||
case analytics
|
||||
case labs
|
||||
case appLock
|
||||
case bugReport
|
||||
case about
|
||||
|
||||
case blockedUsers
|
||||
case linkNewDevice
|
||||
case manageAccount(url: URL)
|
||||
case notifications
|
||||
case advancedSettings
|
||||
case labs
|
||||
case developerOptions
|
||||
case deactivateAccount
|
||||
}
|
||||
|
||||
final class SettingsScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -58,6 +52,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
init(parameters: SettingsScreenCoordinatorParameters) {
|
||||
viewModel = SettingsScreenViewModel(userSession: parameters.userSession,
|
||||
appSettings: parameters.appSettings,
|
||||
appHooks: parameters.appHooks,
|
||||
isBugReportServiceEnabled: parameters.isBugReportServiceEnabled,
|
||||
isInSecondaryWindow: parameters.isInSecondaryWindow,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
@@ -69,48 +65,38 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
|
||||
switch action {
|
||||
case .close:
|
||||
actionsSubject.send(.dismiss)
|
||||
|
||||
case .userDetails:
|
||||
actionsSubject.send(.userDetails)
|
||||
case let .userStatusEmojiPicker(continuation):
|
||||
actionsSubject.send(.userStatusEmojiPicker(continuation))
|
||||
|
||||
case .addAccount:
|
||||
actionsSubject.send(.addAccount)
|
||||
|
||||
case let .manageAccount(url):
|
||||
actionsSubject.send(.manageAccount(url: url))
|
||||
case .linkNewDevice:
|
||||
actionsSubject.send(.linkNewDevice)
|
||||
case .notifications:
|
||||
actionsSubject.send(.notifications)
|
||||
case .secureBackup:
|
||||
actionsSubject.send(.secureBackup)
|
||||
case .moderationAndSafety:
|
||||
actionsSubject.send(.moderationAndSafety)
|
||||
case let .manageAccount(url):
|
||||
actionsSubject.send(.manageAccount(url: url))
|
||||
case .analytics:
|
||||
actionsSubject.send(.analytics)
|
||||
case .appLock:
|
||||
actionsSubject.send(.appLock)
|
||||
case .reportBug:
|
||||
actionsSubject.send(.bugReport)
|
||||
|
||||
case .about:
|
||||
actionsSubject.send(.about)
|
||||
case .blockedUsers:
|
||||
actionsSubject.send(.blockedUsers)
|
||||
case .secureBackup:
|
||||
actionsSubject.send(.secureBackup)
|
||||
case .notifications:
|
||||
actionsSubject.send(.notifications)
|
||||
case .advancedSettings:
|
||||
actionsSubject.send(.advancedSettings)
|
||||
case .labs:
|
||||
actionsSubject.send(.labs)
|
||||
case .developerOptions:
|
||||
actionsSubject.send(.developerOptions)
|
||||
case .logout:
|
||||
actionsSubject.send(.logout)
|
||||
case .deactivateAccount:
|
||||
actionsSubject.send(.deactivateAccount)
|
||||
|
||||
case .mediaUploadQuality:
|
||||
actionsSubject.send(.mediaUploadQuality)
|
||||
case .appLock:
|
||||
actionsSubject.send(.appLock)
|
||||
case .locationSharing:
|
||||
actionsSubject.send(.locationSharing)
|
||||
case .analytics:
|
||||
actionsSubject.send(.analytics)
|
||||
case .labs:
|
||||
actionsSubject.send(.labs)
|
||||
case .about:
|
||||
actionsSubject.send(.about)
|
||||
|
||||
case .developerOptions:
|
||||
actionsSubject.send(.developerOptions)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -10,30 +10,22 @@ import SwiftUI
|
||||
|
||||
enum SettingsScreenViewModelAction {
|
||||
case close
|
||||
|
||||
case userDetails
|
||||
case userStatusEmojiPicker(EmojiPickerScreenContinuation)
|
||||
|
||||
case addAccount
|
||||
|
||||
case manageAccount(url: URL)
|
||||
case linkNewDevice
|
||||
case notifications
|
||||
case secureBackup
|
||||
case moderationAndSafety
|
||||
case manageAccount(url: URL)
|
||||
case analytics
|
||||
case appLock
|
||||
case reportBug
|
||||
|
||||
case about
|
||||
case blockedUsers
|
||||
case secureBackup
|
||||
case notifications
|
||||
case advancedSettings
|
||||
case labs
|
||||
case developerOptions
|
||||
case logout
|
||||
case deactivateAccount
|
||||
|
||||
case mediaUploadQuality
|
||||
case appLock
|
||||
case locationSharing
|
||||
case analytics
|
||||
case labs
|
||||
case about
|
||||
|
||||
case developerOptions
|
||||
}
|
||||
|
||||
enum SettingsScreenSecuritySectionMode {
|
||||
@@ -46,7 +38,6 @@ struct SettingsScreenViewState: BindableState {
|
||||
var userProfile: UserProfile
|
||||
var showUserStatusInput = false
|
||||
var showLinkNewDeviceButton: Bool
|
||||
var showAddAccountButton: Bool
|
||||
var accountProfileURL: URL?
|
||||
var showAccountDeactivation: Bool
|
||||
var showDeveloperOptions: Bool
|
||||
@@ -54,13 +45,16 @@ struct SettingsScreenViewState: BindableState {
|
||||
var securitySectionMode = SettingsScreenSecuritySectionMode.none
|
||||
var showSecuritySectionBadge = false
|
||||
|
||||
var showBlockedUsers = false
|
||||
let showAnalyticsSettings: Bool
|
||||
|
||||
let isBugReportServiceEnabled: Bool
|
||||
|
||||
let navigationBarVisibility: Visibility
|
||||
|
||||
var bindings: SettingsScreenViewStateBindings
|
||||
let appHooks: AppHooks
|
||||
|
||||
var bindings = SettingsScreenViewStateBindings()
|
||||
|
||||
var userStatusRowMode: SettingsScreenUserStatusRow.Mode {
|
||||
if bindings.isShowingCustomStatusField {
|
||||
@@ -74,8 +68,6 @@ struct SettingsScreenViewState: BindableState {
|
||||
}
|
||||
|
||||
struct SettingsScreenViewStateBindings {
|
||||
private let userSettings: UserSettings
|
||||
|
||||
var isPresentingStatusPicker = false
|
||||
var customStatusEmoji: Character = "😄"
|
||||
var isShowingCustomStatusField = false {
|
||||
@@ -87,44 +79,27 @@ struct SettingsScreenViewStateBindings {
|
||||
}
|
||||
|
||||
var isPresentingAccountDeactivationConfirmation = false
|
||||
|
||||
var appAppearance: AppAppearance {
|
||||
get { userSettings.app.appAppearance }
|
||||
set { userSettings.app.appAppearance = newValue }
|
||||
}
|
||||
|
||||
init(userSettings: UserSettings) {
|
||||
self.userSettings = userSettings
|
||||
}
|
||||
}
|
||||
|
||||
enum SettingsScreenViewAction {
|
||||
case close
|
||||
|
||||
case userDetails
|
||||
case userStatus(UserStatusAction)
|
||||
|
||||
case addAccount
|
||||
|
||||
case manageAccount(url: URL)
|
||||
case linkNewDevice
|
||||
case notifications
|
||||
case secureBackup
|
||||
case moderationAndSafety
|
||||
case reportBug
|
||||
|
||||
case logout
|
||||
case deactivateAccount
|
||||
|
||||
case mediaUploadQuality
|
||||
case appLock
|
||||
case locationSharing
|
||||
case analytics
|
||||
case labs
|
||||
case appLock
|
||||
case reportBug
|
||||
case about
|
||||
|
||||
case blockedUsers
|
||||
case secureBackup
|
||||
case linkNewDevice
|
||||
case manageAccount(url: URL)
|
||||
case notifications
|
||||
case enableDeveloperOptions
|
||||
case developerOptions
|
||||
case advancedSettings
|
||||
case labs
|
||||
case logout
|
||||
case deactivateAccount
|
||||
|
||||
enum UserStatusAction {
|
||||
/// Show status picker sheet to select a preset status.
|
||||
|
||||
@@ -12,7 +12,7 @@ import SwiftUI
|
||||
typealias SettingsScreenViewModelType = StateStoreViewModelV2<SettingsScreenViewState, SettingsScreenViewAction>
|
||||
|
||||
class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewModelProtocol {
|
||||
private let userSettings: UserSettings
|
||||
private let appSettings: AppSettings
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
@@ -22,35 +22,30 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(userSession: UserSessionProtocol, isBugReportServiceEnabled: Bool, isInSecondaryWindow: Bool, userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
userSettings = userSession.userSettings
|
||||
init(userSession: UserSessionProtocol, appSettings: AppSettings, appHooks: AppHooks, isBugReportServiceEnabled: Bool, isInSecondaryWindow: Bool, userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.appSettings = appSettings
|
||||
clientProxy = userSession.clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: .init(deviceID: userSession.clientProxy.deviceID,
|
||||
userProfile: userSession.clientProxy.userProfilePublisher.value,
|
||||
showLinkNewDeviceButton: userSettings.app.linkNewDeviceEnabled,
|
||||
showAddAccountButton: userSettings.app.multiAccountEnabled,
|
||||
showLinkNewDeviceButton: appSettings.linkNewDeviceEnabled,
|
||||
showAccountDeactivation: userSession.clientProxy.canDeactivateAccount,
|
||||
showDeveloperOptions: userSettings.app.developerOptionsEnabled,
|
||||
showAnalyticsSettings: userSettings.app.canPromptForAnalytics,
|
||||
showDeveloperOptions: appSettings.developerOptionsEnabled,
|
||||
showAnalyticsSettings: appSettings.canPromptForAnalytics,
|
||||
isBugReportServiceEnabled: isBugReportServiceEnabled,
|
||||
navigationBarVisibility: isInSecondaryWindow ? .hidden : .automatic,
|
||||
bindings: .init(userSettings: userSettings)),
|
||||
appHooks: appHooks),
|
||||
mediaProvider: userSession.mediaProvider)
|
||||
|
||||
userSettings.app.developerOptionsEnabledPublisher
|
||||
appSettings.developerOptionsEnabledPublisher
|
||||
.weakAssign(to: \.state.showDeveloperOptions, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSettings.app.linkNewDeviceEnabledPublisher
|
||||
appSettings.linkNewDeviceEnabledPublisher
|
||||
.weakAssign(to: \.state.showLinkNewDeviceButton, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSettings.app.multiAccountEnabledPublisher
|
||||
.weakAssign(to: \.state.showAddAccountButton, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSession.clientProxy.userProfilePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userProfile, on: self)
|
||||
@@ -78,6 +73,18 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSession.clientProxy.ignoredUsersPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.map {
|
||||
guard let blockedUsers = $0 else {
|
||||
return false
|
||||
}
|
||||
|
||||
return !blockedUsers.isEmpty
|
||||
}
|
||||
.weakAssign(to: \.state.showBlockedUsers, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
Task {
|
||||
if case .success(true) = await userSession.clientProxy.isUserStatusSupported() {
|
||||
state.showUserStatusInput = true
|
||||
@@ -91,7 +98,6 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
switch viewAction {
|
||||
case .close:
|
||||
actionsSubject.send(.close)
|
||||
|
||||
case .userDetails:
|
||||
actionsSubject.send(.userDetails)
|
||||
case .userStatus(.pickStatus):
|
||||
@@ -108,45 +114,36 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
case .userStatus(.cancel):
|
||||
state.bindings.isPresentingStatusPicker = false
|
||||
state.bindings.isShowingCustomStatusField = false
|
||||
|
||||
case .addAccount:
|
||||
actionsSubject.send(.addAccount)
|
||||
|
||||
case let .manageAccount(url):
|
||||
actionsSubject.send(.manageAccount(url: url))
|
||||
case .linkNewDevice:
|
||||
actionsSubject.send(.linkNewDevice)
|
||||
case .notifications:
|
||||
actionsSubject.send(.notifications)
|
||||
case .secureBackup:
|
||||
actionsSubject.send(.secureBackup)
|
||||
case .moderationAndSafety:
|
||||
actionsSubject.send(.moderationAndSafety)
|
||||
case .reportBug:
|
||||
actionsSubject.send(.reportBug)
|
||||
|
||||
case .logout:
|
||||
actionsSubject.send(.logout)
|
||||
case .deactivateAccount:
|
||||
actionsSubject.send(.deactivateAccount)
|
||||
|
||||
case .mediaUploadQuality:
|
||||
actionsSubject.send(.mediaUploadQuality)
|
||||
case .appLock:
|
||||
actionsSubject.send(.appLock)
|
||||
case .locationSharing:
|
||||
actionsSubject.send(.locationSharing)
|
||||
case let .manageAccount(url):
|
||||
actionsSubject.send(.manageAccount(url: url))
|
||||
case .analytics:
|
||||
actionsSubject.send(.analytics)
|
||||
case .labs:
|
||||
actionsSubject.send(.labs)
|
||||
case .appLock:
|
||||
actionsSubject.send(.appLock)
|
||||
case .reportBug:
|
||||
actionsSubject.send(.reportBug)
|
||||
case .about:
|
||||
actionsSubject.send(.about)
|
||||
|
||||
case .blockedUsers:
|
||||
actionsSubject.send(.blockedUsers)
|
||||
case .logout:
|
||||
actionsSubject.send(.logout)
|
||||
case .secureBackup:
|
||||
actionsSubject.send(.secureBackup)
|
||||
case .notifications:
|
||||
actionsSubject.send(.notifications)
|
||||
case .advancedSettings:
|
||||
actionsSubject.send(.advancedSettings)
|
||||
case .labs:
|
||||
actionsSubject.send(.labs)
|
||||
case .enableDeveloperOptions:
|
||||
userSettings.app.developerOptionsEnabled.toggle()
|
||||
appSettings.developerOptionsEnabled.toggle()
|
||||
case .developerOptions:
|
||||
actionsSubject.send(.developerOptions)
|
||||
case .deactivateAccount:
|
||||
actionsSubject.send(.deactivateAccount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,19 +13,37 @@ import SwiftUI
|
||||
struct SettingsScreen: View {
|
||||
@Bindable var context: SettingsScreenViewModel.Context
|
||||
|
||||
private var shouldHideManageAccountSection: Bool {
|
||||
context.viewState.accountProfileURL == nil &&
|
||||
!context.viewState.showBlockedUsers &&
|
||||
!context.viewState.showLinkNewDeviceButton
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
userSection
|
||||
|
||||
if context.viewState.showAddAccountButton {
|
||||
addAccountSection
|
||||
if context.viewState.showUserStatusInput {
|
||||
userStatusSection
|
||||
}
|
||||
|
||||
accountSettingsSection
|
||||
context.viewState.appHooks.settingsScreenHook.accountStatusSection {
|
||||
context.send(viewAction: .userDetails)
|
||||
}
|
||||
|
||||
if !shouldHideManageAccountSection {
|
||||
manageAccountSection
|
||||
}
|
||||
|
||||
manageMyAppSection
|
||||
|
||||
generalSection
|
||||
|
||||
signOutSection
|
||||
|
||||
appSettingsSection
|
||||
if context.viewState.showDeveloperOptions {
|
||||
developerOptionsSection
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(L10n.commonSettings)
|
||||
@@ -56,9 +74,15 @@ struct SettingsScreen: View {
|
||||
.accessibilityHidden(true)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(context.viewState.userProfile.displayName ?? "")
|
||||
.font(.compound.headingMD)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
HStack(spacing: 6) {
|
||||
Text(context.viewState.userProfile.displayName ?? "")
|
||||
|
||||
if let statusEmoji = context.viewState.userProfile.status.displayed?.emoji {
|
||||
Text(String(statusEmoji))
|
||||
}
|
||||
}
|
||||
.font(.compound.headingMD)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
|
||||
Text(context.viewState.userProfile.id)
|
||||
.font(.compound.bodySM)
|
||||
@@ -73,27 +97,47 @@ struct SettingsScreen: View {
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
})
|
||||
|
||||
if context.viewState.showUserStatusInput {
|
||||
SettingsScreenUserStatusRow(mode: context.viewState.userStatusRowMode) { action in
|
||||
context.send(viewAction: .userStatus(action))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var userStatusSection: some View {
|
||||
Section {
|
||||
SettingsScreenUserStatusRow(mode: context.viewState.userStatusRowMode) { action in
|
||||
context.send(viewAction: .userStatus(action))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var addAccountSection: some View {
|
||||
private var manageMyAppSection: some View {
|
||||
Section {
|
||||
ListRow(label: .default(title: L10n.screenSettingsAddAccount,
|
||||
icon: \.plus),
|
||||
ListRow(label: .default(title: L10n.screenNotificationSettingsTitle,
|
||||
icon: \.notifications),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .addAccount)
|
||||
context.send(viewAction: .notifications)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.addAccount)
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.notifications)
|
||||
|
||||
ListRow(label: .default(title: L10n.commonScreenLock,
|
||||
icon: \.lock),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .appLock)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.screenLock)
|
||||
|
||||
switch context.viewState.securitySectionMode {
|
||||
case .secureBackup:
|
||||
ListRow(label: .default(title: L10n.commonEncryption,
|
||||
icon: \.key),
|
||||
details: context.viewState.showSecuritySectionBadge ? .icon(securitySectionBadge) : nil,
|
||||
kind: .navigationLink { context.send(viewAction: .secureBackup) })
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.secureBackup)
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var accountSettingsSection: some View {
|
||||
private var manageAccountSection: some View {
|
||||
Section {
|
||||
if let url = context.viewState.accountProfileURL {
|
||||
ListRow(label: .default(title: L10n.actionManageAccountAndDevices,
|
||||
@@ -112,29 +156,38 @@ struct SettingsScreen: View {
|
||||
})
|
||||
}
|
||||
|
||||
ListRow(label: .default(title: L10n.screenNotificationSettingsTitle,
|
||||
icon: \.notifications),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .notifications)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.notifications)
|
||||
|
||||
switch context.viewState.securitySectionMode {
|
||||
case .secureBackup:
|
||||
ListRow(label: .default(title: L10n.commonEncryption,
|
||||
icon: \.key),
|
||||
details: context.viewState.showSecuritySectionBadge ? .icon(securitySectionBadge) : nil,
|
||||
kind: .navigationLink { context.send(viewAction: .secureBackup) })
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.secureBackup)
|
||||
default:
|
||||
EmptyView()
|
||||
if context.viewState.showBlockedUsers {
|
||||
ListRow(label: .default(title: L10n.commonBlockedUsers,
|
||||
icon: \.block),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .blockedUsers)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.blockedUsers)
|
||||
}
|
||||
|
||||
ListRow(label: .default(title: L10n.commonModerationAndSafety,
|
||||
icon: \.admin),
|
||||
}
|
||||
}
|
||||
|
||||
private var generalSection: some View {
|
||||
Section {
|
||||
ListRow(label: .default(title: L10n.commonAdvancedSettings,
|
||||
icon: \.settings),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .moderationAndSafety)
|
||||
context.send(viewAction: .advancedSettings)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.advancedSettings)
|
||||
|
||||
ListRow(label: .default(title: L10n.screenAdvancedSettingsLabs,
|
||||
icon: \.labs),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .labs)
|
||||
})
|
||||
|
||||
ListRow(label: .default(title: L10n.commonAbout,
|
||||
icon: \.info),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .about)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.about)
|
||||
|
||||
if context.viewState.isBugReportServiceEnabled {
|
||||
ListRow(label: .default(title: L10n.commonReportAProblem,
|
||||
@@ -144,9 +197,15 @@ struct SettingsScreen: View {
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.reportBug)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.commonAccountSettings)
|
||||
.compoundListSectionHeader()
|
||||
|
||||
if context.viewState.showAnalyticsSettings {
|
||||
ListRow(label: .default(title: L10n.commonAnalytics,
|
||||
icon: \.chart),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .analytics)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.analytics)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,68 +227,21 @@ struct SettingsScreen: View {
|
||||
context.send(viewAction: .deactivateAccount)
|
||||
})
|
||||
}
|
||||
} footer: {
|
||||
if !context.viewState.showDeveloperOptions {
|
||||
versionSection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var appSettingsSection: some View {
|
||||
private var developerOptionsSection: some View {
|
||||
Section {
|
||||
ListRow(label: .default(title: L10n.commonAppearance,
|
||||
icon: \.darkMode),
|
||||
kind: .picker(selection: $context.appAppearance,
|
||||
items: AppAppearance.allCases.map { (title: $0.name, tag: $0) }))
|
||||
|
||||
ListRow(label: .default(title: L10n.commonMediaUploadQuality,
|
||||
icon: \.image),
|
||||
ListRow(label: .default(title: L10n.commonDeveloperOptions,
|
||||
icon: \.code),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .mediaUploadQuality)
|
||||
context.send(viewAction: .developerOptions)
|
||||
})
|
||||
|
||||
ListRow(label: .default(title: L10n.commonScreenLock,
|
||||
icon: \.lock),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .appLock)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.screenLock)
|
||||
|
||||
ListRow(label: .default(title: L10n.commonLocationSharing,
|
||||
icon: \.locationPin),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .locationSharing)
|
||||
})
|
||||
|
||||
if context.viewState.showAnalyticsSettings {
|
||||
ListRow(label: .default(title: L10n.commonAnalytics,
|
||||
icon: \.chart),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .analytics)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.analytics)
|
||||
}
|
||||
|
||||
ListRow(label: .default(title: L10n.screenAdvancedSettingsLabs,
|
||||
icon: \.labs),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .labs)
|
||||
})
|
||||
|
||||
ListRow(label: .default(title: L10n.commonAbout,
|
||||
icon: \.info),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .about)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.about)
|
||||
|
||||
if context.viewState.showDeveloperOptions {
|
||||
ListRow(label: .default(title: L10n.commonDeveloperOptions,
|
||||
icon: \.code),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .developerOptions)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.developerOptions)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.commonAppSettings)
|
||||
.compoundListSectionHeader()
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.developerOptions)
|
||||
} footer: {
|
||||
versionSection
|
||||
}
|
||||
@@ -274,19 +286,6 @@ struct SettingsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppAppearance {
|
||||
var name: String {
|
||||
switch self {
|
||||
case .system:
|
||||
L10n.themeSystem
|
||||
case .light:
|
||||
L10n.themeLight
|
||||
case .dark:
|
||||
L10n.themeDark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 26.0, *)
|
||||
@@ -299,7 +298,7 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
SettingsScreen(context: viewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: viewModel.context.observe(\.viewState.accountProfileURL).map { $0 != nil })
|
||||
.frame(height: 1300)
|
||||
.frame(height: 1100)
|
||||
.previewLayout(.sizeThatFits)
|
||||
.previewDisplayName("Default")
|
||||
|
||||
@@ -307,21 +306,19 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
SettingsScreen(context: bugReportDisabledViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: bugReportDisabledViewModel.context.observe(\.viewState.accountProfileURL).map { $0 != nil })
|
||||
.frame(height: 1250)
|
||||
.frame(height: 1050)
|
||||
.previewLayout(.sizeThatFits)
|
||||
.previewDisplayName("Bug report disabled")
|
||||
}
|
||||
|
||||
static func makeViewModel(isBugReportServiceEnabled: Bool = true) -> SettingsScreenViewModel {
|
||||
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))
|
||||
status: .mockFocussing))))
|
||||
return SettingsScreenViewModel(userSession: userSession,
|
||||
appSettings: .volatile(),
|
||||
appHooks: AppHooks(),
|
||||
isBugReportServiceEnabled: isBugReportServiceEnabled,
|
||||
isInSecondaryWindow: false,
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright 2026 Novaloop AG
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// What is holding an account back from using the whole app.
|
||||
nonisolated enum HealthChatAccountStatus: Equatable {
|
||||
/// Nothing is known, e.g. the API is unreachable. Renders nothing — never an error.
|
||||
case unknown
|
||||
/// Not approved by an admin yet. Takes precedence over ``incompleteProfile``,
|
||||
/// as completing a profile does nothing for an unapproved account.
|
||||
case pendingApproval
|
||||
/// Approved, but the server reports missing profile fields. The message is its wording.
|
||||
case incompleteProfile(message: String)
|
||||
case ok
|
||||
}
|
||||
Reference in New Issue
Block a user