mirror of
https://github.com/metabolist/metatext.git
synced 2024-05-15 06:53:02 +00:00
30 lines
966 B
Swift
30 lines
966 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Combine
|
|
import DB
|
|
import Foundation
|
|
import Mastodon
|
|
import MastodonAPI
|
|
|
|
public struct StatusService {
|
|
public let status: Status
|
|
private let mastodonAPIClient: MastodonAPIClient
|
|
private let contentDatabase: ContentDatabase
|
|
|
|
init(status: Status, networkClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
|
|
self.status = status
|
|
self.mastodonAPIClient = networkClient
|
|
self.contentDatabase = contentDatabase
|
|
}
|
|
}
|
|
|
|
public extension StatusService {
|
|
func toggleFavorited() -> AnyPublisher<Never, Error> {
|
|
mastodonAPIClient.request(status.displayStatus.favourited
|
|
? StatusEndpoint.unfavourite(id: status.displayStatus.id)
|
|
: StatusEndpoint.favourite(id: status.displayStatus.id))
|
|
.flatMap(contentDatabase.insert(status:))
|
|
.eraseToAnyPublisher()
|
|
}
|
|
}
|