2021-07-20 10:40:04 +02:00
|
|
|
//
|
|
|
|
// APIService+Status+Publish.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-7-20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import CommonOSLog
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
extension APIService {
|
|
|
|
|
|
|
|
func publishStatus(
|
|
|
|
domain: String,
|
2021-08-09 11:54:11 +02:00
|
|
|
idempotencyKey: String?,
|
2021-07-20 10:40:04 +02:00
|
|
|
query: Mastodon.API.Statuses.PublishStatusQuery,
|
2022-01-27 14:23:39 +01:00
|
|
|
authenticationBox: MastodonAuthenticationBox
|
|
|
|
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
|
|
|
|
let domain = authenticationBox.domain
|
|
|
|
let authorization = authenticationBox.userAuthorization
|
2021-07-20 10:40:04 +02:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
let response = try await Mastodon.API.Statuses.publishStatus(
|
2021-07-20 10:40:04 +02:00
|
|
|
session: session,
|
|
|
|
domain: domain,
|
2021-08-09 11:54:11 +02:00
|
|
|
idempotencyKey: idempotencyKey,
|
2021-07-20 10:40:04 +02:00
|
|
|
query: query,
|
|
|
|
authorization: authorization
|
2022-01-27 14:23:39 +01:00
|
|
|
).singleOutput()
|
|
|
|
|
|
|
|
#if !APP_EXTENSION
|
|
|
|
let managedObjectContext = self.backgroundManagedObjectContext
|
|
|
|
try await managedObjectContext.performChanges {
|
|
|
|
let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user
|
|
|
|
_ = Persistence.Status.createOrMerge(
|
|
|
|
in: managedObjectContext,
|
|
|
|
context: Persistence.Status.PersistContext(
|
|
|
|
domain: domain,
|
|
|
|
entity: response.value,
|
|
|
|
me: me,
|
|
|
|
statusCache: nil,
|
|
|
|
userCache: nil,
|
|
|
|
networkDate: response.networkDate
|
|
|
|
)
|
2021-07-20 10:40:04 +02:00
|
|
|
)
|
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return response
|
2021-07-20 10:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|