mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
refactor(healthchat): move the session hooks onto UserHooks
This commit is contained in:
@@ -16,9 +16,8 @@ extension AppHooks {
|
||||
#if IS_MAIN_APP
|
||||
registerAppSettingsHook(HealthChatAppSettingsHook())
|
||||
registerCompoundHook(HealthChatCompoundHook())
|
||||
registerExtendedProfileSectionHook(HealthChatExtendedProfileSectionHook())
|
||||
registerHomeTabsHook(HealthChatHomeTabsHook())
|
||||
registerSettingsScreenHook(HealthChatSettingsScreenHook())
|
||||
registerUserSessionHook(HealthChatUserSessionHook())
|
||||
registerUserDetailsEditScreenHook(HealthChatUserDetailsEditScreenHook())
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -12,20 +12,14 @@ import SwiftUI
|
||||
// service is main-actor state — the hook's requirements are all @MainActor anyway.
|
||||
@MainActor
|
||||
final class HealthChatExtendedProfileSectionHook: ExtendedProfileSectionHookProtocol {
|
||||
private var extendedProfileService: ExtendedProfileServiceProtocol?
|
||||
private let extendedProfileService: ExtendedProfileServiceProtocol
|
||||
|
||||
// Constructed during hook registration, before the main actor is reachable.
|
||||
nonisolated init() { }
|
||||
|
||||
func configure(with userSession: UserSessionProtocol?) async {
|
||||
extendedProfileService = userSession.map { ExtendedProfileService(clientProxy: $0.clientProxy) }
|
||||
init(extendedProfileService: ExtendedProfileServiceProtocol) {
|
||||
self.extendedProfileService = extendedProfileService
|
||||
}
|
||||
|
||||
func extendedProfileSection(userID: String) -> AnyView? {
|
||||
guard let extendedProfileService else {
|
||||
return nil
|
||||
}
|
||||
return AnyView(HealthChatExtendedProfileSection(userID: userID, service: extendedProfileService))
|
||||
AnyView(HealthChatExtendedProfileSection(userID: userID, service: extendedProfileService))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,28 +14,19 @@ import SwiftUI
|
||||
final class HealthChatSettingsScreenHook: SettingsScreenHookProtocol {
|
||||
// Owned here rather than by the section: the settings screen asks for the section on
|
||||
// every body pass. Nothing is fetched until the screen appears and asks for a refresh.
|
||||
private var statusLoader: HealthChatAccountStatusLoader?
|
||||
private let 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)
|
||||
}
|
||||
init(statusLoader: HealthChatAccountStatusLoader) {
|
||||
self.statusLoader = statusLoader
|
||||
}
|
||||
|
||||
func accountStatusSection(completeProfileAction: @escaping () -> Void) -> AnyView? {
|
||||
guard let statusLoader else {
|
||||
return nil
|
||||
}
|
||||
return AnyView(HealthChatAccountStatusSection(loader: statusLoader,
|
||||
completeProfileAction: completeProfileAction))
|
||||
AnyView(HealthChatAccountStatusSection(loader: statusLoader,
|
||||
completeProfileAction: completeProfileAction))
|
||||
}
|
||||
|
||||
func refreshAccountStatus() {
|
||||
statusLoader?.load()
|
||||
statusLoader.load()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// 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
|
||||
/// Builds the HealthChat session-scoped hooks when a user session is created.
|
||||
nonisolated struct HealthChatUserSessionHook: UserSessionHookProtocol {
|
||||
func makeUserHooks(for clientProxy: ClientProxyProtocol) -> UserHooks {
|
||||
let apiService = HealthChatAPIService(tokenProvider: HealthChatOpenIDTokenProvider(clientProxy: clientProxy))
|
||||
return UserHooks(extendedProfileSectionHook: HealthChatExtendedProfileSectionHook(extendedProfileService: ExtendedProfileService(clientProxy: clientProxy)),
|
||||
settingsScreenHook: HealthChatSettingsScreenHook(statusLoader: HealthChatAccountStatusLoader(apiService: apiService)))
|
||||
}
|
||||
|
||||
func configure(_ userSettings: UserSettings, forHomeserver homeserver: String) -> UserSettings {
|
||||
userSettings
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user