mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
feat(healthchat): advertise the account status in settings
Pending approval and an incomplete profile were only visible in the members tab, which a new user has no reason to open.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// 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
|
||||
import Observation
|
||||
|
||||
/// Loads the own account's status for the banners that advertise it.
|
||||
@Observable
|
||||
final class HealthChatAccountStatusLoader {
|
||||
private(set) var status: HealthChatAccountStatus = .unknown
|
||||
|
||||
/// The load kicked off on creation — await this in tests before asserting.
|
||||
@ObservationIgnored private(set) var loadingTask: Task<Void, Never>?
|
||||
|
||||
init(apiService: HealthChatAPIServiceProtocol) {
|
||||
loadingTask = Task { await load(from: apiService) }
|
||||
}
|
||||
|
||||
/// Creates a loader with a fixed status, for previews.
|
||||
init(status: HealthChatAccountStatus) {
|
||||
self.status = status
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func load(from apiService: HealthChatAPIServiceProtocol) async {
|
||||
// Every failure below leaves the status unknown: a banner must not report an error.
|
||||
guard case let .success(profile) = await apiService.ownProfile() else {
|
||||
return
|
||||
}
|
||||
|
||||
guard profile.isApproved else {
|
||||
status = .pendingApproval
|
||||
return
|
||||
}
|
||||
|
||||
guard case let .success(completeness) = await apiService.profileCompleteness() else {
|
||||
return
|
||||
}
|
||||
|
||||
// The server words the hint itself; without one there is nothing to show.
|
||||
guard !completeness.isComplete, let message = completeness.message else {
|
||||
status = .ok
|
||||
return
|
||||
}
|
||||
|
||||
status = .incompleteProfile(message: message)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user