mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonCore/Service/API/APIService+Thread.swift

53 lines
1.6 KiB
Swift
Raw Normal View History

2021-04-13 13:46:42 +02:00
//
// APIService+Thread.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-12.
//
import Foundation
import Combine
import CoreData
import CoreDataStack
import MastodonSDK
extension APIService {
2022-10-08 07:43:06 +02:00
public func statusContext(
2021-04-13 13:46:42 +02:00
statusID: Mastodon.Entity.Status.ID,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Context> {
let domain = authenticationBox.domain
let authorization = authenticationBox.userAuthorization
2021-04-13 13:46:42 +02:00
let response = try await Mastodon.API.Statuses.statusContext(
2021-04-13 13:46:42 +02:00
session: session,
domain: domain,
statusID: statusID,
authorization: authorization
).singleOutput()
let managedObjectContext = self.backgroundManagedObjectContext
try await managedObjectContext.performChanges {
let me = authenticationBox.authentication.user(in: managedObjectContext)
let value = response.value.ancestors + response.value.descendants
for entity in value {
2022-05-07 05:42:10 +02:00
_ = Persistence.Status.createOrMerge(
in: managedObjectContext,
context: Persistence.Status.PersistContext(
domain: domain,
entity: entity,
me: me,
statusCache: nil,
userCache: nil,
networkDate: response.networkDate
)
)
2021-04-13 13:46:42 +02:00
}
}
return response
} // end func
2021-04-13 13:46:42 +02:00
}