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
committed by Sedat Qaja
parent c0f167ccf7
commit 209a36cbea
47 changed files with 1631 additions and 86 deletions
@@ -0,0 +1,76 @@
//
// 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.
//
@testable import ElementX
import Foundation
import Testing
final class HealthChatInviteMemberScreenViewModelTests {
private let apiService = HealthChatAPIServiceMock()
private let viewModel: HealthChatInviteMemberScreenViewModel
init() {
viewModel = HealthChatInviteMemberScreenViewModel(apiService: apiService,
userIndicatorController: UserIndicatorControllerMock())
}
@Test
func sendingRequiresValidEmailAndNote() {
#expect(!viewModel.context.viewState.canSend)
viewModel.context.email = "new@example.ch"
viewModel.context.personalNote = "Zu kurz"
#expect(!viewModel.context.viewState.canSend)
viewModel.context.personalNote = "Bitte tritt unserem Netzwerk bei!"
#expect(viewModel.context.viewState.canSend)
viewModel.context.email = "not-an-email"
#expect(!viewModel.context.viewState.canSend)
}
@Test
func sendSuccessDismisses() async throws {
apiService.inviteMemberEmailPersonalNoteReturnValue = .success(())
viewModel.context.email = "new@example.ch"
viewModel.context.personalNote = "Bitte tritt unserem Netzwerk bei!"
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
guard case .dismiss = action else { return false }
return true
}
viewModel.context.send(viewAction: .send)
try await deferred.fulfill()
let arguments = try #require(apiService.inviteMemberEmailPersonalNoteReceivedArguments)
#expect(arguments.email == "new@example.ch")
#expect(arguments.personalNote == "Bitte tritt unserem Netzwerk bei!")
}
@Test
func sendFailureShowsAlert() async throws {
apiService.inviteMemberEmailPersonalNoteReturnValue = .failure(.networkFailure)
viewModel.context.email = "new@example.ch"
viewModel.context.personalNote = "Bitte tritt unserem Netzwerk bei!"
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.bindings.alertInfo)) { $0 != nil }
viewModel.context.send(viewAction: .send)
try await deferred.fulfill()
}
@Test
func cancelDismisses() async throws {
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
guard case .dismiss = action else { return false }
return true
}
viewModel.context.send(viewAction: .cancel)
try await deferred.fulfill()
}
}
@@ -13,6 +13,10 @@ final class HealthChatMemberDirectoryScreenViewModelTests {
private let apiService = HealthChatAPIServiceMock()
private let clientProxy = ClientProxyMock(.init())
init() throws {
apiService.profileCompletenessReturnValue = try .success(makeCompleteness(isComplete: true, message: nil))
}
@Test
func loadsMembersOnStart() async throws {
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
@@ -126,8 +130,89 @@ final class HealthChatMemberDirectoryScreenViewModelTests {
try await deferred.fulfill()
}
@Test
func showsCompletenessHintWhenProfileIsIncomplete() async throws {
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
apiService.profileCompletenessReturnValue = try .success(makeCompleteness(isComplete: false,
message: "Profil unvollständig"))
let viewModel = makeViewModel()
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.completenessMessage)) { $0 == "Profil unvollständig" }
try await deferred.fulfill()
#expect(viewModel.context.viewState.isApproved)
}
@Test
func hidesCompletenessHintWhenProfileIsComplete() async throws {
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: ["@alice:healthchat.ch"]))
let viewModel = makeViewModel()
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
guard case .members = content else { return false }
return true
}
try await deferred.fulfill()
#expect(viewModel.context.viewState.completenessMessage == nil)
}
@Test
func pendingApprovalDisablesInviting() async throws {
apiService.membersSearchQueryReturnValue = .success(.init(users: [],
isApproved: false,
pendingMessage: "Ihr Konto wird geprüft"))
let viewModel = makeViewModel()
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.content)) { content in
guard case .pendingApproval = content else { return false }
return true
}
try await deferred.fulfill()
#expect(!viewModel.context.viewState.isApproved)
}
@Test
func editProfileEmitsAction() async throws {
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: []))
let viewModel = makeViewModel()
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
guard case .editProfile = action else { return false }
return true
}
viewModel.context.send(viewAction: .editProfile)
try await deferred.fulfill()
}
@Test
func inviteEmitsAction() async throws {
apiService.membersSearchQueryReturnValue = try .success(makeResponse(userIDs: []))
let viewModel = makeViewModel()
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
guard case .invite = action else { return false }
return true
}
viewModel.context.send(viewAction: .invite)
try await deferred.fulfill()
}
// MARK: - Helpers
private func makeCompleteness(isComplete: Bool, message: String?) throws -> HealthChatProfileCompleteness {
let messageJSON = message.map { "\"\($0)\"" } ?? "null"
return try JSONDecoder().decode(HealthChatProfileCompleteness.self, from: Data("""
{ "isComplete": \(isComplete), "message": \(messageJSON) }
""".utf8))
}
private func makeViewModel() -> HealthChatMemberDirectoryScreenViewModel {
HealthChatMemberDirectoryScreenViewModel(apiService: apiService,
clientProxy: clientProxy,
@@ -0,0 +1,140 @@
//
// 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.
//
@testable import ElementX
import Foundation
import Testing
final class HealthChatProfileEditScreenViewModelTests {
private let apiService = HealthChatAPIServiceMock()
private let clientProxy = ClientProxyMock(.init())
@Test
func loadsProfileIntoBindings() async throws {
apiService.ownProfileReturnValue = try .success(makeProfile())
let viewModel = makeViewModel()
try await waitForLoad(of: viewModel)
#expect(viewModel.context.firstName == "Alice")
#expect(viewModel.context.businessTel == "+41 44 123 45 67")
#expect(viewModel.context.furtherInfo == "Old info")
#expect(viewModel.context.viewState.canEditAvatar)
#expect(!viewModel.context.viewState.canSave)
}
@Test
func saveSendsOnlyChangedFields() async throws {
apiService.ownProfileReturnValue = try .success(makeProfile())
apiService.updateOwnProfileReturnValue = .success(())
let viewModel = makeViewModel()
try await waitForLoad(of: viewModel)
viewModel.context.businessTel = "+41 79 111 22 33"
viewModel.context.furtherInfo = ""
let deferred = deferFulfillment(viewModel.actionsPublisher) { action in
guard case .dismiss = action else { return false }
return true
}
viewModel.context.send(viewAction: .save)
try await deferred.fulfill()
let update = try #require(apiService.updateOwnProfileReceivedUpdate)
#expect(update.businessTel == "+41 79 111 22 33")
#expect(update.furtherInfo == "")
#expect(update.firstName == nil)
#expect(update.title == nil)
}
@Test
func missingRequiredFieldBlocksSaving() async throws {
apiService.ownProfileReturnValue = try .success(makeProfile())
let viewModel = makeViewModel()
try await waitForLoad(of: viewModel)
viewModel.context.firstName = " "
#expect(!viewModel.context.viewState.canSave)
}
@Test
func saveFailureShowsAlert() async throws {
apiService.ownProfileReturnValue = try .success(makeProfile())
apiService.updateOwnProfileReturnValue = .failure(.networkFailure)
let viewModel = makeViewModel()
try await waitForLoad(of: viewModel)
viewModel.context.businessTel = "+41 79 111 22 33"
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.bindings.alertInfo)) { $0 != nil }
viewModel.context.send(viewAction: .save)
try await deferred.fulfill()
}
@Test
func cancelWithChangesShowsUnsavedChangesAlert() async throws {
apiService.ownProfileReturnValue = try .success(makeProfile())
let viewModel = makeViewModel()
try await waitForLoad(of: viewModel)
viewModel.context.businessTel = "+41 79 111 22 33"
viewModel.context.send(viewAction: .cancel)
#expect(viewModel.context.viewState.bindings.alertInfo != nil)
}
@Test
func loadFailureOffersRetry() async throws {
apiService.ownProfileReturnValue = .failure(.networkFailure)
let viewModel = makeViewModel()
let deferredFailure = deferFulfillment(viewModel.context.observe(\.viewState.loadFailed)) { $0 }
try await deferredFailure.fulfill()
apiService.ownProfileReturnValue = try .success(makeProfile())
let deferredLoad = deferFulfillment(viewModel.context.observe(\.viewState.initialProfile)) { $0 != nil }
viewModel.context.send(viewAction: .retry)
try await deferredLoad.fulfill()
}
// MARK: - Helpers
private func makeViewModel() -> HealthChatProfileEditScreenViewModel {
HealthChatProfileEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
apiService: apiService,
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: .volatile()),
userIndicatorController: UserIndicatorControllerMock())
}
private func waitForLoad(of viewModel: HealthChatProfileEditScreenViewModel) async throws {
let deferred = deferFulfillment(viewModel.context.observe(\.viewState.initialProfile)) { $0 != nil }
try await deferred.fulfill()
}
private func makeProfile() throws -> HealthChatMember {
try JSONDecoder().decode(HealthChatMember.self, from: Data("""
{
"userId": "@alice:healthchat.ch",
"displayName": "Dr. Alice Alpha",
"firstName": "Alice",
"lastName": "Alpha",
"specialty": "Physiotherapie",
"practiceName": "Praxis Alpha",
"businessCity": "Zürich",
"businessTel": "+41 44 123 45 67",
"furtherInfo": "Old info"
}
""".utf8))
}
}