2023-02-03 15:16:30 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2023-02-19 10:32:38 +01:00
|
|
|
import PixelfedKit
|
2023-02-03 15:16:30 +01:00
|
|
|
|
2023-02-19 10:43:37 +01:00
|
|
|
/// Pixelfed 'Statuses'.
|
2023-02-03 15:16:30 +01:00
|
|
|
extension Client {
|
|
|
|
public class Statuses: BaseClient {
|
|
|
|
|
2023-02-12 20:55:20 +01:00
|
|
|
public func status(withId statusId: String) async throws -> Status {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.status(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func favourite(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.favourite(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func unfavourite(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.unfavourite(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-18 20:59:21 +01:00
|
|
|
func pin(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.pin(statusId: statusId)
|
2023-02-18 20:59:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func unpin(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.unpin(statusId: statusId)
|
2023-02-18 20:59:21 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 15:16:30 +01:00
|
|
|
func boost(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.boost(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func unboost(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.unboost(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func bookmark(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.bookmark(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func unbookmark(statusId: String) async throws -> Status? {
|
2023-02-19 10:43:37 +01:00
|
|
|
return try await pixelfedClient.unbookmark(statusId: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-19 10:43:37 +01:00
|
|
|
func new(status: Pixelfed.Statuses.Components) async throws -> Status? {
|
|
|
|
return try await pixelfedClient.new(statusComponents: status)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-18 20:59:21 +01:00
|
|
|
func delete(statusId: String) async throws {
|
2023-02-19 10:43:37 +01:00
|
|
|
try await pixelfedClient.delete(statusId: statusId)
|
2023-02-18 20:59:21 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 15:16:30 +01:00
|
|
|
func comments(to statusId: String) async throws -> [CommentModel] {
|
|
|
|
var commentViewModels: [CommentModel] = []
|
|
|
|
|
|
|
|
try await self.getCommentDescendants(to: statusId, showDivider: true, to: &commentViewModels)
|
|
|
|
|
|
|
|
return commentViewModels
|
|
|
|
}
|
|
|
|
|
2023-02-23 10:56:42 +01:00
|
|
|
public func favouritedBy(statusId: String, limit: Int, page: Int) async throws -> [Account] {
|
|
|
|
return try await pixelfedClient.favouritedBy(for: statusId, limit: limit, page: page)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 10:56:42 +01:00
|
|
|
public func rebloggedBy(statusId: String, limit: Int, page: Int) async throws -> [Account] {
|
|
|
|
return try await pixelfedClient.rebloggedBy(for: statusId, limit: limit, page: page)
|
2023-02-03 15:16:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private func getCommentDescendants(to statusId: String, showDivider: Bool, to commentViewModels: inout [CommentModel]) async throws {
|
2023-02-19 10:43:37 +01:00
|
|
|
let context = try await pixelfedClient.getContext(for: statusId)
|
2023-02-03 15:16:30 +01:00
|
|
|
|
2023-02-21 10:55:17 +01:00
|
|
|
let descendants = context.descendants.toStatusModels()
|
2023-02-03 15:16:30 +01:00
|
|
|
for status in descendants {
|
|
|
|
commentViewModels.append(CommentModel(status: status, showDivider: showDivider))
|
|
|
|
|
|
|
|
if status.repliesCount > 0 {
|
|
|
|
try await self.getCommentDescendants(to: status.id, showDivider: false, to: &commentViewModels)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|