diff --git a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 9.xcdatamodel/contents b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 9.xcdatamodel/contents index ee57231f2..c5bbd1485 100644 --- a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 9.xcdatamodel/contents +++ b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 9.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -225,7 +225,6 @@ - @@ -239,17 +238,6 @@ - - - - - - - - - - - diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift index 736d4b7eb..1bdd9410a 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift @@ -99,8 +99,6 @@ public final class Status: NSManagedObject { @NSManaged public private(set) var replyFrom: Set @NSManaged public private(set) var notifications: Set @NSManaged public private(set) var searchHistories: Set - - @NSManaged public private(set) var editHistory: Set? // 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) { - self.editHistory = editHistory - } } extension Status { diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/StatusEdit.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/StatusEdit.swift deleted file mode 100644 index 1cb7aa1a4..000000000 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/StatusEdit.swift +++ /dev/null @@ -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 - -} - diff --git a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/StatusEdit+Property.swift b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/StatusEdit+Property.swift deleted file mode 100644 index e32d45795..000000000 --- a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/StatusEdit+Property.swift +++ /dev/null @@ -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 - } -} diff --git a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+StatusEdit.swift b/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+StatusEdit.swift deleted file mode 100644 index be28ec63c..000000000 --- a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence+StatusEdit.swift +++ /dev/null @@ -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 - } -} - diff --git a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence.swift b/MastodonSDK/Sources/MastodonCore/Persistence/Persistence.swift index 9142e8b51..3a36dec41 100644 --- a/MastodonSDK/Sources/MastodonCore/Persistence/Persistence.swift +++ b/MastodonSDK/Sources/MastodonCore/Persistence/Persistence.swift @@ -20,7 +20,6 @@ extension Persistence { public enum Tag { } public enum SearchHistory { } public enum Notification { } - public enum StatusEdit {} } extension Persistence { diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+History.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+History.swift index 482dd0019..523f95617 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+History.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Status+History.swift @@ -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 } } diff --git a/MastodonSDK/Sources/MastodonUI/Protocol/StatusCompatible.swift b/MastodonSDK/Sources/MastodonUI/Protocol/StatusCompatible.swift index 7ae2a932d..5977cba12 100644 --- a/MastodonSDK/Sources/MastodonUI/Protocol/StatusCompatible.swift +++ b/MastodonSDK/Sources/MastodonUI/Protocol/StatusCompatible.swift @@ -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 - } -} diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift index 4ed4c603e..5257fa483 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift @@ -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 diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift index 86948b5b5..2ff5b6f85 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift @@ -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