2022-11-20 15:39:06 +00:00
import Foundation
2023-02-27 05:39:07 +00:00
import Atomics
2022-11-20 15:39:06 +00:00
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 )
}
}
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 {
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 }
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 }
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
2023-02-22 06:09:56 +00:00
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 {
2023-02-22 06:09:56 +00:00
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 {
2023-02-21 11:35:07 +00:00
lhs . id = = rhs . id && lhs . viewId = = rhs . viewId
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 ?
2023-01-17 10:36:01 +00:00
2023-02-27 05:39:07 +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-02-12 15:29:41 +00:00
content : . init ( stringValue : " Lorem ipsum [#dolor](#) sit amet \n consectetur [@adipiscing](#) elit \n Ased 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
}
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 ?
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
extension Application : Sendable { }
extension StatusViewId : Sendable { }
// E v e r y p r o p e r t y i n S t a t u s i s i m m u t a b l e .
extension Status : Sendable { }
// E v e r y p r o p e r t y i n R e b l o g S t a t u s i s i m m u t a b l e .
extension ReblogStatus : Sendable { }