1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-20 14:32:48 +01:00
metatext-app-ios-iphone-ipad/Services/StatusService.swift
Justin Mazzocchi f86d8188b3
Renaming
2020-08-30 16:59:49 -07:00

29 lines
884 B
Swift

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import Combine
import Mastodon
struct StatusService {
let status: Status
private let networkClient: APIClient
private let contentDatabase: ContentDatabase
init(status: Status, networkClient: APIClient, contentDatabase: ContentDatabase) {
self.status = status
self.networkClient = networkClient
self.contentDatabase = contentDatabase
}
}
extension StatusService {
func toggleFavorited() -> AnyPublisher<Never, Error> {
networkClient.request(status.favourited
? StatusEndpoint.unfavourite(id: status.id)
: StatusEndpoint.favourite(id: status.id))
.map { ([$0], nil) }
.flatMap(contentDatabase.insert(statuses:collection:))
.eraseToAnyPublisher()
}
}