IceCubesApp/Packages/Models/Sources/Models/Status.swift

154 lines
4.3 KiB
Swift
Raw Normal View History

import Foundation
2022-12-24 06:32:20 +00:00
public struct Application: Codable, Identifiable {
public var id: String {
name
}
2023-01-17 10:36:01 +00:00
2022-12-24 06:32:20 +00:00
public let name: String
2022-12-27 13:20:00 +00:00
public let website: URL?
}
2023-01-17 10:36:01 +00:00
public extension Application {
init(from decoder: Decoder) throws {
2023-01-06 20:19:29 +00:00
let values = try decoder.container(keyedBy: CodingKeys.self)
name = try values.decodeIfPresent(String.self, forKey: .name) ?? ""
website = try? values.decodeIfPresent(URL.self, forKey: .website)
}
}
2022-12-27 18:10:31 +00:00
public enum Visibility: String, Codable, CaseIterable {
2022-12-27 13:20:00 +00:00
case pub = "public"
case unlisted
case priv = "private"
case direct
2022-12-24 06:32:20 +00:00
}
2022-12-16 12:16:48 +00:00
public protocol AnyStatus {
2022-12-26 07:24:55 +00:00
var viewId: String { get }
2022-12-16 12:16:48 +00:00
var id: String { get }
2022-12-20 13:35:47 +00:00
var content: HTMLString { get }
2022-12-16 12:16:48 +00:00
var account: Account { get }
2022-12-26 07:24:55 +00:00
var createdAt: ServerDate { get }
var editedAt: ServerDate? { get }
2022-12-17 12:37:46 +00:00
var mediaAttachments: [MediaAttachement] { get }
2022-12-19 14:51:25 +00:00
var mentions: [Mention] { get }
2022-12-19 15:17:25 +00:00
var repliesCount: Int { get }
var reblogsCount: Int { get }
var favouritesCount: Int { get }
2022-12-19 15:34:57 +00:00
var card: Card? { get }
2022-12-23 14:53:02 +00:00
var favourited: Bool? { get }
var reblogged: Bool? { get }
2022-12-21 11:39:29 +00:00
var pinned: Bool? { get }
2023-01-09 18:26:56 +00:00
var bookmarked: Bool? { get }
2022-12-21 16:39:48 +00:00
var emojis: [Emoji] { get }
2022-12-23 14:53:02 +00:00
var url: URL? { get }
2022-12-24 06:32:20 +00:00
var application: Application? { get }
var inReplyToAccountId: String? { get }
2022-12-27 13:20:00 +00:00
var visibility: Visibility { get }
2022-12-28 09:08:41 +00:00
var poll: Poll? { get }
2022-12-28 09:45:05 +00:00
var spoilerText: String { get }
2023-01-03 14:15:08 +00:00
var filtered: [Filtered]? { get }
var sensitive: Bool { get }
var language: String? { get }
2022-12-16 12:16:48 +00:00
}
public struct Status: AnyStatus, Codable, Identifiable {
2022-12-26 07:24:55 +00:00
public var viewId: String {
id + createdAt + (editedAt ?? "")
}
2023-01-17 10:36:01 +00:00
2022-12-16 12:16:48 +00:00
public let id: String
2022-12-17 12:37:46 +00:00
public let content: HTMLString
2022-12-16 12:16:48 +00:00
public let account: Account
2022-12-17 12:37:46 +00:00
public let createdAt: ServerDate
2022-12-26 07:24:55 +00:00
public let editedAt: ServerDate?
2022-12-16 12:16:48 +00:00
public let reblog: ReblogStatus?
2022-12-17 12:37:46 +00:00
public let mediaAttachments: [MediaAttachement]
2022-12-19 14:51:25 +00:00
public let mentions: [Mention]
2022-12-19 15:17:25 +00:00
public let repliesCount: Int
public let reblogsCount: Int
public let favouritesCount: Int
2022-12-19 15:34:57 +00:00
public let card: Card?
2022-12-23 14:53:02 +00:00
public let favourited: Bool?
public let reblogged: Bool?
2022-12-21 11:39:29 +00:00
public let pinned: Bool?
2023-01-09 18:26:56 +00:00
public let bookmarked: Bool?
2022-12-21 16:39:48 +00:00
public let emojis: [Emoji]
2022-12-23 14:53:02 +00:00
public let url: URL?
2022-12-24 06:32:20 +00:00
public let application: Application?
public let inReplyToAccountId: String?
2022-12-27 13:20:00 +00:00
public let visibility: Visibility
2022-12-28 09:08:41 +00:00
public let poll: Poll?
2022-12-28 09:45:05 +00:00
public let spoilerText: String
2023-01-03 14:15:08 +00:00
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
2023-01-17 10:36:01 +00:00
2022-12-17 12:37:46 +00:00
public static func placeholder() -> Status {
.init(id: UUID().uuidString,
2023-01-06 16:14:34 +00:00
content: "This is a #toot\nWith some @content\nAnd some more content for your #eyes @only",
2022-12-17 12:37:46 +00:00
account: .placeholder(),
createdAt: "2022-12-16T10:20:54.000Z",
2022-12-26 07:24:55 +00:00
editedAt: nil,
2022-12-17 12:37:46 +00:00
reblog: nil,
2022-12-19 14:51:25 +00:00
mediaAttachments: [],
2022-12-19 15:17:25 +00:00
mentions: [],
repliesCount: 0,
reblogsCount: 0,
2022-12-19 15:34:57 +00:00
favouritesCount: 0,
2022-12-20 19:33:45 +00:00
card: nil,
favourited: false,
2022-12-21 11:39:29 +00:00
reblogged: false,
2022-12-21 16:39:48 +00:00
pinned: false,
2023-01-09 18:26:56 +00:00
bookmarked: false,
2022-12-23 14:53:02 +00:00
emojis: [],
2022-12-24 06:32:20 +00:00
url: nil,
application: nil,
2022-12-27 13:20:00 +00:00
inReplyToAccountId: nil,
2022-12-28 09:08:41 +00:00
visibility: .pub,
2022-12-28 09:45:05 +00:00
poll: nil,
2023-01-03 11:24:15 +00:00
spoilerText: "",
filtered: [],
sensitive: false,
language: nil)
2022-12-17 12:37:46 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-17 12:37:46 +00:00
public static func placeholders() -> [Status] {
[.placeholder(), .placeholder(), .placeholder(), .placeholder(), .placeholder()]
}
2022-12-16 12:16:48 +00:00
}
public struct ReblogStatus: AnyStatus, Codable, Identifiable {
2022-12-26 07:24:55 +00:00
public var viewId: String {
id + createdAt + (editedAt ?? "")
}
2023-01-17 10:36:01 +00:00
public let id: String
public let content: String
public let account: Account
2022-11-25 11:00:01 +00:00
public let createdAt: String
2022-12-26 07:24:55 +00:00
public let editedAt: ServerDate?
2022-12-17 12:37:46 +00:00
public let mediaAttachments: [MediaAttachement]
2022-12-19 14:51:25 +00:00
public let mentions: [Mention]
2022-12-19 15:17:25 +00:00
public let repliesCount: Int
public let reblogsCount: Int
public let favouritesCount: Int
2022-12-19 15:34:57 +00:00
public let card: Card?
2022-12-23 14:53:02 +00:00
public let favourited: Bool?
public let reblogged: Bool?
2022-12-21 11:39:29 +00:00
public let pinned: Bool?
2023-01-09 18:26:56 +00:00
public let bookmarked: Bool?
2022-12-21 16:39:48 +00:00
public let emojis: [Emoji]
2022-12-23 14:53:02 +00:00
public let url: URL?
2022-12-24 06:32:20 +00:00
public var application: Application?
public let inReplyToAccountId: String?
2022-12-27 13:20:00 +00:00
public let visibility: Visibility
2022-12-28 09:08:41 +00:00
public let poll: Poll?
2022-12-28 09:45:05 +00:00
public let spoilerText: String
2023-01-03 14:15:08 +00:00
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
}