Files
element-x-ios/ElementX/Sources/Screens/HealthChatMemberDirectoryScreen/View/HealthChatMemberDirectoryScreen.swift
T
joel.poyet b475cc7e9a Let members edit their profile and invite others (#12)
* 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

* Add a member directory tab

Add a HomeTabsHook that lets the fork append an extra tab to the home
tab bar, and a HealthChat members flow behind it: a directory of all
approved members from the HealthChat API with server-side search,
pending-approval and error states, chat shortcuts and pushed member
profiles. Chats and calls are handed back to the session flow via the
hook's actions publisher.

Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS

* Let members edit their profile and invite others

Add a native profile editor for the HealthChat extended profile fields
(13 fields plus avatar, saved as a partial diff through the HealthChat
API so displayname derivation and Zitadel sync stay server-side), an
invitation sheet (email plus personal note) and a profile-completeness
hint on the member directory.

A new UserDetailsEditScreenHook lets the fork substitute the profile
editor behind the settings user row — the stock display-name editor
would let users edit a value the next profile update derives away.

Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS
2026-09-22 18:27:37 +02:00

218 lines
9.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// 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
struct HealthChatMemberDirectoryScreen: View {
@Bindable var context: HealthChatMemberDirectoryScreenViewModel.Context
var body: some View {
content
.navigationTitle(HealthChatL10n.screenMemberDirectoryTitle)
.navigationBarTitleDisplayMode(.inline)
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.searchController(query: $context.searchQuery,
placeholder: HealthChatL10n.screenMemberDirectorySearchPlaceholder)
.toolbar { toolbar }
.alert(item: $context.alertInfo)
}
@ToolbarContentBuilder
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .primaryAction) {
Button {
context.send(viewAction: .editProfile)
} label: {
CompoundIcon(\.edit)
}
.accessibilityLabel(L10n.screenEditProfileTitle)
}
if context.viewState.isApproved {
ToolbarItem(placement: .primaryAction) {
Button {
context.send(viewAction: .invite)
} label: {
CompoundIcon(\.userAdd)
}
.accessibilityLabel(HealthChatL10n.screenInviteMemberTitle)
}
}
}
// MARK: - Private
@ViewBuilder
private var content: some View {
switch context.viewState.content {
case .loading:
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
case .pendingApproval(let message):
statusView(icon: \.time, message: message)
case .failure:
failureView
case .members(let members) where members.isEmpty:
statusView(icon: \.search, message: L10n.commonNoResults)
case .members(let members):
memberList(members)
}
}
private func memberList(_ members: [HealthChatMember]) -> some View {
Form {
if let completenessMessage = context.viewState.completenessMessage {
Section {
ListRow(label: .default(title: completenessMessage, icon: \.info),
kind: .button {
context.send(viewAction: .editProfile)
})
}
}
Section {
ForEach(members) { member in
HealthChatMemberListRow(member: member, mediaProvider: context.mediaProvider) {
context.send(viewAction: .selectMember(member))
} startChatAction: {
context.send(viewAction: .startChat(member))
}
}
}
}
.compoundList()
}
private var failureView: some View {
VStack(spacing: 16) {
statusContent(icon: \.error, message: L10n.commonSomethingWentWrong)
Button(L10n.actionRetry) {
context.send(viewAction: .retry)
}
.buttonStyle(.compound(.secondary, size: .medium))
.fixedSize()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(16)
}
private func statusView(icon: KeyPath<CompoundIcons, Image>, message: String) -> some View {
statusContent(icon: icon, message: message)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(16)
}
private func statusContent(icon: KeyPath<CompoundIcons, Image>, message: String) -> some View {
VStack(spacing: 16) {
BigIcon(icon: icon)
Text(message)
.font(.compound.bodyLG)
.foregroundColor(.compound.textSecondary)
.multilineTextAlignment(.center)
}
}
}
// MARK: - Previews
struct HealthChatMemberDirectoryScreen_Previews: PreviewProvider, TestablePreview {
static let loadedViewModel = makeViewModel(configuration: .members)
static let incompleteProfileViewModel = makeViewModel(configuration: .incompleteProfile)
static let pendingViewModel = makeViewModel(configuration: .pendingApproval)
static let failureViewModel = makeViewModel(configuration: .failure)
static var previews: some View {
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: loadedViewModel.context)
}
.snapshotPreferences(expect: loadedViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Members")
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: incompleteProfileViewModel.context)
}
.snapshotPreferences(expect: incompleteProfileViewModel.context.observe(\.viewState.completenessMessage).map { $0 != nil })
.previewDisplayName("Incomplete profile")
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: pendingViewModel.context)
}
.snapshotPreferences(expect: pendingViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Pending approval")
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: failureViewModel.context)
}
.snapshotPreferences(expect: failureViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Failure")
}
enum PreviewConfiguration {
case members
case incompleteProfile
case pendingApproval
case failure
}
static func makeViewModel(configuration: PreviewConfiguration) -> HealthChatMemberDirectoryScreenViewModel {
let apiService = HealthChatAPIServiceMock()
switch configuration {
case .members:
let members = try? JSONDecoder().decode([HealthChatMember].self, from: Data("""
[
{
"userId": "@alice:healthchat.ch",
"displayName": "Dr. Alice Alpha",
"specialty": "Physiotherapie",
"practiceName": "Praxis Alpha",
"businessCity": "Zürich"
},
{
"userId": "@bob:healthchat.ch",
"displayName": "Bob Beta",
"specialty": "Ergotherapie",
"businessCity": "Basel"
},
{
"userId": "@carol:healthchat.ch",
"displayName": "Dr. Carol Gamma"
}
]
""".utf8))
apiService.membersSearchQueryReturnValue = .success(.init(users: members ?? [],
isApproved: true,
pendingMessage: nil))
apiService.profileCompletenessReturnValue = try? .success(JSONDecoder().decode(HealthChatProfileCompleteness.self,
from: Data(#"{ "isComplete": true }"#.utf8)))
case .incompleteProfile:
let member = try? JSONDecoder().decode(HealthChatMember.self, from: Data("""
{ "userId": "@alice:healthchat.ch", "displayName": "Dr. Alice Alpha", "specialty": "Physiotherapie" }
""".utf8))
apiService.membersSearchQueryReturnValue = .success(.init(users: member.map { [$0] } ?? [],
isApproved: true,
pendingMessage: nil))
apiService.profileCompletenessReturnValue = try? .success(JSONDecoder().decode(HealthChatProfileCompleteness.self,
from: Data(#"{ "isComplete": false, "message": "Profil unvollständig – Fehlende Angaben: Fachgebiet, Ort" }"#.utf8)))
case .pendingApproval:
apiService.membersSearchQueryReturnValue = .success(.init(users: [],
isApproved: false,
pendingMessage: "Ihr Konto wird derzeit geprüft. Sie erhalten Zugriff auf das Mitgliederverzeichnis, sobald Ihr Konto freigegeben wurde."))
case .failure:
apiService.membersSearchQueryReturnValue = .failure(.networkFailure)
}
return HealthChatMemberDirectoryScreenViewModel(apiService: apiService,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MediaProviderMock(.init()),
userIndicatorController: UserIndicatorControllerMock())
}
}