144 lines
4.9 KiB
Swift
144 lines
4.9 KiB
Swift
//
|
|
// Status.swift
|
|
// Pachyderm
|
|
//
|
|
// Created by Shadowfacts on 9/9/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public class Status: Decodable {
|
|
public let id: String
|
|
public let uri: String
|
|
public let url: URL?
|
|
public let account: Account
|
|
public let inReplyToID: String?
|
|
public let inReplyToAccountID: String?
|
|
public let reblog: Status?
|
|
public let content: String
|
|
public let createdAt: Date
|
|
public let emojis: [Emoji]
|
|
// TODO: missing from pleroma
|
|
// public let repliesCount: Int
|
|
public let reblogsCount: Int
|
|
public let favouritesCount: Int
|
|
public let reblogged: Bool?
|
|
public let favourited: Bool?
|
|
public let muted: Bool?
|
|
public let sensitive: Bool
|
|
public let spoilerText: String
|
|
public let visibility: Visibility
|
|
public let attachments: [Attachment]
|
|
public let mentions: [Mention]
|
|
public let hashtags: [Hashtag]
|
|
public let application: Application?
|
|
public let language: String?
|
|
public let pinned: Bool?
|
|
public let bookmarked: Bool?
|
|
|
|
public static func getContext(_ status: Status) -> Request<ConversationContext> {
|
|
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(status.id)/context")
|
|
}
|
|
|
|
public static func getCard(_ status: Status) -> Request<Card> {
|
|
return Request<Card>(method: .get, path: "/api/v1/statuses/\(status.id)/card")
|
|
}
|
|
|
|
public static func getFavourites(_ status: Status, range: RequestRange = .default) -> Request<[Account]> {
|
|
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(status.id)/favourited_by")
|
|
request.range = range
|
|
return request
|
|
}
|
|
|
|
public static func getReblogs(_ status: Status, range: RequestRange = .default) -> Request<[Account]> {
|
|
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(status.id)/reblogged_by")
|
|
request.range = range
|
|
return request
|
|
}
|
|
|
|
public static func delete(_ status: Status) -> Request<Empty> {
|
|
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
|
|
}
|
|
|
|
public static func reblog(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/reblog")
|
|
}
|
|
|
|
public static func unreblog(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unreblog")
|
|
}
|
|
|
|
public static func favourite(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/favourite")
|
|
}
|
|
|
|
public static func unfavourite(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unfavourite")
|
|
}
|
|
|
|
public static func pin(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/pin")
|
|
}
|
|
|
|
public static func unpin(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unpin")
|
|
}
|
|
|
|
public static func bookmark(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/bookmark")
|
|
}
|
|
|
|
public static func unbookmark(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unbookmark")
|
|
}
|
|
|
|
public static func muteConversation(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/mute")
|
|
}
|
|
|
|
public static func unmuteConversation(_ status: Status) -> Request<Status> {
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unmute")
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case uri
|
|
case url
|
|
case account
|
|
case inReplyToID = "in_reply_to_id"
|
|
case inReplyToAccountID = "in_reply_to_account_id"
|
|
case reblog
|
|
case content
|
|
case createdAt = "created_at"
|
|
case emojis
|
|
// case repliesCount = "replies_count"
|
|
case reblogsCount = "reblogs_count"
|
|
case favouritesCount = "favourites_count"
|
|
case reblogged
|
|
case favourited
|
|
case muted
|
|
case sensitive
|
|
case spoilerText = "spoiler_text"
|
|
case visibility
|
|
case attachments = "media_attachments"
|
|
case mentions
|
|
case hashtags = "tags"
|
|
case application
|
|
case language
|
|
case pinned
|
|
case bookmarked
|
|
}
|
|
}
|
|
|
|
extension Status {
|
|
public enum Visibility: String, Codable, CaseIterable {
|
|
case `public`
|
|
case unlisted
|
|
case `private`
|
|
case direct
|
|
}
|
|
}
|
|
|
|
extension Status: Identifiable {}
|