fix: Make translatedContent a transient CoreData property
This commit is contained in:
parent
518941b10c
commit
855f626c42
|
@ -60,9 +60,10 @@ private extension DataSourceFacade {
|
|||
|
||||
static func translateAndApply(provider: Provider, status: Status) async throws {
|
||||
do {
|
||||
status.translatedContent = try await translateStatus(provider: provider, status: status)
|
||||
let translated = try await translateStatus(provider: provider, status: status)
|
||||
status.update(translatedContent: translated)
|
||||
} catch {
|
||||
status.translatedContent = nil
|
||||
status.update(translatedContent: nil)
|
||||
throw TranslationFailure.emptyOrInvalidResponse
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21512" systemVersion="22A400" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21512" systemVersion="22C65" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Application" representedClassName="CoreDataStack.Application" syncable="YES">
|
||||
<attribute name="identifier" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
|
@ -201,6 +201,7 @@
|
|||
<attribute name="sensitive" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="spoilerText" optional="YES" attributeType="String"/>
|
||||
<attribute name="text" optional="YES" attributeType="String"/>
|
||||
<attribute name="translatedContent" optional="YES" transient="YES" attributeType="String"/>
|
||||
<attribute name="updatedAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="uri" attributeType="String"/>
|
||||
<attribute name="url" optional="YES" attributeType="String"/>
|
||||
|
|
|
@ -100,7 +100,8 @@ public final class Status: NSManagedObject {
|
|||
// sourcery: autoUpdatableObject
|
||||
@NSManaged public private(set) var revealedAt: Date?
|
||||
|
||||
@Published public var translatedContent: String?
|
||||
// sourcery: autoUpdatableObject
|
||||
@NSManaged public private(set) var translatedContent: String?
|
||||
}
|
||||
|
||||
extension Status {
|
||||
|
@ -497,6 +498,11 @@ extension Status: AutoUpdatableObject {
|
|||
self.revealedAt = revealedAt
|
||||
}
|
||||
}
|
||||
public func update(translatedContent: String?) {
|
||||
if self.translatedContent != translatedContent {
|
||||
self.translatedContent = translatedContent
|
||||
}
|
||||
}
|
||||
public func update(attachments: [MastodonAttachment]) {
|
||||
if self.attachments != attachments {
|
||||
self.attachments = attachments
|
||||
|
|
|
@ -57,8 +57,8 @@ extension StatusView {
|
|||
configureFilter(status: status)
|
||||
viewModel.originalStatus = status
|
||||
[
|
||||
status.$translatedContent,
|
||||
status.reblog?.$translatedContent
|
||||
status.publisher(for: \.translatedContent),
|
||||
status.reblog?.publisher(for: \.translatedContent)
|
||||
].compactMap { $0 }
|
||||
.last?
|
||||
.receive(on: DispatchQueue.main)
|
||||
|
@ -245,8 +245,8 @@ extension StatusView {
|
|||
func revertTranslation() {
|
||||
guard let originalStatus = viewModel.originalStatus else { return }
|
||||
viewModel.translatedFromLanguage = nil
|
||||
originalStatus.reblog?.translatedContent = nil
|
||||
originalStatus.translatedContent = nil
|
||||
originalStatus.reblog?.update(translatedContent: nil)
|
||||
originalStatus.update(translatedContent: nil)
|
||||
configure(status: originalStatus)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue