aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-12 16:29:12 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-12 16:29:12 -0800
commita428e3e28fb851cec65ff27f212c19bce08e5369 (patch)
treed106ce73c1411dff56f401f3a9df62419c8d4f58
parenta4798840e1d58ddb19ed5d5e0e0a4f0add47c9fb (diff)
Break model objects out into their own files.
-rw-r--r--Hotline.xcodeproj/project.pbxproj18
-rw-r--r--Hotline/Models/ChatMessage.swift35
-rw-r--r--Hotline/Models/FileInfo.swift31
-rw-r--r--Hotline/Models/Hotline.swift129
-rw-r--r--Hotline/Models/NewsCategory.swift34
-rw-r--r--Hotline/Models/User.swift33
6 files changed, 150 insertions, 130 deletions
diff --git a/Hotline.xcodeproj/project.pbxproj b/Hotline.xcodeproj/project.pbxproj
index 3dd6c06..bff9214 100644
--- a/Hotline.xcodeproj/project.pbxproj
+++ b/Hotline.xcodeproj/project.pbxproj
@@ -11,6 +11,10 @@
DA0D698D2B1E7CF700C71DF5 /* UsersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0D698C2B1E7CF700C71DF5 /* UsersView.swift */; };
DA0D698F2B1E841600C71DF5 /* MessageBoardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0D698E2B1E841600C71DF5 /* MessageBoardView.swift */; };
DA0D69912B1E894800C71DF5 /* FilesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0D69902B1E894800C71DF5 /* FilesView.swift */; };
+ DA32CD492B2931640053B98B /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA32CD482B2931640053B98B /* User.swift */; };
+ DA32CD4B2B29318E0053B98B /* FileInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA32CD4A2B29318E0053B98B /* FileInfo.swift */; };
+ DA32CD4D2B2931B50053B98B /* ChatMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA32CD4C2B2931B50053B98B /* ChatMessage.swift */; };
+ DA32CD4F2B2931CC0053B98B /* NewsCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA32CD4E2B2931CC0053B98B /* NewsCategory.swift */; };
DA43205E2B1D615600FC8843 /* ServerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA43205D2B1D615600FC8843 /* ServerView.swift */; };
DA4F2BF82B16A17200D8ADDC /* HotlineProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4F2BF72B16A17200D8ADDC /* HotlineProtocol.swift */; };
DA4F2C012B1A558E00D8ADDC /* ChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4F2C002B1A558E00D8ADDC /* ChatView.swift */; };
@@ -35,6 +39,10 @@
DA0D698E2B1E841600C71DF5 /* MessageBoardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBoardView.swift; sourceTree = "<group>"; };
DA0D69902B1E894800C71DF5 /* FilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilesView.swift; sourceTree = "<group>"; };
DA32CD472B28EE640053B98B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
+ DA32CD482B2931640053B98B /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
+ DA32CD4A2B29318E0053B98B /* FileInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileInfo.swift; sourceTree = "<group>"; };
+ DA32CD4C2B2931B50053B98B /* ChatMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessage.swift; sourceTree = "<group>"; };
+ DA32CD4E2B2931CC0053B98B /* NewsCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsCategory.swift; sourceTree = "<group>"; };
DA43205D2B1D615600FC8843 /* ServerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerView.swift; sourceTree = "<group>"; };
DA4F2BF72B16A17200D8ADDC /* HotlineProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HotlineProtocol.swift; sourceTree = "<group>"; };
DA4F2C002B1A558E00D8ADDC /* ChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatView.swift; sourceTree = "<group>"; };
@@ -142,9 +150,13 @@
DADDB2892B22B2C60024040D /* Models */ = {
isa = PBXGroup;
children = (
+ DADDB28A2B22B31F0024040D /* Tracker.swift */,
DADDB28E2B238D850024040D /* Hotline.swift */,
DADDB28C2B22B5920024040D /* Server.swift */,
- DADDB28A2B22B31F0024040D /* Tracker.swift */,
+ DA32CD482B2931640053B98B /* User.swift */,
+ DA32CD4A2B29318E0053B98B /* FileInfo.swift */,
+ DA32CD4C2B2931B50053B98B /* ChatMessage.swift */,
+ DA32CD4E2B2931CC0053B98B /* NewsCategory.swift */,
);
path = Models;
sourceTree = "<group>";
@@ -219,6 +231,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ DA32CD4D2B2931B50053B98B /* ChatMessage.swift in Sources */,
DA6300972B24036B0034CBFD /* HotlineClient.swift in Sources */,
DA43205E2B1D615600FC8843 /* ServerView.swift in Sources */,
DA0D69912B1E894800C71DF5 /* FilesView.swift in Sources */,
@@ -228,7 +241,9 @@
DADDB28F2B238D850024040D /* Hotline.swift in Sources */,
DADDB28D2B22B5920024040D /* Server.swift in Sources */,
DA9CAFBD2B126D5700CDA197 /* TrackerView.swift in Sources */,
+ DA32CD4B2B29318E0053B98B /* FileInfo.swift in Sources */,
DA9CAFCB2B126E3300CDA197 /* HotlineTrackerClient.swift in Sources */,
+ DA32CD4F2B2931CC0053B98B /* NewsCategory.swift in Sources */,
DA9CAFBB2B126D5700CDA197 /* HotlineApp.swift in Sources */,
DA0D698F2B1E841600C71DF5 /* MessageBoardView.swift in Sources */,
DABFCC292B1530DC009F40D2 /* FoundationExtensions.swift in Sources */,
@@ -237,6 +252,7 @@
DA0D698D2B1E7CF700C71DF5 /* UsersView.swift in Sources */,
DADDB28B2B22B31F0024040D /* Tracker.swift in Sources */,
DA4F2C012B1A558E00D8ADDC /* ChatView.swift in Sources */,
+ DA32CD492B2931640053B98B /* User.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/Hotline/Models/ChatMessage.swift b/Hotline/Models/ChatMessage.swift
new file mode 100644
index 0000000..8a57d61
--- /dev/null
+++ b/Hotline/Models/ChatMessage.swift
@@ -0,0 +1,35 @@
+import SwiftUI
+
+enum ChatMessageType {
+ case agreement
+ case status
+ case message
+ case server
+}
+
+struct ChatMessage: Identifiable {
+ let id = UUID()
+
+ let text: String
+ let type: ChatMessageType
+ let date: Date
+ let username: String?
+
+ static let parser = /^\s*([^\:]+)\:\s*(.+)/
+
+ init(text: String, type: ChatMessageType, date: Date) {
+ self.type = type
+ self.date = date
+
+ if
+ type == .message,
+ let match = text.firstMatch(of: ChatMessage.parser) {
+ self.username = String(match.1)
+ self.text = String(match.2)
+ }
+ else {
+ self.username = nil
+ self.text = text
+ }
+ }
+}
diff --git a/Hotline/Models/FileInfo.swift b/Hotline/Models/FileInfo.swift
new file mode 100644
index 0000000..0e2c76d
--- /dev/null
+++ b/Hotline/Models/FileInfo.swift
@@ -0,0 +1,31 @@
+import SwiftUI
+
+@Observable class FileInfo: Identifiable {
+ let id: UUID = UUID()
+
+ let path: [String]
+ let name: String
+
+ let type: String
+ let creator: String
+ let fileSize: UInt
+
+ let isFolder: Bool
+ var children: [FileInfo]? = nil
+
+ init(hotlineFile: HotlineFile) {
+ self.path = hotlineFile.path
+ self.name = hotlineFile.name
+ self.type = hotlineFile.type
+ self.creator = hotlineFile.creator
+ self.fileSize = UInt(hotlineFile.fileSize)
+ self.isFolder = hotlineFile.isFolder
+ if self.isFolder {
+ self.children = []
+ }
+ }
+
+ static func == (lhs: FileInfo, rhs: FileInfo) -> Bool {
+ return lhs.id == rhs.id
+ }
+}
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index beb3a74..92366fa 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -1,134 +1,5 @@
import SwiftUI
-enum NewsCategoryType {
- case bundle
- case category
-}
-
-@Observable class NewsCategory: Identifiable, Hashable {
- let id: UUID = UUID()
-
- let name: String
- let count: UInt16
- let type: NewsCategoryType
-
- init(hotlineNewsCategory: HotlineNewsCategory) {
- self.name = hotlineNewsCategory.name
- self.count = hotlineNewsCategory.count
-
- if hotlineNewsCategory.type == 2 {
- self.type = .bundle
- }
- else {
- self.type = .category
- }
- }
-
- func hash(into hasher: inout Hasher) {
- hasher.combine(self.id)
- }
-
- static func == (lhs: NewsCategory, rhs: NewsCategory) -> Bool {
- return lhs.id == rhs.id
- }
-}
-
-@Observable class FileInfo: Identifiable {
- let id: UUID = UUID()
-
- let path: [String]
- let name: String
-
- let type: String
- let creator: String
- let fileSize: UInt
-
- let isFolder: Bool
- var children: [FileInfo]? = nil
-
- init(hotlineFile: HotlineFile) {
- self.path = hotlineFile.path
- self.name = hotlineFile.name
- self.type = hotlineFile.type
- self.creator = hotlineFile.creator
- self.fileSize = UInt(hotlineFile.fileSize)
- self.isFolder = hotlineFile.isFolder
- if self.isFolder {
- self.children = []
- }
- }
-
- static func == (lhs: FileInfo, rhs: FileInfo) -> Bool {
- return lhs.id == rhs.id
- }
-}
-
-enum ChatMessageType {
- case agreement
- case status
- case message
- case server
-}
-
-struct ChatMessage: Identifiable {
- let id = UUID()
-
- let text: String
- let type: ChatMessageType
- let date: Date
- let username: String?
-
- static let parser = /^\s*([^\:]+)\:\s*(.+)/
-
- init(text: String, type: ChatMessageType, date: Date) {
- self.type = type
- self.date = date
-
- if
- type == .message,
- let match = text.firstMatch(of: ChatMessage.parser) {
- self.username = String(match.1)
- self.text = String(match.2)
- }
- else {
- self.username = nil
- self.text = text
- }
- }
-}
-
-struct UserStatus: OptionSet {
- let rawValue: Int
-
- static let idle = UserStatus(rawValue: 1 << 0)
- static let admin = UserStatus(rawValue: 1 << 1)
-}
-
-struct User: Identifiable {
- let id: UInt
- var name: String
- var iconID: UInt
- var status: UserStatus
-
- init(hotlineUser: HotlineUser) {
- var status: UserStatus = UserStatus()
- if hotlineUser.isIdle { status.update(with: .idle) }
- if hotlineUser.isAdmin { status.update(with: .admin) }
-
- self.id = UInt(hotlineUser.id)
- self.name = hotlineUser.name
- self.iconID = UInt(hotlineUser.iconID)
- self.status = status
- }
-
- init(id: UInt, name: String, iconID: UInt, status: UserStatus) {
- self.id = id
- self.name = name
- self.iconID = iconID
- self.status = status
- }
-}
-
@Observable final class Hotline: HotlineClientDelegate {
let trackerClient: HotlineTrackerClient
let client: HotlineClient
diff --git a/Hotline/Models/NewsCategory.swift b/Hotline/Models/NewsCategory.swift
new file mode 100644
index 0000000..0ba87a7
--- /dev/null
+++ b/Hotline/Models/NewsCategory.swift
@@ -0,0 +1,34 @@
+import SwiftUI
+
+enum NewsCategoryType {
+ case bundle
+ case category
+}
+
+@Observable class NewsCategory: Identifiable, Hashable {
+ let id: UUID = UUID()
+
+ let name: String
+ let count: UInt16
+ let type: NewsCategoryType
+
+ init(hotlineNewsCategory: HotlineNewsCategory) {
+ self.name = hotlineNewsCategory.name
+ self.count = hotlineNewsCategory.count
+
+ if hotlineNewsCategory.type == 2 {
+ self.type = .bundle
+ }
+ else {
+ self.type = .category
+ }
+ }
+
+ func hash(into hasher: inout Hasher) {
+ hasher.combine(self.id)
+ }
+
+ static func == (lhs: NewsCategory, rhs: NewsCategory) -> Bool {
+ return lhs.id == rhs.id
+ }
+}
diff --git a/Hotline/Models/User.swift b/Hotline/Models/User.swift
new file mode 100644
index 0000000..9011e56
--- /dev/null
+++ b/Hotline/Models/User.swift
@@ -0,0 +1,33 @@
+import SwiftUI
+
+struct UserStatus: OptionSet {
+ let rawValue: Int
+
+ static let idle = UserStatus(rawValue: 1 << 0)
+ static let admin = UserStatus(rawValue: 1 << 1)
+}
+
+struct User: Identifiable {
+ let id: UInt
+ var name: String
+ var iconID: UInt
+ var status: UserStatus
+
+ init(hotlineUser: HotlineUser) {
+ var status: UserStatus = UserStatus()
+ if hotlineUser.isIdle { status.update(with: .idle) }
+ if hotlineUser.isAdmin { status.update(with: .admin) }
+
+ self.id = UInt(hotlineUser.id)
+ self.name = hotlineUser.name
+ self.iconID = UInt(hotlineUser.iconID)
+ self.status = status
+ }
+
+ init(id: UInt, name: String, iconID: UInt, status: UserStatus) {
+ self.id = id
+ self.name = name
+ self.iconID = iconID
+ self.status = status
+ }
+}