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:
2026-09-22 17:02:26 +02:00
parent 00f08ab2dc
commit 352d25f2bb
30 changed files with 466 additions and 2 deletions
@@ -0,0 +1,9 @@
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
"common_academic_title" = "Titel";
"common_address" = "Adresse";
"common_business_email" = "E-Mail (geschäftlich)";
"common_business_tel" = "Telefon (geschäftlich)";
"common_further_info" = "Weitere Infos / Qualifikationen";
"common_practice_name" = "Praxisname / Firmenname";
"common_specialty" = "Fachgebiet";
"common_website" = "Webseite";
@@ -0,0 +1,9 @@
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
"common_academic_title" = "Title";
"common_address" = "Address";
"common_business_email" = "Business email";
"common_business_tel" = "Business phone";
"common_further_info" = "Further infos / qualifications";
"common_practice_name" = "Practice name";
"common_specialty" = "Speciality";
"common_website" = "Website";
@@ -0,0 +1,9 @@
// HealthChat fork strings. Not managed by Localazy — edit all three languages by hand.
"common_academic_title" = "Titre";
"common_address" = "Adresse";
"common_business_email" = "Email (professionnel)";
"common_business_tel" = "Téléphone (professionnel)";
"common_further_info" = "Informations supplémentaires / qualifications";
"common_practice_name" = "Nom de l’entreprise";
"common_specialty" = "Spécialisation";
"common_website" = "Site web";
+5 -1
View File
@@ -14,6 +14,7 @@ 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())
@@ -42,7 +43,10 @@ final nonisolated class AppHooks: AppHooksProtocol {
@AppHook(default: DefaultUserProfileScreenHook())
var userProfileScreenHook: UserProfileScreenHookProtocol
@AppHook(default: DefaultExtendedProfileSectionHook())
var extendedProfileSectionHook: ExtendedProfileSectionHookProtocol
@AppHook(default: DefaultDeveloperOptionsScreenHook())
var developerOptionsScreenHook: DeveloperOptionsScreenHookProtocol
@@ -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
}
}
@@ -0,0 +1,61 @@
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
import Foundation
// swiftlint:disable superfluous_disable_command file_length implicit_return
// MARK: - Strings
// 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 {
/// Title
internal static var commonAcademicTitle: String { return HealthChatL10n.tr("HealthChat", "common_academic_title") }
/// Address
internal static var commonAddress: String { return HealthChatL10n.tr("HealthChat", "common_address") }
/// Business email
internal static var commonBusinessEmail: String { return HealthChatL10n.tr("HealthChat", "common_business_email") }
/// Business phone
internal static var commonBusinessTel: String { return HealthChatL10n.tr("HealthChat", "common_business_tel") }
/// Further infos / qualifications
internal static var commonFurtherInfo: String { return HealthChatL10n.tr("HealthChat", "common_further_info") }
/// Practice name
internal static var commonPracticeName: String { return HealthChatL10n.tr("HealthChat", "common_practice_name") }
/// Speciality
internal static var commonSpecialty: String { return HealthChatL10n.tr("HealthChat", "common_specialty") }
/// Website
internal static var commonWebsite: String { return HealthChatL10n.tr("HealthChat", "common_website") }
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
// MARK: - Implementation Details
nonisolated extension HealthChatL10n {
static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
// Use preferredLocalizations to get a language that is in the bundle and the user's preferred list of languages.
let languages = Bundle.overrideLocalizations ?? Bundle.app.preferredLocalizations
for language in languages {
if let translation = trIn(language, table, key, args) {
return translation
}
}
return Bundle.app.developmentLocalization.flatMap { trIn($0, table, key, args) } ?? key
}
private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String? {
guard let bundle = Bundle.lprojBundle(for: language) else { return nil }
let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "")
let translation = String(format: format, locale: Locale(identifier: language), arguments: args)
guard translation != key,
translation != "\(key) \(key)" // Handle double pseudo for tests
else {
return nil
}
return translation
}
}
// swiftlint:enable all
@@ -56,6 +56,7 @@ enum TestablePreviewsDictionary {
"FormattingToolbar_Previews" : FormattingToolbar_Previews.self,
"FullscreenDialog_Previews" : FullscreenDialog_Previews.self,
"GalleryRoomTimelineView_Previews" : GalleryRoomTimelineView_Previews.self,
"HealthChatExtendedProfileSection_Previews" : HealthChatExtendedProfileSection_Previews.self,
"HighlightedTimelineItemModifier_Previews" : HighlightedTimelineItemModifier_Previews.self,
"HomeScreenEmptyStateView_Previews" : HomeScreenEmptyStateView_Previews.self,
"HomeScreenInviteCell_Previews" : HomeScreenInviteCell_Previews.self,
@@ -17,6 +17,7 @@ enum RoomMemberDetailsScreenViewModelAction {
struct RoomMemberDetailsScreenViewState: BindableState {
let userID: String
let appHooks: AppHooks
var memberDetails: RoomMemberDetails?
var verificationState: UserIdentityVerificationState?
var isOwnMemberDetails = false
@@ -36,7 +36,7 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro
self.userIndicatorController = userIndicatorController
self.analytics = analytics
let initialViewState = RoomMemberDetailsScreenViewState(userID: userID, bindings: .init())
let initialViewState = RoomMemberDetailsScreenViewState(userID: userID, appHooks: appHooks, bindings: .init())
super.init(initialViewState: appHooks.roomMemberDetailsScreenHook.update(initialViewState),
mediaProvider: userSession.mediaProvider)
@@ -16,6 +16,8 @@ struct RoomMemberDetailsScreen: View {
Form {
headerSection
context.viewState.appHooks.extendedProfileSectionHook.extendedProfileSection(userID: context.viewState.userID)
if context.viewState.showVerifyIdentitySection {
verificationSection
}
@@ -18,6 +18,7 @@ struct UserProfileScreenViewState: BindableState {
let userID: String
let isOwnUser: Bool
let isPresentedModally: Bool
let appHooks: AppHooks
var userProfile: UserProfile?
var isIdentityKnown = false
@@ -35,6 +35,7 @@ class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScr
let initialViewState = UserProfileScreenViewState(userID: userID,
isOwnUser: userID == userSession.clientProxy.userID,
isPresentedModally: isPresentedModally,
appHooks: appHooks,
bindings: .init())
super.init(initialViewState: appHooks.userProfileScreenHook.update(initialViewState),
@@ -15,6 +15,8 @@ struct UserProfileScreen: View {
var body: some View {
Form {
headerSection
context.viewState.appHooks.extendedProfileSectionHook.extendedProfileSection(userID: context.viewState.userID)
}
.compoundList()
.navigationTitle(L10n.screenRoomMemberDetailsTitle)