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

283 lines
9.4 KiB
Swift
Raw Normal View History

import Foundation
import Atomics
2023-01-22 15:55:03 +00:00
public struct Application: Codable, Identifiable, Hashable, Equatable {
2022-12-24 06:32:20 +00:00
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)
}
}
public enum Visibility: String, Codable, CaseIterable, Hashable, Equatable, Sendable {
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 {
2023-02-19 06:25:27 +00:00
var viewId: StatusViewId { 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 }
var mediaAttachments: [MediaAttachment] { 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 }
2023-01-24 05:56:28 +00:00
var favouritesCount: Int { get }
2022-12-19 15:34:57 +00:00
var card: Card? { get }
2023-01-24 05:56:28 +00:00
var favourited: Bool? { get }
2022-12-23 14:53:02 +00:00
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 }
var url: String? { get }
2022-12-24 06:32:20 +00:00
var application: Application? { get }
2023-02-16 16:07:52 +00:00
var inReplyToId: String? { get }
2022-12-24 06:32:20 +00:00
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 }
var spoilerText: HTMLString { 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
}
2023-02-19 06:25:27 +00:00
public struct StatusViewId: Hashable {
2023-02-21 06:23:42 +00:00
let id: String
let editedAt: Date?
2023-02-19 06:25:27 +00:00
}
2023-02-12 15:29:41 +00:00
public extension AnyStatus {
2023-02-19 06:25:27 +00:00
var viewId: StatusViewId {
StatusViewId(id: id, editedAt: editedAt?.asDate)
2023-02-09 08:12:44 +00:00
}
}
2023-02-26 08:38:26 +00:00
public final class Status: AnyStatus, Codable, Identifiable, Equatable, Hashable {
2023-01-22 19:23:41 +00:00
public static func == (lhs: Status, rhs: Status) -> Bool {
lhs.id == rhs.id && lhs.viewId == rhs.viewId
2023-01-22 19:23:41 +00:00
}
2023-01-22 19:23:41 +00:00
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
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?
public let mediaAttachments: [MediaAttachment]
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
2023-01-24 05:56:28 +00:00
public let favouritesCount: Int
2022-12-19 15:34:57 +00:00
public let card: Card?
2023-01-24 05:56:28 +00:00
public let favourited: Bool?
2022-12-23 14:53:02 +00:00
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]
public let url: String?
2022-12-24 06:32:20 +00:00
public let application: Application?
2023-02-16 16:07:52 +00:00
public let inReplyToId: String?
2022-12-24 06:32:20 +00:00
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?
public let spoilerText: HTMLString
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
2023-02-26 08:38:26 +00:00
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, reblog: ReblogStatus?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application?, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.id = id
self.content = content
self.account = account
self.createdAt = createdAt
self.editedAt = editedAt
self.reblog = reblog
self.mediaAttachments = mediaAttachments
self.mentions = mentions
self.repliesCount = repliesCount
self.reblogsCount = reblogsCount
self.favouritesCount = favouritesCount
self.card = card
self.favourited = favourited
self.reblogged = reblogged
self.pinned = pinned
self.bookmarked = bookmarked
self.emojis = emojis
self.url = url
self.application = application
self.inReplyToId = inReplyToId
self.inReplyToAccountId = inReplyToAccountId
self.visibility = visibility
self.poll = poll
self.spoilerText = spoilerText
self.filtered = filtered
self.sensitive = sensitive
self.language = language
}
2023-02-12 15:29:41 +00:00
public static func placeholder(forSettings: Bool = false, language: String? = nil) -> Status {
2022-12-17 12:37:46 +00:00
.init(id: UUID().uuidString,
2023-02-12 15:29:41 +00:00
content: .init(stringValue: "Lorem ipsum [#dolor](#) sit amet\nconsectetur [@adipiscing](#) elit\nAsed do eiusmod tempor incididunt ut labore.", parseMarkdown: forSettings),
account: .placeholder(),
createdAt: ServerDate(),
editedAt: nil,
reblog: nil,
mediaAttachments: [],
mentions: [],
repliesCount: 0,
reblogsCount: 0,
favouritesCount: 0,
card: nil,
favourited: false,
reblogged: false,
pinned: false,
bookmarked: false,
emojis: [],
url: "https://example.com",
application: nil,
2023-02-16 16:07:52 +00:00
inReplyToId: nil,
2023-02-12 15:29:41 +00:00
inReplyToAccountId: nil,
visibility: .pub,
poll: nil,
spoilerText: .init(stringValue: ""),
filtered: [],
sensitive: false,
language: language)
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()]
}
2023-02-12 15:29:41 +00:00
2023-02-10 17:25:38 +00:00
public var reblogAsAsStatus: Status? {
if let reblog {
return .init(id: reblog.id,
content: reblog.content,
account: reblog.account,
createdAt: reblog.createdAt,
editedAt: reblog.editedAt,
reblog: nil,
mediaAttachments: reblog.mediaAttachments,
mentions: reblog.mentions,
repliesCount: reblog.repliesCount,
reblogsCount: reblog.reblogsCount,
favouritesCount: reblog.favouritesCount,
card: reblog.card,
favourited: reblog.favourited,
reblogged: reblog.reblogged,
pinned: reblog.pinned,
bookmarked: reblog.bookmarked,
emojis: reblog.emojis,
url: reblog.url,
application: reblog.application,
2023-02-16 16:07:52 +00:00
inReplyToId: reblog.inReplyToId,
2023-02-10 17:25:38 +00:00
inReplyToAccountId: reblog.inReplyToAccountId,
visibility: reblog.visibility,
poll: reblog.poll,
spoilerText: reblog.spoilerText,
filtered: reblog.filtered,
sensitive: reblog.sensitive,
language: reblog.language)
}
return nil
}
2022-12-16 12:16:48 +00:00
}
public final class ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Hashable {
2023-01-22 19:23:41 +00:00
public static func == (lhs: ReblogStatus, rhs: ReblogStatus) -> Bool {
lhs.id == rhs.id
}
2023-01-22 19:23:41 +00:00
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
2023-01-17 10:36:01 +00:00
public let id: String
public let content: HTMLString
public let account: Account
2023-02-09 08:12:44 +00:00
public let createdAt: ServerDate
2022-12-26 07:24:55 +00:00
public let editedAt: ServerDate?
public let mediaAttachments: [MediaAttachment]
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
2023-01-24 05:56:28 +00:00
public let favouritesCount: Int
2022-12-19 15:34:57 +00:00
public let card: Card?
2023-01-24 05:56:28 +00:00
public let favourited: Bool?
2022-12-23 14:53:02 +00:00
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]
public let url: String?
public let application: Application?
2023-02-16 16:07:52 +00:00
public let inReplyToId: String?
2022-12-24 06:32:20 +00:00
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?
public let spoilerText: HTMLString
2023-01-03 14:15:08 +00:00
public let filtered: [Filtered]?
public let sensitive: Bool
public let language: String?
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application? = nil, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {
self.id = id
self.content = content
self.account = account
self.createdAt = createdAt
self.editedAt = editedAt
self.mediaAttachments = mediaAttachments
self.mentions = mentions
self.repliesCount = repliesCount
self.reblogsCount = reblogsCount
self.favouritesCount = favouritesCount
self.card = card
self.favourited = favourited
self.reblogged = reblogged
self.pinned = pinned
self.bookmarked = bookmarked
self.emojis = emojis
self.url = url
self.application = application
self.inReplyToId = inReplyToId
self.inReplyToAccountId = inReplyToAccountId
self.visibility = visibility
self.poll = poll
self.spoilerText = spoilerText
self.filtered = filtered
self.sensitive = sensitive
self.language = language
}
}
extension Application: Sendable {}
extension StatusViewId: Sendable {}
// Every property in Status is immutable.
extension Status: Sendable {}
// Every property in ReblogStatus is immutable.
extension ReblogStatus: Sendable {}