2022-11-20 15:39:06 +00:00
|
|
|
import Foundation
|
|
|
|
|
2023-02-18 21:51:44 +00:00
|
|
|
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 {
|
|
|
|
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 }
|
2023-01-17 14:14:50 +00:00
|
|
|
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 }
|
2023-01-18 12:36:00 +00:00
|
|
|
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 }
|
2023-01-20 17:27:00 +00:00
|
|
|
var spoilerText: HTMLString { get }
|
2023-01-03 14:15:08 +00:00
|
|
|
var filtered: [Filtered]? { get }
|
2023-01-09 19:39:42 +00:00
|
|
|
var sensitive: Bool { get }
|
2023-01-17 06:07:26 +00:00
|
|
|
var language: String? { get }
|
2024-01-01 20:06:10 +00:00
|
|
|
var isHidden: Bool { get }
|
2022-12-16 12:16:48 +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 {
|
2024-01-02 13:06:53 +00:00
|
|
|
lhs.id == rhs.id && lhs.editedAt?.asDate == rhs.editedAt?.asDate
|
2023-01-22 19:23:41 +00:00
|
|
|
}
|
2023-01-25 12:02:28 +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?
|
2023-01-17 14:14:50 +00:00
|
|
|
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]
|
2023-01-18 12:36:00 +00:00
|
|
|
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?
|
2023-01-20 17:27:00 +00:00
|
|
|
public let spoilerText: HTMLString
|
2023-01-03 14:15:08 +00:00
|
|
|
public let filtered: [Filtered]?
|
2023-01-09 19:39:42 +00:00
|
|
|
public let sensitive: Bool
|
2023-01-17 06:07:26 +00:00
|
|
|
public let language: String?
|
2024-02-14 11:48:14 +00:00
|
|
|
|
2024-01-01 20:06:10 +00:00
|
|
|
public var isHidden: Bool {
|
|
|
|
filtered?.first?.filter.filterAction == .hide
|
|
|
|
}
|
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?) {
|
2023-02-18 06:15:57 +00:00
|
|
|
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-07-20 12:27:18 +00:00
|
|
|
content: .init(stringValue: "Here's to the [#crazy](#) ones. The misfits.\nThe [@rebels](#). The troublemakers.",
|
2023-03-26 17:19:59 +00:00
|
|
|
parseMarkdown: forSettings),
|
2023-02-12 15:29:41 +00:00
|
|
|
|
|
|
|
account: .placeholder(),
|
|
|
|
createdAt: ServerDate(),
|
|
|
|
editedAt: nil,
|
|
|
|
reblog: nil,
|
|
|
|
mediaAttachments: [],
|
|
|
|
mentions: [],
|
2024-01-22 20:20:43 +00:00
|
|
|
repliesCount: 34,
|
|
|
|
reblogsCount: 8,
|
|
|
|
favouritesCount: 150,
|
2023-02-12 15:29:41 +00:00
|
|
|
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] {
|
2023-12-27 15:07:16 +00:00
|
|
|
[.placeholder(), .placeholder(), .placeholder(), .placeholder(), .placeholder(),
|
|
|
|
.placeholder(), .placeholder(), .placeholder(), .placeholder(), .placeholder()]
|
2022-12-17 12:37:46 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2023-02-18 06:15:57 +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-25 12:02:28 +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-11-20 15:39:06 +00:00
|
|
|
public let id: String
|
2023-01-20 17:27:00 +00:00
|
|
|
public let content: HTMLString
|
2022-11-20 15:39:06 +00:00
|
|
|
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?
|
2023-01-17 14:14:50 +00:00
|
|
|
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]
|
2023-01-18 12:36:00 +00:00
|
|
|
public let url: String?
|
2023-02-27 05:39:07 +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?
|
2023-01-20 17:27:00 +00:00
|
|
|
public let spoilerText: HTMLString
|
2023-01-03 14:15:08 +00:00
|
|
|
public let filtered: [Filtered]?
|
2023-01-09 19:39:42 +00:00
|
|
|
public let sensitive: Bool
|
2023-01-17 06:07:26 +00:00
|
|
|
public let language: String?
|
2024-02-14 11:48:14 +00:00
|
|
|
|
2024-01-01 20:06:10 +00:00
|
|
|
public var isHidden: Bool {
|
|
|
|
filtered?.first?.filter.filterAction == .hide
|
|
|
|
}
|
2023-02-18 06:15:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-11-20 15:39:06 +00:00
|
|
|
}
|
2023-02-27 05:39:07 +00:00
|
|
|
|
|
|
|
// Every property in Status is immutable.
|
|
|
|
extension Status: Sendable {}
|
|
|
|
|
|
|
|
// Every property in ReblogStatus is immutable.
|
|
|
|
extension ReblogStatus: Sendable {}
|