This commit is contained in:
Justin Mazzocchi 2020-10-05 13:22:47 -07:00
parent 18d1b61101
commit 9ac6ed2d93
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
2 changed files with 9 additions and 9 deletions

View File

@ -9,27 +9,27 @@ import MastodonAPI
public struct ContextService {
public let sections: AnyPublisher<[[CollectionItem]], Error>
public let navigationService: NavigationService
public var contextParentID: String? { statusID }
public var contextParentID: String? { parentID }
private let statusID: String
private let parentID: String
private let mastodonAPIClient: MastodonAPIClient
private let contentDatabase: ContentDatabase
init(statusID: String, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
self.statusID = statusID
init(parentID: String, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
self.parentID = parentID
self.mastodonAPIClient = mastodonAPIClient
self.contentDatabase = contentDatabase
sections = contentDatabase.contextObservation(parentID: statusID)
sections = contentDatabase.contextObservation(parentID: parentID)
navigationService = NavigationService(mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase)
}
}
extension ContextService: CollectionService {
public func request(maxID: String?, minID: String?) -> AnyPublisher<Never, Error> {
mastodonAPIClient.request(StatusEndpoint.status(id: statusID))
mastodonAPIClient.request(StatusEndpoint.status(id: parentID))
.flatMap(contentDatabase.insert(status:))
.merge(with: mastodonAPIClient.request(ContextEndpoint.context(id: statusID))
.flatMap { contentDatabase.insert(context: $0, parentID: statusID) })
.merge(with: mastodonAPIClient.request(ContextEndpoint.context(id: parentID))
.flatMap { contentDatabase.insert(context: $0, parentID: parentID) })
.eraseToAnyPublisher()
}
}

View File

@ -50,7 +50,7 @@ public extension NavigationService {
}
func contextService(id: String) -> ContextService {
ContextService(statusID: id, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase)
ContextService(parentID: id, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase)
}
func profileService(id: String) -> ProfileService {