summaryrefslogtreecommitdiff
path: root/Hutch/Models
diff options
context:
space:
mode:
Diffstat (limited to 'Hutch/Models')
-rw-r--r--Hutch/Models/Inbox.swift2
-rw-r--r--Hutch/Models/Paste.swift29
-rw-r--r--Hutch/Models/Project.swift101
3 files changed, 131 insertions, 1 deletions
diff --git a/Hutch/Models/Inbox.swift b/Hutch/Models/Inbox.swift
index 54e2685..c89cb12 100644
--- a/Hutch/Models/Inbox.swift
+++ b/Hutch/Models/Inbox.swift
@@ -150,7 +150,7 @@ struct MailComposeDraft: Sendable {
extension MailComposeDraft: Identifiable {}
-struct InboxMailingListReference: Decodable, Sendable, Hashable {
+struct InboxMailingListReference: Decodable, Sendable, Hashable, Identifiable {
let id: Int
let rid: String
let name: String
diff --git a/Hutch/Models/Paste.swift b/Hutch/Models/Paste.swift
new file mode 100644
index 0000000..b4c8f18
--- /dev/null
+++ b/Hutch/Models/Paste.swift
@@ -0,0 +1,29 @@
+import Foundation
+
+struct PasteFile: Codable, Sendable, Hashable, Identifiable {
+ let filename: String?
+ let hash: String
+ let contents: URL?
+
+ var id: String { hash }
+}
+
+struct Paste: Codable, Sendable, Identifiable, Hashable {
+ let id: String
+ let created: Date
+ let visibility: Visibility
+ let files: [PasteFile]
+ let user: Entity
+}
+
+struct PasteUploadDraft: Identifiable, Equatable, Sendable {
+ let id: UUID
+ var filename: String
+ var contents: String
+
+ init(id: UUID = UUID(), filename: String = "", contents: String = "") {
+ self.id = id
+ self.filename = filename
+ self.contents = contents
+ }
+}
diff --git a/Hutch/Models/Project.swift b/Hutch/Models/Project.swift
new file mode 100644
index 0000000..e6726c2
--- /dev/null
+++ b/Hutch/Models/Project.swift
@@ -0,0 +1,101 @@
+import Foundation
+
+struct Project: Identifiable, Hashable, Sendable {
+ struct MailingList: Identifiable, Hashable, Sendable {
+ let id: String
+ let name: String
+ let description: String?
+ let visibility: Visibility
+ let owner: Entity
+
+ var ownerUsername: String {
+ owner.canonicalName.srhtUsername
+ }
+
+ var inboxReference: InboxMailingListReference {
+ InboxMailingListReference(
+ id: 0,
+ rid: id,
+ name: name,
+ owner: owner
+ )
+ }
+ }
+
+ struct SourceRepo: Identifiable, Hashable, Sendable {
+ enum RepoType: String, Decodable, Sendable {
+ case git = "GIT"
+ case hg = "HG"
+
+ var service: SRHTService {
+ switch self {
+ case .git: .git
+ case .hg: .hg
+ }
+ }
+ }
+
+ let id: String
+ let name: String
+ let description: String?
+ let visibility: Visibility
+ let owner: Entity
+ let repoType: RepoType
+
+ var ownerUsername: String {
+ owner.canonicalName.srhtUsername
+ }
+ }
+
+ struct Tracker: Identifiable, Hashable, Sendable {
+ let id: String
+ let name: String
+ let description: String?
+ let visibility: Visibility
+ let owner: Entity
+
+ var ownerUsername: String {
+ owner.canonicalName.srhtUsername
+ }
+ }
+
+ let id: String
+ let name: String
+ let description: String?
+ let website: String?
+ let visibility: Visibility
+ let tags: [String]
+ let mailingLists: [MailingList]
+ let sources: [SourceRepo]
+ let trackers: [Tracker]
+
+ var resourceSummary: String? {
+ let parts = [
+ Self.resourceCountText(count: sources.count, singular: "repo"),
+ Self.resourceCountText(count: trackers.count, singular: "tracker"),
+ Self.resourceCountText(count: mailingLists.count, singular: "list")
+ ].compactMap { $0 }
+
+ if !parts.isEmpty {
+ return parts.joined(separator: " • ")
+ }
+
+ if let website, !website.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
+ return "Website linked"
+ }
+
+ return nil
+ }
+
+ private static func resourceCountText(count: Int, singular: String) -> String? {
+ guard count > 0 else { return nil }
+ let label = count == 1 ? singular : "\(singular)s"
+ return "\(count) \(label)"
+ }
+}
+
+extension String {
+ var srhtUsername: String {
+ hasPrefix("~") ? String(dropFirst()) : self
+ }
+}