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
This commit is contained in:
2026-09-22 17:04:37 +02:00
parent 93149f1cbd
commit b475cc7e9a
47 changed files with 1595 additions and 17 deletions
@@ -0,0 +1,49 @@
//
// 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 Combine
import SwiftUI
struct HealthChatInviteMemberScreenCoordinatorParameters {
let apiService: HealthChatAPIServiceProtocol
let userIndicatorController: UserIndicatorControllerProtocol
}
enum HealthChatInviteMemberScreenCoordinatorAction {
case dismiss
}
final class HealthChatInviteMemberScreenCoordinator: CoordinatorProtocol {
private let viewModel: HealthChatInviteMemberScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<HealthChatInviteMemberScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<HealthChatInviteMemberScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: HealthChatInviteMemberScreenCoordinatorParameters) {
viewModel = HealthChatInviteMemberScreenViewModel(apiService: parameters.apiService,
userIndicatorController: parameters.userIndicatorController)
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .dismiss:
actionsSubject.send(.dismiss)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(HealthChatInviteMemberScreen(context: viewModel.context))
}
}
@@ -0,0 +1,49 @@
//
// 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
enum HealthChatInviteMemberScreenViewModelAction {
case dismiss
}
struct HealthChatInviteMemberScreenViewState: BindableState {
/// The backend requires a personal note of at least this many characters.
static let minimumNoteLength = 10
var bindings = HealthChatInviteMemberScreenViewStateBindings()
var canSend: Bool {
isEmailValid && isNoteValid
}
var isEmailValid: Bool {
let email = bindings.email.trimmingCharacters(in: .whitespaces)
let components = email.split(separator: "@")
return components.count == 2 && components[1].contains(".")
}
var isNoteValid: Bool {
bindings.personalNote.trimmingCharacters(in: .whitespacesAndNewlines).count >= Self.minimumNoteLength
}
}
struct HealthChatInviteMemberScreenViewStateBindings {
var email = ""
var personalNote = ""
var alertInfo: AlertInfo<HealthChatInviteMemberScreenAlertType>?
}
enum HealthChatInviteMemberScreenAlertType: Hashable {
case sendFailed
}
enum HealthChatInviteMemberScreenViewAction {
case send
case cancel
}
@@ -0,0 +1,63 @@
//
// 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 Combine
import SwiftUI
typealias HealthChatInviteMemberScreenViewModelType = StateStoreViewModelV2<HealthChatInviteMemberScreenViewState, HealthChatInviteMemberScreenViewAction>
class HealthChatInviteMemberScreenViewModel: HealthChatInviteMemberScreenViewModelType, HealthChatInviteMemberScreenViewModelProtocol {
private let apiService: HealthChatAPIServiceProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
private let actionsSubject: PassthroughSubject<HealthChatInviteMemberScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<HealthChatInviteMemberScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(apiService: HealthChatAPIServiceProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.apiService = apiService
self.userIndicatorController = userIndicatorController
super.init(initialViewState: HealthChatInviteMemberScreenViewState(), mediaProvider: nil)
}
// MARK: - Public
override func process(viewAction: HealthChatInviteMemberScreenViewAction) {
switch viewAction {
case .send:
Task { await sendInvitation() }
case .cancel:
actionsSubject.send(.dismiss)
}
}
// MARK: - Private
private func sendInvitation() async {
let indicatorID = "\(Self.self)-Sending"
defer { userIndicatorController.retractIndicatorWithId(indicatorID) }
userIndicatorController.submitIndicator(UserIndicator(id: indicatorID,
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
title: L10n.commonLoading,
persistent: true),
delay: .milliseconds(100))
let email = state.bindings.email.trimmingCharacters(in: .whitespaces)
let personalNote = state.bindings.personalNote.trimmingCharacters(in: .whitespacesAndNewlines)
switch await apiService.inviteMember(email: email, personalNote: personalNote) {
case .success:
userIndicatorController.submitIndicator(UserIndicator(title: HealthChatL10n.screenInviteMemberSuccess, icon: \.check))
actionsSubject.send(.dismiss)
case .failure:
state.bindings.alertInfo = .init(id: .sendFailed)
}
}
}
@@ -0,0 +1,14 @@
//
// 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 Combine
@MainActor
protocol HealthChatInviteMemberScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<HealthChatInviteMemberScreenViewModelAction, Never> { get }
var context: HealthChatInviteMemberScreenViewModelType.Context { get }
}
@@ -0,0 +1,71 @@
//
// 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 HealthChatInviteMemberScreen: View {
@Bindable var context: HealthChatInviteMemberScreenViewModel.Context
var body: some View {
Form {
Section {
ListRow(label: .plain(title: HealthChatL10n.screenInviteMemberEmailPlaceholder),
kind: .textField(text: $context.email, axis: .horizontal))
.keyboardType(.emailAddress)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
}
Section {
ListRow(label: .plain(title: HealthChatL10n.screenInviteMemberNotePlaceholder),
kind: .textField(text: $context.personalNote, axis: .vertical))
.lineLimit(4...)
} footer: {
Text(HealthChatL10n.screenInviteMemberNoteFooter)
.compoundListSectionFooter()
}
}
.compoundList()
.scrollDismissesKeyboard(.immediately)
.navigationTitle(HealthChatL10n.screenInviteMemberTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar { toolbar }
.alert(item: $context.alertInfo)
}
// MARK: - Private
@ToolbarContentBuilder
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel) {
context.send(viewAction: .cancel)
}
}
ToolbarItem(placement: .confirmationAction) {
Button(L10n.actionSend) {
context.send(viewAction: .send)
}
.disabled(!context.viewState.canSend)
}
}
}
// MARK: - Previews
struct HealthChatInviteMemberScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = HealthChatInviteMemberScreenViewModel(apiService: HealthChatAPIServiceMock(),
userIndicatorController: UserIndicatorControllerMock())
static var previews: some View {
ElementNavigationStack {
HealthChatInviteMemberScreen(context: viewModel.context)
}
.previewDisplayName("Invite")
}
}