Add a member directory tab (#11)

* 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
This commit is contained in:
2026-09-22 17:03:28 +02:00
parent 352d25f2bb
commit 93149f1cbd
33 changed files with 954 additions and 1 deletions
@@ -0,0 +1,125 @@
//
// 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 SwiftState
import SwiftUI
/// The flow behind the HealthChat "Members" tab: the member directory with
/// pushed member profiles. Chats and calls are handed off to the session flow.
final class HealthChatMembersFlowCoordinator {
private let flowParameters: CommonFlowParameters
let navigationStackCoordinator: NavigationStackCoordinator
private var cancellables = Set<AnyCancellable>()
enum State: StateType {
/// The state machine hasn't started.
case initial
/// The member directory at the root of the tab.
case memberDirectory
/// A member's profile pushed on top of the directory.
case memberProfile
}
enum Event: EventType {
/// The flow is being started.
case start
/// Request presentation of a member's profile.
case showMemberProfile
/// The member profile has been dismissed.
case dismissedMemberProfile
}
private let stateMachine: StateMachine<State, Event>
private let actionsSubject: PassthroughSubject<ExtraHomeTabAction, Never> = .init()
var actionsPublisher: AnyPublisher<ExtraHomeTabAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(flowParameters: CommonFlowParameters) {
self.flowParameters = flowParameters
navigationStackCoordinator = NavigationStackCoordinator()
stateMachine = StateMachine(state: .initial)
configureStateMachine()
}
func start() {
stateMachine.tryEvent(.start)
}
// MARK: - Private
private func configureStateMachine() {
stateMachine.addRoutes(event: .start, transitions: [.initial => .memberDirectory]) { [weak self] _ in
self?.presentMemberDirectory()
}
stateMachine.addRoutes(event: .showMemberProfile, transitions: [.memberDirectory => .memberProfile])
stateMachine.addRoutes(event: .dismissedMemberProfile, transitions: [.memberProfile => .memberDirectory])
stateMachine.addErrorHandler { context in
fatalError("Unexpected transition from `\(context.fromState)` to `\(context.toState)` for event `\(String(describing: context.event))`.")
}
}
private func presentMemberDirectory() {
let userSession = flowParameters.userSession
let apiService = HealthChatAPIService(tokenProvider: HealthChatOpenIDTokenProvider(clientProxy: userSession.clientProxy))
let coordinator = HealthChatMemberDirectoryScreenCoordinator(parameters: .init(apiService: apiService,
clientProxy: userSession.clientProxy,
mediaProvider: userSession.mediaProvider,
userIndicatorController: flowParameters.userIndicatorController))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .selectMember(let userID):
presentMemberProfile(userID: userID)
case .presentRoom(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
}
}
.store(in: &cancellables)
navigationStackCoordinator.setRootCoordinator(coordinator)
}
private func presentMemberProfile(userID: String) {
let parameters = UserProfileScreenCoordinatorParameters(userID: userID,
isPresentedModally: false,
userSession: flowParameters.userSession,
userIndicatorController: flowParameters.userIndicatorController,
analytics: flowParameters.analytics,
appSettings: flowParameters.appSettings,
appHooks: flowParameters.appHooks)
let coordinator = UserProfileScreenCoordinator(parameters: parameters)
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .openDirectChat(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
case .startCall(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCall(roomID: roomProxy.id, isVoiceCall: isVoiceCall))
case .dismiss:
navigationStackCoordinator.pop()
}
}
.store(in: &cancellables)
stateMachine.tryEvent(.showMemberProfile)
navigationStackCoordinator.push(coordinator) { [weak self] in
self?.stateMachine.tryEvent(.dismissedMemberProfile)
}
}
}
@@ -20,7 +20,7 @@ enum UserSessionFlowCoordinatorAction {
}
class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
enum HomeTab: Hashable { case chats, spaces, search }
enum HomeTab: Hashable { case chats, spaces, search, members }
private let navigationRootCoordinator: NavigationRootCoordinator
private let navigationTabCoordinator: NavigationTabCoordinator<HomeTab>
@@ -44,6 +44,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
private let searchTabNavigationStackCoordinator: NavigationStackCoordinator?
private let searchTabDetails: NavigationTabCoordinator<HomeTab>.TabDetails?
private let extraTabActions: AnyPublisher<ExtraHomeTabAction, Never>?
private var settingsFlowCoordinator: SettingsFlowCoordinator?
enum State: StateType {
@@ -128,6 +130,14 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
if let searchTabNavigationStackCoordinator, let searchTabDetails {
tabs.append(.init(coordinator: searchTabNavigationStackCoordinator, details: searchTabDetails))
}
if let extraTab = flowParameters.appHooks.homeTabsHook.makeExtraTab(flowParameters: flowParameters) {
tabs.append(extraTab.tab)
extraTabActions = extraTab.actions
} else {
extraTabActions = nil
}
navigationTabCoordinator.setTabs(tabs)
stateMachine = flowParameters.stateMachineFactory.makeUserSessionFlowStateMachine(state: .initial)
@@ -228,6 +238,17 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// swiftlint:disable:next function_body_length
private func setupObservers() {
extraTabActions?
.sink { [weak self] action in
switch action {
case .presentRoom(let roomID):
self?.handleAppRoute(.room(roomID: roomID, via: []), animated: true)
case .presentCall(let roomID, let isVoiceCall):
self?.handleAppRoute(.call(roomID: roomID, isVoiceCall: isVoiceCall), animated: true)
}
}
.store(in: &cancellables)
chatsTabFlowCoordinator.actionsPublisher
.sink { [weak self] action in
guard let self else { return }