forked from zelo72/mastodon-ios
55 lines
1.6 KiB
Swift
55 lines
1.6 KiB
Swift
//
|
|
// APIService+Thread.swift
|
|
// Mastodon
|
|
//
|
|
// Created by MainasuK Cirno on 2021-4-12.
|
|
//
|
|
|
|
import os.log
|
|
import Foundation
|
|
import Combine
|
|
import CoreData
|
|
import CoreDataStack
|
|
import MastodonSDK
|
|
|
|
extension APIService {
|
|
|
|
func statusContext(
|
|
statusID: Mastodon.Entity.Status.ID,
|
|
authenticationBox: MastodonAuthenticationBox
|
|
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Context> {
|
|
let domain = authenticationBox.domain
|
|
let authorization = authenticationBox.userAuthorization
|
|
|
|
let response = try await Mastodon.API.Statuses.statusContext(
|
|
session: session,
|
|
domain: domain,
|
|
statusID: statusID,
|
|
authorization: authorization
|
|
).singleOutput()
|
|
|
|
let managedObjectContext = self.backgroundManagedObjectContext
|
|
try await managedObjectContext.performChanges {
|
|
let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user
|
|
let value = response.value.ancestors + response.value.descendants
|
|
|
|
for entity in value {
|
|
_ = Persistence.Status.createOrMerge(
|
|
in: managedObjectContext,
|
|
context: Persistence.Status.PersistContext(
|
|
domain: domain,
|
|
entity: entity,
|
|
me: me,
|
|
statusCache: nil,
|
|
userCache: nil,
|
|
networkDate: response.networkDate
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
return response
|
|
} // end func
|
|
|
|
}
|