Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Service/APIService/APIService+PublicTimeline.s...

53 lines
1.6 KiB
Swift
Raw Normal View History

//
// APIService+PublicTimeline.swift
// Mastodon
//
// Created by MainasuK on 2022-4-29.
//
import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK
extension APIService {
func publicTimeline(
query: Mastodon.API.Timeline.PublicTimelineQuery,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Status]> {
let domain = authenticationBox.domain
let authorization = authenticationBox.userAuthorization
let response = try await Mastodon.API.Timeline.public(
session: session,
domain: domain,
query: query,
authorization: authorization
).singleOutput()
let managedObjectContext = self.backgroundManagedObjectContext
try await managedObjectContext.performChanges {
let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user
for entity in response.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
}