mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
d9524130fa
Pending approval and an incomplete profile were only visible in the members tab, which a new user has no reason to open.
54 lines
1.7 KiB
Swift
54 lines
1.7 KiB
Swift
//
|
|
// 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)
|
|
}
|
|
}
|