mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Show extended profile details on the profile screens (#10)
* Add HealthChat API and extended profile services Expose OpenID tokens and homeserver credentials from the client proxy, and add fork-only services for the HealthChat member directory backend (api.healthchat.ch) plus a service that reads MSC4133 extended profile fields directly from the homeserver. Groundwork for the members tab and the profile screens. Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS * Show extended profile details on the profile screens Add a UserProfileScreenHook that lets the fork inject an extra Form section below the header of the user profile and room member details screens. The HealthChat implementation loads the MSC4133 extended profile fields and renders them with tappable phone/email/website links, hiding the section entirely for profiles without any fields. Strings live in a new fork-only HealthChat.strings table (de/en/fr, generated as HealthChatL10n via SwiftGen) since Untranslated.strings pins the English bundle. Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS
This commit is contained in:
@@ -12,6 +12,11 @@ import Synchronization
|
||||
|
||||
final nonisolated class AppHooks: AppHooksProtocol {
|
||||
#if IS_MAIN_APP
|
||||
func configure(with userSession: UserSessionProtocol?) async {
|
||||
await userSessionHook.configure(with: userSession)
|
||||
await extendedProfileSectionHook.configure(with: userSession)
|
||||
}
|
||||
|
||||
@AppHook(default: DefaultAppSettingsHook())
|
||||
var appSettingsHook: AppSettingsHookProtocol
|
||||
|
||||
@@ -24,8 +29,29 @@ final nonisolated class AppHooks: AppHooksProtocol {
|
||||
@AppHook(default: DefaultOAuthPresenterHook())
|
||||
var oAuthPresenterHook: OAuthPresenterHookProtocol
|
||||
|
||||
@AppHook(default: DefaultUserSessionHook())
|
||||
var userSessionHook: UserSessionHookProtocol
|
||||
|
||||
@AppHook(default: DefaultRoomScreenHook())
|
||||
var roomScreenHook: RoomScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultRoomDetailsScreenHook())
|
||||
var roomDetailsScreenHook: RoomDetailsScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultRoomMemberDetailsScreenHook())
|
||||
var roomMemberDetailsScreenHook: RoomMemberDetailsScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultUserProfileScreenHook())
|
||||
var userProfileScreenHook: UserProfileScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultExtendedProfileSectionHook())
|
||||
var extendedProfileSectionHook: ExtendedProfileSectionHookProtocol
|
||||
|
||||
@AppHook(default: DefaultDeveloperOptionsScreenHook())
|
||||
var developerOptionsScreenHook: DeveloperOptionsScreenHookProtocol
|
||||
|
||||
@AppHook(default: DefaultRecoveryKeyScreenHook())
|
||||
var recoveryKeyScreenHook: RecoveryKeyScreenHookProtocol
|
||||
#endif
|
||||
|
||||
@AppHook(default: DefaultTracingHook())
|
||||
@@ -36,9 +62,6 @@ final nonisolated class AppHooks: AppHooksProtocol {
|
||||
|
||||
@AppHook(default: DefaultRemoteSettingsHook())
|
||||
var remoteSettingsHook: RemoteSettingsHookProtocol
|
||||
|
||||
@AppHook(default: DefaultUserSessionHook())
|
||||
var userSessionHook: UserSessionHookProtocol
|
||||
}
|
||||
|
||||
nonisolated protocol AppHooksProtocol: Sendable {
|
||||
|
||||
@@ -16,6 +16,7 @@ extension AppHooks {
|
||||
#if IS_MAIN_APP
|
||||
registerAppSettingsHook(HealthChatAppSettingsHook())
|
||||
registerCompoundHook(HealthChatCompoundHook())
|
||||
registerExtendedProfileSectionHook(HealthChatExtendedProfileSectionHook())
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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 a user's extended profile for display, hiding profiles without any HealthChat fields.
|
||||
@Observable
|
||||
final class HealthChatExtendedProfileLoader {
|
||||
private(set) var profile: ExtendedProfile?
|
||||
|
||||
/// The load kicked off on creation — await this in tests before asserting.
|
||||
@ObservationIgnored private(set) var loadingTask: Task<Void, Never>?
|
||||
|
||||
init(userID: String, service: ExtendedProfileServiceProtocol) {
|
||||
loadingTask = Task {
|
||||
guard case let .success(profile) = await service.profile(for: userID), profile.hasContent else {
|
||||
return
|
||||
}
|
||||
self.profile = profile
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a loader with a fixed result, for previews.
|
||||
init(profile: ExtendedProfile?) {
|
||||
self.profile = profile
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
//
|
||||
// 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 HealthChat profile fields shown below the header on the profile screens.
|
||||
/// Renders nothing while loading and for profiles without any HealthChat fields.
|
||||
struct HealthChatExtendedProfileSection: View {
|
||||
@State private var loader: HealthChatExtendedProfileLoader
|
||||
|
||||
init(userID: String, service: ExtendedProfileServiceProtocol) {
|
||||
_loader = State(initialValue: HealthChatExtendedProfileLoader(userID: userID, service: service))
|
||||
}
|
||||
|
||||
init(loader: HealthChatExtendedProfileLoader) {
|
||||
_loader = State(initialValue: loader)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let profile = loader.profile {
|
||||
Section {
|
||||
if let title = profile.title {
|
||||
row(label: HealthChatL10n.commonAcademicTitle, value: title)
|
||||
}
|
||||
if let specialty = profile.specialty {
|
||||
row(label: HealthChatL10n.commonSpecialty, value: specialty)
|
||||
}
|
||||
if let practiceName = profile.practiceName {
|
||||
row(label: HealthChatL10n.commonPracticeName, value: practiceName)
|
||||
}
|
||||
if let address = profile.formattedAddress {
|
||||
row(label: HealthChatL10n.commonAddress, value: address)
|
||||
}
|
||||
if let businessEmail = profile.businessEmail {
|
||||
linkRow(label: HealthChatL10n.commonBusinessEmail,
|
||||
value: businessEmail,
|
||||
url: URL(string: "mailto:\(businessEmail)"))
|
||||
}
|
||||
if let businessTel = profile.businessTel {
|
||||
linkRow(label: HealthChatL10n.commonBusinessTel,
|
||||
value: businessTel,
|
||||
url: URL(string: "tel:\(businessTel.filter { !$0.isWhitespace })"))
|
||||
}
|
||||
if let website = profile.website {
|
||||
linkRow(label: HealthChatL10n.commonWebsite,
|
||||
value: website,
|
||||
url: websiteURL(for: website))
|
||||
}
|
||||
if let furtherInfo = profile.furtherInfo {
|
||||
row(label: HealthChatL10n.commonFurtherInfo, value: furtherInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func row(label: String, value: String) -> some View {
|
||||
ListRow(kind: .custom {
|
||||
rowContent(label: label, value: value, valueColor: .compound.textPrimary)
|
||||
})
|
||||
}
|
||||
|
||||
private func linkRow(label: String, value: String, url: URL?) -> some View {
|
||||
ListRow(kind: .custom {
|
||||
Button {
|
||||
guard let url else { return }
|
||||
UIApplication.shared.open(url)
|
||||
} label: {
|
||||
rowContent(label: label, value: value, valueColor: .compound.textLinkExternal)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private func rowContent(label: String, value: String, valueColor: Color) -> some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(label)
|
||||
.font(.compound.bodySM)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
Text(value)
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundColor(valueColor)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal, ListRowPadding.horizontal)
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
private func websiteURL(for website: String) -> URL? {
|
||||
guard let url = URL(string: website) else {
|
||||
return nil
|
||||
}
|
||||
return url.scheme == nil ? URL(string: "https://\(website)") : url
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct HealthChatExtendedProfileSection_Previews: PreviewProvider, TestablePreview {
|
||||
static let fullProfile = try? JSONDecoder().decode(ExtendedProfile.self, from: Data("""
|
||||
{
|
||||
"displayname": "Dr. Alice Alpha",
|
||||
"io.element.profile.title": "Dr. med.",
|
||||
"io.element.profile.specialization": "Physiotherapie",
|
||||
"io.element.profile.practice_name": "Praxis Alpha",
|
||||
"io.element.profile.business_street": "Friedaustrasse",
|
||||
"io.element.profile.business_street_nr": "17",
|
||||
"io.element.profile.business_plz": "8003",
|
||||
"io.element.profile.business_city": "Zürich",
|
||||
"io.element.profile.business_email": "praxis@example.ch",
|
||||
"io.element.profile.business_tel": "+41 44 123 45 67",
|
||||
"io.element.profile.website": "https://example.ch",
|
||||
"io.element.profile.further_info": "Krankenkassen-anerkannt\\nHausbesuche möglich"
|
||||
}
|
||||
""".utf8))
|
||||
|
||||
static let contactOnlyProfile = try? JSONDecoder().decode(ExtendedProfile.self, from: Data("""
|
||||
{ "io.element.profile.business_tel": "+41 44 123 45 67" }
|
||||
""".utf8))
|
||||
|
||||
static var previews: some View {
|
||||
Form {
|
||||
HealthChatExtendedProfileSection(loader: .init(profile: fullProfile))
|
||||
}
|
||||
.compoundList()
|
||||
.previewDisplayName("Full profile")
|
||||
|
||||
Form {
|
||||
HealthChatExtendedProfileSection(loader: .init(profile: contactOnlyProfile))
|
||||
}
|
||||
.compoundList()
|
||||
.previewDisplayName("Contact only")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// 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 HealthChatExtendedProfileSectionHook: ExtendedProfileSectionHookProtocol {
|
||||
private var 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) }
|
||||
}
|
||||
|
||||
func extendedProfileSection(userID: String) -> AnyView? {
|
||||
guard let extendedProfileService else {
|
||||
return nil
|
||||
}
|
||||
return AnyView(HealthChatExtendedProfileSection(userID: userID, service: extendedProfileService))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// 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 ExtendedProfileSectionHookProtocol: Sendable {
|
||||
@MainActor func configure(with userSession: UserSessionProtocol?) async
|
||||
|
||||
/// An extra Form section rendered below the header on the user profile
|
||||
/// and room member details screens.
|
||||
@MainActor func extendedProfileSection(userID: String) -> AnyView?
|
||||
}
|
||||
|
||||
struct DefaultExtendedProfileSectionHook: ExtendedProfileSectionHookProtocol {
|
||||
func configure(with userSession: UserSessionProtocol?) async { }
|
||||
|
||||
func extendedProfileSection(userID: String) -> AnyView? {
|
||||
nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user