aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models/Hotline.swift
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 /Hotline/Models/Hotline.swift
parenta4798840e1d58ddb19ed5d5e0e0a4f0add47c9fb (diff)
Break model objects out into their own files.
Diffstat (limited to 'Hotline/Models/Hotline.swift')
-rw-r--r--Hotline/Models/Hotline.swift129
1 files changed, 0 insertions, 129 deletions
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