Remove CoreData entities and references of StatusEdit
This commit is contained in:
parent
1806f9a350
commit
79f978cee7
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="22G74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="23B74" 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"/>
|
||||
|
@ -225,7 +225,6 @@
|
|||
<relationship name="author" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="statuses" inverseEntity="MastodonUser"/>
|
||||
<relationship name="bookmarkedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="bookmarked" inverseEntity="MastodonUser"/>
|
||||
<relationship name="card" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Card" inverseName="status" inverseEntity="Card"/>
|
||||
<relationship name="editHistory" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="StatusEdit" inverseName="status" inverseEntity="StatusEdit"/>
|
||||
<relationship name="favouritedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="favourite" inverseEntity="MastodonUser"/>
|
||||
<relationship name="feeds" toMany="YES" deletionRule="Cascade" destinationEntity="Feed" inverseName="status" inverseEntity="Feed"/>
|
||||
<relationship name="mutedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="muted" inverseEntity="MastodonUser"/>
|
||||
|
@ -239,17 +238,6 @@
|
|||
<relationship name="replyTo" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="replyFrom" inverseEntity="Status"/>
|
||||
<relationship name="searchHistories" toMany="YES" deletionRule="Cascade" destinationEntity="SearchHistory" inverseName="status" inverseEntity="SearchHistory"/>
|
||||
</entity>
|
||||
<entity name="StatusEdit" representedClassName="CoreDataStack.StatusEdit" syncable="YES">
|
||||
<attribute name="attachments" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="content" optional="YES" attributeType="String"/>
|
||||
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="emojis" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="poll" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="sensitive" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="spoilerText" optional="YES" attributeType="String"/>
|
||||
<relationship name="author" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser"/>
|
||||
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="editHistory" inverseEntity="Status"/>
|
||||
</entity>
|
||||
<entity name="Subscription" representedClassName="CoreDataStack.Subscription" syncable="YES">
|
||||
<attribute name="activedAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
|
|
|
@ -99,8 +99,6 @@ public final class Status: NSManagedObject {
|
|||
@NSManaged public private(set) var replyFrom: Set<Status>
|
||||
@NSManaged public private(set) var notifications: Set<Notification>
|
||||
@NSManaged public private(set) var searchHistories: Set<SearchHistory>
|
||||
|
||||
@NSManaged public private(set) var editHistory: Set<StatusEdit>?
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public private(set) var updatedAt: Date
|
||||
|
@ -590,10 +588,6 @@ extension Status: AutoUpdatableObject {
|
|||
public func update(isReveal: Bool) {
|
||||
revealedAt = isReveal ? Date() : nil
|
||||
}
|
||||
|
||||
public func update(editHistory: Set<StatusEdit>) {
|
||||
self.editHistory = editHistory
|
||||
}
|
||||
}
|
||||
|
||||
extension Status {
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
public final class StatusEdit: NSManagedObject {
|
||||
public final class Poll: NSObject, Codable {
|
||||
public final class Option: NSObject, Codable {
|
||||
public let title: String
|
||||
|
||||
public init(title: String) {
|
||||
self.title = title
|
||||
}
|
||||
}
|
||||
public let options: [Option]
|
||||
|
||||
public init(options: [Option]) {
|
||||
self.options = options
|
||||
}
|
||||
}
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public var createdAt: Date
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public var content: String
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public var sensitive: Bool
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public var spoilerText: String?
|
||||
|
||||
// MARK: - AutoGenerateProperty
|
||||
// sourcery:inline:StatusEdit.AutoGenerateProperty
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public struct Property {
|
||||
public let createdAt: Date
|
||||
public let content: String
|
||||
public let sensitive: Bool
|
||||
public let spoilerText: String?
|
||||
public let emojis: [MastodonEmoji]
|
||||
public let attachments: [MastodonAttachment]
|
||||
public let poll: Poll?
|
||||
|
||||
public init(
|
||||
createdAt: Date,
|
||||
content: String,
|
||||
sensitive: Bool,
|
||||
spoilerText: String?,
|
||||
emojis: [MastodonEmoji],
|
||||
attachments: [MastodonAttachment],
|
||||
poll: Poll?
|
||||
) {
|
||||
self.createdAt = createdAt
|
||||
self.content = content
|
||||
self.sensitive = sensitive
|
||||
self.spoilerText = spoilerText
|
||||
self.emojis = emojis
|
||||
self.attachments = attachments
|
||||
self.poll = poll
|
||||
}
|
||||
}
|
||||
|
||||
public func configure(property: Property) {
|
||||
self.createdAt = property.createdAt
|
||||
self.content = property.content
|
||||
self.sensitive = property.sensitive
|
||||
self.spoilerText = property.spoilerText
|
||||
self.emojis = property.emojis
|
||||
self.attachments = property.attachments
|
||||
self.poll = property.poll
|
||||
}
|
||||
|
||||
public func update(property: Property) {
|
||||
update(createdAt: property.createdAt)
|
||||
update(content: property.content)
|
||||
update(sensitive: property.sensitive)
|
||||
update(spoilerText: property.spoilerText)
|
||||
update(emojis: property.emojis)
|
||||
update(attachments: property.attachments)
|
||||
update(poll: property.poll)
|
||||
}
|
||||
// sourcery:end
|
||||
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@objc public var emojis: [MastodonEmoji] {
|
||||
get {
|
||||
let keyPath = #keyPath(StatusEdit.emojis)
|
||||
willAccessValue(forKey: keyPath)
|
||||
let _data = primitiveValue(forKey: keyPath) as? Data
|
||||
didAccessValue(forKey: keyPath)
|
||||
do {
|
||||
guard let data = _data else { return [] }
|
||||
let emojis = try JSONDecoder().decode([MastodonEmoji].self, from: data)
|
||||
return emojis
|
||||
} catch {
|
||||
assertionFailure(error.localizedDescription)
|
||||
return []
|
||||
}
|
||||
}
|
||||
set {
|
||||
let keyPath = #keyPath(StatusEdit.emojis)
|
||||
let data = try? JSONEncoder().encode(newValue)
|
||||
willChangeValue(forKey: keyPath)
|
||||
setPrimitiveValue(data, forKey: keyPath)
|
||||
didChangeValue(forKey: keyPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension StatusEdit {
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@objc public var attachments: [MastodonAttachment] {
|
||||
get {
|
||||
let keyPath = #keyPath(StatusEdit.attachments)
|
||||
willAccessValue(forKey: keyPath)
|
||||
let _data = primitiveValue(forKey: keyPath) as? Data
|
||||
didAccessValue(forKey: keyPath)
|
||||
do {
|
||||
guard let data = _data else { return [] }
|
||||
let attachments = try JSONDecoder().decode([MastodonAttachment].self, from: data)
|
||||
return attachments
|
||||
} catch {
|
||||
assertionFailure(error.localizedDescription)
|
||||
return []
|
||||
}
|
||||
}
|
||||
set {
|
||||
let keyPath = #keyPath(StatusEdit.attachments)
|
||||
let data = try? JSONEncoder().encode(newValue)
|
||||
willChangeValue(forKey: keyPath)
|
||||
setPrimitiveValue(data, forKey: keyPath)
|
||||
didChangeValue(forKey: keyPath)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension StatusEdit {
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@objc public var poll: Poll? {
|
||||
get {
|
||||
let keyPath = #keyPath(StatusEdit.poll)
|
||||
willAccessValue(forKey: keyPath)
|
||||
let _data = primitiveValue(forKey: keyPath) as? Data
|
||||
didAccessValue(forKey: keyPath)
|
||||
do {
|
||||
guard let data = _data else { return nil }
|
||||
let poll = try JSONDecoder().decode(Poll.self, from: data)
|
||||
return poll
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
set {
|
||||
let keyPath = #keyPath(StatusEdit.poll)
|
||||
let data = try? JSONEncoder().encode(newValue)
|
||||
willChangeValue(forKey: keyPath)
|
||||
setPrimitiveValue(data, forKey: keyPath)
|
||||
didChangeValue(forKey: keyPath)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension StatusEdit: Managed {
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property
|
||||
) -> StatusEdit {
|
||||
let object: StatusEdit = context.insertObject()
|
||||
|
||||
object.configure(property: property)
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
extension StatusEdit: AutoUpdatableObject {
|
||||
// sourcery:inline:StatusEdit.AutoUpdatableObject
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public func update(createdAt: Date) {
|
||||
if self.createdAt != createdAt {
|
||||
self.createdAt = createdAt
|
||||
}
|
||||
}
|
||||
public func update(content: String) {
|
||||
if self.content != content {
|
||||
self.content = content
|
||||
}
|
||||
}
|
||||
public func update(sensitive: Bool) {
|
||||
if self.sensitive != sensitive {
|
||||
self.sensitive = sensitive
|
||||
}
|
||||
}
|
||||
public func update(spoilerText: String?) {
|
||||
if self.spoilerText != spoilerText {
|
||||
self.spoilerText = spoilerText
|
||||
}
|
||||
}
|
||||
public func update(emojis: [MastodonEmoji]) {
|
||||
if self.emojis != emojis {
|
||||
self.emojis = emojis
|
||||
}
|
||||
}
|
||||
public func update(attachments: [MastodonAttachment]) {
|
||||
if self.attachments != attachments {
|
||||
self.attachments = attachments
|
||||
}
|
||||
}
|
||||
public func update(poll: Poll?) {
|
||||
if self.poll != poll {
|
||||
self.poll = poll
|
||||
}
|
||||
}
|
||||
// sourcery:end
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import CoreDataStack
|
||||
import MastodonSDK
|
||||
|
||||
extension StatusEdit.Property {
|
||||
init(entity: Mastodon.Entity.StatusEdit) {
|
||||
self.init(
|
||||
createdAt: entity.createdAt,
|
||||
content: entity.content,
|
||||
sensitive: entity.sensitive,
|
||||
spoilerText: entity.spoilerText,
|
||||
emojis: entity.mastodonEmojis,
|
||||
attachments: entity.mastodonAttachments,
|
||||
poll: entity.poll.map { StatusEdit.Poll(options: $0.options.map { StatusEdit.Poll.Option(title: $0.title) } ) } )
|
||||
}
|
||||
}
|
||||
|
||||
extension Mastodon.Entity.StatusEdit {
|
||||
public var mastodonAttachments: [MastodonAttachment] {
|
||||
mediaAttachments.mastodonAttachments
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import CoreData
|
||||
import CoreDataStack
|
||||
import MastodonSDK
|
||||
|
||||
extension Persistence.StatusEdit {
|
||||
|
||||
public static func createOrMerge(
|
||||
in managedObjectContext: NSManagedObjectContext,
|
||||
statusEdits: [Mastodon.Entity.StatusEdit],
|
||||
forStatus status: Status
|
||||
) {
|
||||
guard statusEdits.isEmpty == false else { return }
|
||||
|
||||
// remove all edits for status
|
||||
|
||||
if let editHistory = status.editHistory {
|
||||
for statusEdit in Array(editHistory) {
|
||||
managedObjectContext.delete(statusEdit)
|
||||
}
|
||||
}
|
||||
status.update(editHistory: Set())
|
||||
let persistedEdits = create(in: managedObjectContext, statusEdits: statusEdits, forStatus: status)
|
||||
status.update(editHistory: Set(persistedEdits))
|
||||
}
|
||||
|
||||
public static func create(
|
||||
in managedObjectContext: NSManagedObjectContext,
|
||||
statusEdits: [Mastodon.Entity.StatusEdit],
|
||||
forStatus status: Status
|
||||
) -> [StatusEdit] {
|
||||
|
||||
var entries: [StatusEdit] = []
|
||||
|
||||
for statusEdit in statusEdits {
|
||||
let property = StatusEdit.Property(createdAt: statusEdit.createdAt, content: statusEdit.content, sensitive: statusEdit.sensitive, spoilerText: statusEdit.spoilerText, emojis: statusEdit.mastodonEmojis, attachments: statusEdit.mastodonAttachments, poll: statusEdit.poll.map { StatusEdit.Poll(options: $0.options.map { StatusEdit.Poll.Option(title: $0.title) } ) })
|
||||
let statusEditEntry = StatusEdit.insert(into: managedObjectContext, property: property)
|
||||
|
||||
entries.append(statusEditEntry)
|
||||
}
|
||||
|
||||
status.update(editHistory: Set(entries))
|
||||
|
||||
return entries
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@ extension Persistence {
|
|||
public enum Tag { }
|
||||
public enum SearchHistory { }
|
||||
public enum Notification { }
|
||||
public enum StatusEdit {}
|
||||
}
|
||||
|
||||
extension Persistence {
|
||||
|
|
|
@ -33,21 +33,6 @@ extension APIService {
|
|||
domain: domain,
|
||||
authorization: authorization).singleOutput()
|
||||
|
||||
guard response.value.isEmpty == false else { return response }
|
||||
|
||||
let managedObjectContext = self.backgroundManagedObjectContext
|
||||
|
||||
try await managedObjectContext.performChanges {
|
||||
// get status
|
||||
guard let status = Status.fetch(in: managedObjectContext, configurationBlock: {
|
||||
$0.predicate = Status.predicate(domain: domain, id: statusID)
|
||||
}).first else { return }
|
||||
|
||||
Persistence.StatusEdit.createOrMerge(in: managedObjectContext,
|
||||
statusEdits: response.value,
|
||||
forStatus: status)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
|
@ -71,32 +56,7 @@ extension APIService {
|
|||
domain: domain,
|
||||
authorization: authorization
|
||||
).singleOutput()
|
||||
|
||||
#if !APP_EXTENSION
|
||||
let managedObjectContext = self.backgroundManagedObjectContext
|
||||
|
||||
try await managedObjectContext.performChanges {
|
||||
let me = authenticationBox.authentication.user(in: managedObjectContext)
|
||||
let status = Persistence.Status.createOrMerge(
|
||||
in: managedObjectContext,
|
||||
context: Persistence.Status.PersistContext(
|
||||
domain: domain,
|
||||
entity: response.value,
|
||||
me: me,
|
||||
statusCache: nil,
|
||||
userCache: nil,
|
||||
networkDate: response.networkDate
|
||||
)
|
||||
)
|
||||
|
||||
Persistence.StatusEdit.createOrMerge(
|
||||
in: managedObjectContext,
|
||||
statusEdits: responseHistory.value,
|
||||
forStatus: status.status
|
||||
)
|
||||
}
|
||||
#endif
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,17 +11,3 @@ public protocol StatusCompatible {
|
|||
}
|
||||
|
||||
extension Status: StatusCompatible {}
|
||||
|
||||
extension StatusEdit: StatusCompatible {
|
||||
public var reblog: Status? {
|
||||
nil
|
||||
}
|
||||
|
||||
public var isMediaSensitive: Bool {
|
||||
sensitive
|
||||
}
|
||||
|
||||
public var isSensitiveToggled: Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -506,13 +506,6 @@ extension StatusView {
|
|||
.assign(to: \.editedAt, on: viewModel)
|
||||
.store(in: &disposeBag)
|
||||
|
||||
status.publisher(for: \.editHistory)
|
||||
.compactMap({ guard let edits = $0 else { return nil }
|
||||
return Array(edits)
|
||||
})
|
||||
.assign(to: \.statusEdits, on: viewModel)
|
||||
.store(in: &disposeBag)
|
||||
|
||||
// relationship
|
||||
status.publisher(for: \.rebloggedBy)
|
||||
.map { [weak viewModel] rebloggedBy in
|
||||
|
|
|
@ -99,8 +99,7 @@ extension StatusView {
|
|||
@Published public var replyCount: Int = 0
|
||||
@Published public var reblogCount: Int = 0
|
||||
@Published public var favoriteCount: Int = 0
|
||||
|
||||
@Published public var statusEdits: [StatusEdit] = []
|
||||
|
||||
@Published public var editedAt: Date? = nil
|
||||
|
||||
// Filter
|
||||
|
|
Loading…
Reference in New Issue