summaryrefslogtreecommitdiff
path: root/Hutch/Models/Meta.swift
blob: f52fc76aaf48e0cc934368b19b73a3b6cf241cf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Foundation

// MARK: - User Profile (full)

/// Extended user profile from meta.sr.ht with all fields from the `me` query.
struct UserProfile: Codable, Sendable {
    let username: String
    let canonicalName: String
    let email: String
    let url: String?
    let location: String?
    let bio: String?
    let avatar: String?
    let userType: String?
    let sshKeys: SSHKeyPage
    let pgpKeys: PGPKeyPage
    let paymentStatus: String?
    let subscription: Subscription?
}

// MARK: - SSH Key

struct SSHKey: Codable, Sendable, Identifiable {
    let id: Int
    let comment: String?
    let created: Date
    let lastUsed: Date?

    var displayLabel: String {
        if let comment, !comment.isEmpty {
            return comment
        }
        return "SSH key #\(id)"
    }
}

struct SSHKeyPage: Codable, Sendable {
    let results: [SSHKey]
    let cursor: String?
}

// MARK: - PGP Key

struct PGPKey: Codable, Sendable, Identifiable {
    let id: Int
    let fingerprint: String
    let created: Date
}

struct PGPKeyPage: Codable, Sendable {
    let results: [PGPKey]
    let cursor: String?
}

// MARK: - Subscription

struct Subscription: Codable, Sendable {
    let status: String?
    let autorenew: Bool?
    let interval: String?
}

// MARK: - Personal Access Token

struct PersonalAccessToken: Codable, Sendable, Identifiable {
    let id: Int
    let issued: Date
    let expires: Date?
    let comment: String?
    let grants: String?
}

/// One entry in meta.sr.ht's audit log: a security-relevant action on the
/// account, with the address it came from.
struct AuditLogEntry: Codable, Sendable, Identifiable {
    let id: Int
    let created: Date
    let ipAddress: String
    let eventType: String
    let details: String?
}