Impressia/Vernissage/EnvironmentObjects/Client+Statuses.swift

87 lines
3.2 KiB
Swift
Raw Normal View History

2023-02-03 15:16:30 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-02-03 15:16:30 +01:00
//
import Foundation
2023-02-19 10:32:38 +01:00
import PixelfedKit
2023-02-03 15:16:30 +01:00
extension Client {
public class Statuses: BaseClient {
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
}
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
}
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
}
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
}
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
}
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
}
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] = []
2023-02-03 15:16:30 +01:00
try await self.getCommentDescendants(to: statusId, showDivider: true, to: &commentViewModels)
2023-02-03 15:16:30 +01:00
return commentViewModels
}
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
}
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
}
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)
let descendants = context.descendants.toStatusModels()
2023-02-03 15:16:30 +01:00
for status in descendants {
commentViewModels.append(CommentModel(status: status, showDivider: showDivider))
2023-02-03 15:16:30 +01:00
if status.repliesCount > 0 {
try await self.getCommentDescendants(to: status.id, showDivider: false, to: &commentViewModels)
}
}
}
}
}