forked from shadowfacts/Tusker
parent
edd1e55cbb
commit
6a3dcca9ee
|
@ -44,6 +44,47 @@ public final class Status: StatusProtocol, Decodable {
|
|||
|
||||
public var applicationName: String? { application?.name }
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.id = try container.decode(String.self, forKey: .id)
|
||||
self.uri = try container.decode(String.self, forKey: .uri)
|
||||
self.url = try container.decodeIfPresent(WebURL.self, forKey: .url)
|
||||
self.account = try container.decode(Account.self, forKey: .account)
|
||||
self.inReplyToID = try container.decodeIfPresent(String.self, forKey: .inReplyToID)
|
||||
self.inReplyToAccountID = try container.decodeIfPresent(String.self, forKey: .inReplyToAccountID)
|
||||
self.reblog = try container.decodeIfPresent(Status.self, forKey: .reblog)
|
||||
self.content = try container.decode(String.self, forKey: .content)
|
||||
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
|
||||
self.emojis = try container.decode([Emoji].self, forKey: .emojis)
|
||||
self.reblogsCount = try container.decode(Int.self, forKey: .reblogsCount)
|
||||
self.favouritesCount = try container.decode(Int.self, forKey: .favouritesCount)
|
||||
self.reblogged = try container.decodeIfPresent(Bool.self, forKey: .reblogged)
|
||||
self.favourited = try container.decodeIfPresent(Bool.self, forKey: .favourited)
|
||||
self.muted = try container.decodeIfPresent(Bool.self, forKey: .muted)
|
||||
self.sensitive = try container.decode(Bool.self, forKey: .sensitive)
|
||||
self.spoilerText = try container.decode(String.self, forKey: .spoilerText)
|
||||
if let visibility = try? container.decode(Status.Visibility.self, forKey: .visibility) {
|
||||
self.visibility = visibility
|
||||
self.localOnly = try container.decodeIfPresent(Bool.self, forKey: .localOnly)
|
||||
} else if let s = try? container.decode(String.self, forKey: .visibility),
|
||||
s == "local" {
|
||||
// hacky workaround for #332, akkoma describes local posts with a separate visibility
|
||||
self.visibility = .public
|
||||
self.localOnly = true
|
||||
} else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .visibility, in: container, debugDescription: "Could not decode visibility")
|
||||
}
|
||||
self.attachments = try container.decode([Attachment].self, forKey: .attachments)
|
||||
self.mentions = try container.decode([Mention].self, forKey: .mentions)
|
||||
self.hashtags = try container.decode([Hashtag].self, forKey: .hashtags)
|
||||
self.application = try container.decodeIfPresent(Application.self, forKey: .application)
|
||||
self.language = try container.decodeIfPresent(String.self, forKey: .language)
|
||||
self.pinned = try container.decodeIfPresent(Bool.self, forKey: .pinned)
|
||||
self.bookmarked = try container.decodeIfPresent(Bool.self, forKey: .bookmarked)
|
||||
self.card = try container.decodeIfPresent(Card.self, forKey: .card)
|
||||
self.poll = try container.decodeIfPresent(Poll.self, forKey: .poll)
|
||||
}
|
||||
|
||||
public static func getContext(_ statusID: String) -> Request<ConversationContext> {
|
||||
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(statusID)/context")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue