mirror of
https://github.com/VernissageApp/Vernissage.git
synced 2024-12-27 09:23:45 +01:00
68 lines
2.6 KiB
Swift
68 lines
2.6 KiB
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the MIT License.
|
|
//
|
|
|
|
import Foundation
|
|
import MastodonSwift
|
|
|
|
public class StatusService {
|
|
public static let shared = StatusService()
|
|
private init() { }
|
|
|
|
func favourite(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.favourite(statusId: statusId)
|
|
}
|
|
|
|
func unfavourite(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.unfavourite(statusId: statusId)
|
|
}
|
|
|
|
func boost(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.boost(statusId: statusId)
|
|
}
|
|
|
|
func unboost(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.unboost(statusId: statusId)
|
|
}
|
|
|
|
func bookmark(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.bookmark(statusId: statusId)
|
|
}
|
|
|
|
func unbookmark(statusId: String, accountData: AccountData?) async throws -> Status? {
|
|
guard let accessToken = accountData?.accessToken, let serverUrl = accountData?.serverUrl else {
|
|
return nil
|
|
}
|
|
|
|
let client = MastodonClient(baseURL: serverUrl).getAuthenticated(token: accessToken)
|
|
return try await client.unbookmark(statusId: statusId)
|
|
}
|
|
}
|