2018-09-11 14:52:21 +00:00
|
|
|
//
|
|
|
|
// Status.swift
|
|
|
|
// Pachyderm
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/9/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-05-11 21:57:50 +00:00
|
|
|
public final class Status: /*StatusProtocol,*/ Decodable {
|
2018-09-11 14:52:21 +00:00
|
|
|
public let id: String
|
|
|
|
public let uri: String
|
|
|
|
public let url: URL?
|
|
|
|
public let account: Account
|
|
|
|
public let inReplyToID: String?
|
|
|
|
public let inReplyToAccountID: String?
|
2018-09-17 23:22:37 +00:00
|
|
|
public let reblog: Status?
|
2018-09-11 14:52:21 +00:00
|
|
|
public let content: String
|
|
|
|
public let createdAt: Date
|
2018-09-17 23:22:37 +00:00
|
|
|
public let emojis: [Emoji]
|
2018-09-11 14:52:21 +00:00
|
|
|
// TODO: missing from pleroma
|
|
|
|
// public let repliesCount: Int
|
|
|
|
public let reblogsCount: Int
|
|
|
|
public let favouritesCount: Int
|
2020-05-11 21:57:50 +00:00
|
|
|
public let reblogged: Bool?
|
|
|
|
public let favourited: Bool?
|
2018-09-17 23:22:37 +00:00
|
|
|
public let muted: Bool?
|
2018-09-11 14:52:21 +00:00
|
|
|
public let sensitive: Bool
|
|
|
|
public let spoilerText: String
|
|
|
|
public let visibility: Visibility
|
2018-09-17 23:22:37 +00:00
|
|
|
public let attachments: [Attachment]
|
|
|
|
public let mentions: [Mention]
|
|
|
|
public let hashtags: [Hashtag]
|
|
|
|
public let application: Application?
|
2018-09-11 14:52:21 +00:00
|
|
|
public let language: String?
|
2018-09-17 23:22:37 +00:00
|
|
|
public let pinned: Bool?
|
2019-12-14 17:40:50 +00:00
|
|
|
public let bookmarked: Bool?
|
2020-03-05 02:14:58 +00:00
|
|
|
public let card: Card?
|
2021-04-28 23:00:17 +00:00
|
|
|
public let poll: Poll?
|
2022-02-04 04:11:29 +00:00
|
|
|
// Hometown, Glitch only
|
2022-01-23 15:57:32 +00:00
|
|
|
public let localOnly: Bool?
|
2018-09-11 14:52:21 +00:00
|
|
|
|
2020-05-06 22:40:12 +00:00
|
|
|
public var applicationName: String? { application?.name }
|
|
|
|
|
2020-04-14 02:41:31 +00:00
|
|
|
public static func getContext(_ statusID: String) -> Request<ConversationContext> {
|
|
|
|
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(statusID)/context")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 23:22:37 +00:00
|
|
|
public static func getCard(_ status: Status) -> Request<Card> {
|
|
|
|
return Request<Card>(method: .get, path: "/api/v1/statuses/\(status.id)/card")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:20:09 +00:00
|
|
|
public static func getFavourites(_ statusID: String, range: RequestRange = .default) -> Request<[Account]> {
|
|
|
|
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(statusID)/favourited_by")
|
2018-09-11 14:52:21 +00:00
|
|
|
request.range = range
|
2018-09-17 23:22:37 +00:00
|
|
|
return request
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:20:09 +00:00
|
|
|
public static func getReblogs(_ statusID: String, range: RequestRange = .default) -> Request<[Account]> {
|
|
|
|
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(statusID)/reblogged_by")
|
2018-09-11 14:52:21 +00:00
|
|
|
request.range = range
|
2018-09-17 23:22:37 +00:00
|
|
|
return request
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 23:22:37 +00:00
|
|
|
public static func delete(_ status: Status) -> Request<Empty> {
|
|
|
|
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:32:16 +00:00
|
|
|
public static func reblog(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/reblog")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:32:16 +00:00
|
|
|
public static func unreblog(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unreblog")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:32:16 +00:00
|
|
|
public static func favourite(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/favourite")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:32:16 +00:00
|
|
|
public static func unfavourite(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unfavourite")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:57:00 +00:00
|
|
|
public static func pin(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/pin")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:57:00 +00:00
|
|
|
public static func unpin(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unpin")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:57:00 +00:00
|
|
|
public static func bookmark(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/bookmark")
|
2019-12-14 17:40:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:25:41 +00:00
|
|
|
public static func unbookmark(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unbookmark")
|
2019-12-14 17:40:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:57:00 +00:00
|
|
|
public static func muteConversation(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/mute")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:57:00 +00:00
|
|
|
public static func unmuteConversation(_ statusID: String) -> Request<Status> {
|
|
|
|
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unmute")
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-12-14 17:40:50 +00:00
|
|
|
case bookmarked
|
2020-03-05 02:14:58 +00:00
|
|
|
case card
|
2021-04-28 23:00:17 +00:00
|
|
|
case poll
|
2022-01-23 15:57:32 +00:00
|
|
|
case localOnly = "local_only"
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Status {
|
|
|
|
public enum Visibility: String, Codable, CaseIterable {
|
|
|
|
case `public`
|
|
|
|
case unlisted
|
|
|
|
case `private`
|
|
|
|
case direct
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 18:33:10 +00:00
|
|
|
|
|
|
|
extension Status: Identifiable {}
|