mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 20:39:24 +00:00
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:
+56
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// 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 HealthChatMemberDirectoryScreenCoordinatorParameters {
|
||||
let apiService: HealthChatAPIServiceProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let mediaProvider: MediaProviderProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum HealthChatMemberDirectoryScreenCoordinatorAction {
|
||||
case selectMember(userID: String)
|
||||
case presentRoom(roomID: String)
|
||||
}
|
||||
|
||||
final class HealthChatMemberDirectoryScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: HealthChatMemberDirectoryScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<HealthChatMemberDirectoryScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: HealthChatMemberDirectoryScreenCoordinatorParameters) {
|
||||
viewModel = HealthChatMemberDirectoryScreenViewModel(apiService: parameters.apiService,
|
||||
clientProxy: parameters.clientProxy,
|
||||
mediaProvider: parameters.mediaProvider,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .selectMember(let userID):
|
||||
actionsSubject.send(.selectMember(userID: userID))
|
||||
case .presentRoom(let roomID):
|
||||
actionsSubject.send(.presentRoom(roomID: roomID))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(HealthChatMemberDirectoryScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// 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 HealthChatMemberDirectoryScreenViewModelAction {
|
||||
case selectMember(userID: String)
|
||||
case presentRoom(roomID: String)
|
||||
}
|
||||
|
||||
nonisolated enum HealthChatMemberDirectoryScreenContent: Equatable {
|
||||
case loading
|
||||
case members([HealthChatMember])
|
||||
case pendingApproval(message: String)
|
||||
case failure
|
||||
}
|
||||
|
||||
struct HealthChatMemberDirectoryScreenViewState: BindableState {
|
||||
var content: HealthChatMemberDirectoryScreenContent = .loading
|
||||
|
||||
var bindings = HealthChatMemberDirectoryScreenViewStateBindings()
|
||||
}
|
||||
|
||||
struct HealthChatMemberDirectoryScreenViewStateBindings {
|
||||
var searchQuery = ""
|
||||
var alertInfo: AlertInfo<HealthChatMemberDirectoryScreenAlertType>?
|
||||
}
|
||||
|
||||
enum HealthChatMemberDirectoryScreenAlertType: Hashable {
|
||||
case failedStartingChat
|
||||
}
|
||||
|
||||
enum HealthChatMemberDirectoryScreenViewAction {
|
||||
case retry
|
||||
case selectMember(HealthChatMember)
|
||||
case startChat(HealthChatMember)
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// 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 AsyncAlgorithms
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias HealthChatMemberDirectoryScreenViewModelType = StateStoreViewModelV2<HealthChatMemberDirectoryScreenViewState, HealthChatMemberDirectoryScreenViewAction>
|
||||
|
||||
class HealthChatMemberDirectoryScreenViewModel: HealthChatMemberDirectoryScreenViewModelType, HealthChatMemberDirectoryScreenViewModelProtocol {
|
||||
private let apiService: HealthChatAPIServiceProtocol
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private var searchQueryObservationTask: Task<Void, Never>?
|
||||
// periphery:ignore - auto cancels when reassigned
|
||||
@CancellableTask private var fetchTask: Task<Void, Never>?
|
||||
|
||||
private let actionsSubject: PassthroughSubject<HealthChatMemberDirectoryScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(apiService: HealthChatAPIServiceProtocol,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
mediaProvider: MediaProviderProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.apiService = apiService
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: HealthChatMemberDirectoryScreenViewState(), mediaProvider: mediaProvider)
|
||||
|
||||
fetchMembers()
|
||||
|
||||
// The stream replays the current query, which the initial fetch above already covers.
|
||||
let searchQueryStream = context.observe(\.viewState.bindings.searchQuery)
|
||||
.debounce(for: .milliseconds(300))
|
||||
.removeDuplicates()
|
||||
.dropFirst()
|
||||
searchQueryObservationTask = Task { [weak self] in
|
||||
for await _ in searchQueryStream {
|
||||
self?.fetchMembers()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isolated deinit {
|
||||
searchQueryObservationTask?.cancel()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: HealthChatMemberDirectoryScreenViewAction) {
|
||||
switch viewAction {
|
||||
case .retry:
|
||||
state.content = .loading
|
||||
fetchMembers()
|
||||
case .selectMember(let member):
|
||||
actionsSubject.send(.selectMember(userID: member.userID))
|
||||
case .startChat(let member):
|
||||
Task { await startChat(with: member) }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func fetchMembers() {
|
||||
fetchTask = Task { [weak self] in
|
||||
guard let self else { return }
|
||||
|
||||
let searchQuery = state.bindings.searchQuery
|
||||
let result = await apiService.members(searchQuery: searchQuery.isEmpty ? nil : searchQuery)
|
||||
|
||||
guard !Task.isCancelled else { return }
|
||||
|
||||
switch result {
|
||||
case .success(let response) where !response.isApproved:
|
||||
state.content = .pendingApproval(message: response.pendingMessage ?? HealthChatL10n.screenMemberDirectoryPendingApproval)
|
||||
case .success(let response):
|
||||
state.content = .members(response.users)
|
||||
case .failure:
|
||||
state.content = .failure
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func startChat(with member: HealthChatMember) async {
|
||||
switch clientProxy.directRoomForUserID(member.userID) {
|
||||
case .success(let roomID?):
|
||||
actionsSubject.send(.presentRoom(roomID: roomID))
|
||||
case .success(nil):
|
||||
showLoadingIndicator()
|
||||
defer { hideLoadingIndicator() }
|
||||
|
||||
switch await clientProxy.createDirectRoom(with: member.userID, expectedRoomName: member.displayName) {
|
||||
case .success(let roomID):
|
||||
actionsSubject.send(.presentRoom(roomID: roomID))
|
||||
case .failure:
|
||||
state.bindings.alertInfo = .init(id: .failedStartingChat,
|
||||
title: L10n.commonError,
|
||||
message: L10n.screenStartChatErrorStartingChat)
|
||||
}
|
||||
case .failure:
|
||||
state.bindings.alertInfo = .init(id: .failedStartingChat,
|
||||
title: L10n.commonError,
|
||||
message: L10n.screenStartChatErrorStartingChat)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: User Indicators
|
||||
|
||||
private var loadingIndicatorIdentifier: String {
|
||||
"\(Self.self)-Loading"
|
||||
}
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: loadingIndicatorIdentifier,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: false, allowsInteraction: false),
|
||||
title: L10n.commonLoading,
|
||||
persistent: true),
|
||||
delay: .milliseconds(100))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
+14
@@ -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 HealthChatMemberDirectoryScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenViewModelAction, Never> { get }
|
||||
var context: HealthChatMemberDirectoryScreenViewModelType.Context { get }
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
//
|
||||
// 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)
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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 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: 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 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))
|
||||
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())
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// 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 HealthChatMemberListRow: View {
|
||||
let member: HealthChatMember
|
||||
let mediaProvider: MediaProviderProtocol?
|
||||
let selectAction: () -> Void
|
||||
let startChatAction: () -> Void
|
||||
|
||||
private var subtitle: String {
|
||||
[member.specialty, member.practiceName, member.businessCity]
|
||||
.compactMap { $0 }
|
||||
.joined(separator: " · ")
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ListRow(kind: .custom {
|
||||
HStack(spacing: 12) {
|
||||
Button(action: selectAction) {
|
||||
HStack(spacing: 12) {
|
||||
LoadableAvatarImage(url: member.avatarURL,
|
||||
name: member.displayName,
|
||||
contentID: member.userID,
|
||||
avatarSize: .user(on: .startChat),
|
||||
mediaProvider: mediaProvider)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(member.displayName ?? member.userID)
|
||||
.font(.compound.bodyLGSemibold)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.lineLimit(1)
|
||||
|
||||
if !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.font(.compound.bodySM)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
.lineLimit(2)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
Button(action: startChatAction) {
|
||||
CompoundIcon(\.chat)
|
||||
.foregroundColor(.compound.iconAccentTertiary)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.accessibilityLabel(L10n.actionStartChat)
|
||||
}
|
||||
.padding(.horizontal, ListRowPadding.horizontal)
|
||||
.padding(.vertical, 8)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user