aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models/NewsInfo.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-05-14 13:35:26 -0700
committerDustin Mierau <dustin@mierau.me>2024-05-14 13:35:26 -0700
commit87e979fb48da4a46e64544cea3e7b7d5fc32caa1 (patch)
tree4c10cdba5a88544543bf45ae454f643decf1358c /Hotline/Models/NewsInfo.swift
parente9fcf8c3b14e77479a6fb471bb51cd82a008147c (diff)
Newsgroup posting now works. Added reload button to news. More work on server and user icons.
Diffstat (limited to 'Hotline/Models/NewsInfo.swift')
-rw-r--r--Hotline/Models/NewsInfo.swift44
1 files changed, 38 insertions, 6 deletions
diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift
index eecd550..6ee28b8 100644
--- a/Hotline/Models/NewsInfo.swift
+++ b/Hotline/Models/NewsInfo.swift
@@ -9,15 +9,15 @@ enum NewsInfoType {
@Observable class NewsInfo: Identifiable, Hashable {
let id: UUID = UUID()
- let name: String
- let count: UInt
+ var name: String
+ var count: UInt
let type: NewsInfoType
- let categoryID: UUID?
- let articleID: UInt?
- let parentID: UInt?
+ var categoryID: UUID?
+ var articleID: UInt?
+ var parentID: UInt?
- let path: [String]
+ var path: [String]
var expanded: Bool = false
var children: [NewsInfo] = []
@@ -30,6 +30,38 @@ enum NewsInfoType {
self.type == .bundle || self.type == .category || self.children.count > 0
}
+ var lookupPath: String? {
+ switch self.type {
+ case .bundle, .category:
+ return "/\(self.path.joined(separator: "/"))"
+ case .article:
+ guard let aid = self.articleID else {
+ return nil
+ }
+// if let pid = self.parentID, pid != 0 {
+// return "/\(self.path.joined(separator: "/"))/\(pid)/\(aid)"
+// }
+ return "/\(self.path.joined(separator: "/"))/\(aid)"
+ }
+ }
+
+ var parentArticleLookupPath: String? {
+ switch self.type {
+ case .bundle, .category:
+// if self.path.count <= 1 {
+// return "/"
+// }
+// let parentPath = self.path[0..<self.path.count-1]
+// return "/\(parentPath.joined(separator: "/"))"
+ return nil
+ case .article:
+ guard let pid = self.parentID, pid != 0 else {
+ return nil
+ }
+ return "/\(self.path.joined(separator: "/"))/\(pid)"
+ }
+ }
+
init(hotlineNewsCategory: HotlineNewsCategory) {
self.categoryID = hotlineNewsCategory.id
self.articleID = nil