2020-08-18 05:13:37 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
|
2020-08-19 22:16:03 +00:00
|
|
|
struct TimelineService {
|
2020-08-18 05:13:37 +00:00
|
|
|
let statusSections: AnyPublisher<[[Status]], Error>
|
|
|
|
|
|
|
|
private let timeline: Timeline
|
|
|
|
private let networkClient: MastodonClient
|
|
|
|
private let contentDatabase: ContentDatabase
|
|
|
|
|
|
|
|
init(timeline: Timeline, networkClient: MastodonClient, contentDatabase: ContentDatabase) {
|
|
|
|
self.timeline = timeline
|
|
|
|
self.networkClient = networkClient
|
|
|
|
self.contentDatabase = contentDatabase
|
|
|
|
statusSections = contentDatabase.statusesObservation(timeline: timeline)
|
|
|
|
.map { [$0] }
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
}
|
2020-08-19 22:16:03 +00:00
|
|
|
}
|
2020-08-18 05:13:37 +00:00
|
|
|
|
2020-08-19 22:16:03 +00:00
|
|
|
extension TimelineService: StatusListService {
|
2020-08-26 09:19:38 +00:00
|
|
|
func request(maxID: String?, minID: String?) -> AnyPublisher<Never, Error> {
|
2020-08-18 05:13:37 +00:00
|
|
|
return networkClient.request(timeline.endpoint)
|
|
|
|
.map { ($0, timeline) }
|
|
|
|
.flatMap(contentDatabase.insert(statuses:collection:))
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
}
|
2020-08-19 22:16:03 +00:00
|
|
|
|
2020-08-21 02:29:01 +00:00
|
|
|
func statusService(status: Status) -> StatusService {
|
|
|
|
StatusService(status: status, networkClient: networkClient, contentDatabase: contentDatabase)
|
|
|
|
}
|
|
|
|
|
2020-08-19 22:16:03 +00:00
|
|
|
func contextService(status: Status) -> ContextService {
|
2020-08-21 02:29:01 +00:00
|
|
|
ContextService(status: status.displayStatus, networkClient: networkClient, contentDatabase: contentDatabase)
|
2020-08-19 22:16:03 +00:00
|
|
|
}
|
2020-08-18 05:13:37 +00:00
|
|
|
}
|