diff options
| author | Christian Cleberg <[email protected]> | 2026-07-16 01:29:06 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-16 01:29:06 -0500 |
| commit | 8e585a709d8979d493fef3ed4015db93687f48e8 (patch) | |
| tree | faebe598a4c6f7a5f3db92d465ed693aab594252 /Hutch/Views/Settings | |
| parent | f100206cc6d6784563d8eb905c9feb15c58bcc1e (diff) | |
| parent | 21be03e6ca54c1a15607faab905b119eda9a548f (diff) | |
| download | hutch-8e585a709d8979d493fef3ed4015db93687f48e8.tar.gz hutch-8e585a709d8979d493fef3ed4015db93687f48e8.tar.bz2 hutch-8e585a709d8979d493fef3ed4015db93687f48e8.zip | |
Merge pull request #6 from zerolabsco/phase-3-api-features
Phase 3: API features
Diffstat (limited to 'Hutch/Views/Settings')
| -rw-r--r-- | Hutch/Views/Settings/SettingsViewModel.swift | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Hutch/Views/Settings/SettingsViewModel.swift b/Hutch/Views/Settings/SettingsViewModel.swift index edfaad4..8536e60 100644 --- a/Hutch/Views/Settings/SettingsViewModel.swift +++ b/Hutch/Views/Settings/SettingsViewModel.swift @@ -43,6 +43,15 @@ private struct PATListResponse: Decodable, Sendable { let personalAccessTokens: [PersonalAccessToken] } +private struct AuditLogResponse: Decodable, Sendable { + let auditLog: AuditLogPage +} + +private struct AuditLogPage: Decodable, Sendable { + let results: [AuditLogEntry] + let cursor: String? +} + // MARK: - View Model @Observable @@ -53,6 +62,11 @@ final class SettingsViewModel { private(set) var sshKeys: [SSHKey] = [] private(set) var pgpKeys: [PGPKey] = [] private(set) var personalAccessTokens: [PersonalAccessToken] = [] + private(set) var auditLog: [AuditLogEntry] = [] + private(set) var isLoadingAuditLog = false + /// Kept apart from `error` so a failed audit fetch cannot bury a profile + /// save failure, and vice versa. + var auditLogError: String? private(set) var isLoading = false private(set) var isLoadingPATs = false @@ -139,6 +153,12 @@ final class SettingsViewModel { } """ + private static let auditLogQuery = """ + query auditLog { + auditLog { results { id created ipAddress eventType details } } + } + """ + private static let personalAccessTokensQuery = """ query personalAccessTokens { personalAccessTokens { id issued expires comment grants } @@ -393,4 +413,26 @@ final class SettingsViewModel { isLoadingPATs = false } + // MARK: - Audit Log + + /// Loads the most recent audit entries. + /// + /// Deliberately one page: this is a glanceable "has anything happened to my + /// account" surface, not an archive. The full log is on meta.sr.ht. + func loadAuditLog() async { + guard !isLoadingAuditLog else { return } + isLoadingAuditLog = true + defer { isLoadingAuditLog = false } + + do { + let result = try await client.execute( + service: .meta, + query: Self.auditLogQuery, + responseType: AuditLogResponse.self + ) + auditLog = result.auditLog.results + } catch { + auditLogError = error.userFacingMessage + } + } } |
