mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Remove card-persistence
This commit is contained in:
parent
e668b21da5
commit
9691e905c0
@ -7,23 +7,6 @@
|
||||
<attribute name="website" optional="YES" attributeType="String"/>
|
||||
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="application" inverseEntity="Status"/>
|
||||
</entity>
|
||||
<entity name="Card" representedClassName="CoreDataStack.Card" syncable="YES">
|
||||
<attribute name="authorName" optional="YES" attributeType="String"/>
|
||||
<attribute name="authorURLRaw" optional="YES" attributeType="String"/>
|
||||
<attribute name="blurhash" optional="YES" attributeType="String"/>
|
||||
<attribute name="desc" attributeType="String"/>
|
||||
<attribute name="embedURLRaw" optional="YES" attributeType="String"/>
|
||||
<attribute name="height" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="html" optional="YES" attributeType="String"/>
|
||||
<attribute name="image" optional="YES" attributeType="String"/>
|
||||
<attribute name="providerName" optional="YES" attributeType="String"/>
|
||||
<attribute name="providerURLRaw" optional="YES" attributeType="String"/>
|
||||
<attribute name="title" attributeType="String"/>
|
||||
<attribute name="typeRaw" attributeType="String"/>
|
||||
<attribute name="urlRaw" attributeType="String"/>
|
||||
<attribute name="width" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="card" inverseEntity="Status"/>
|
||||
</entity>
|
||||
<entity name="DomainBlock" representedClassName="CoreDataStack.DomainBlock" syncable="YES">
|
||||
<attribute name="blockedDomain" attributeType="String"/>
|
||||
<attribute name="createAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
@ -162,7 +145,6 @@
|
||||
<relationship name="application" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Application" inverseName="status" inverseEntity="Application"/>
|
||||
<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="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"/>
|
||||
|
@ -1,180 +0,0 @@
|
||||
//
|
||||
// Card.swift
|
||||
// CoreDataStack
|
||||
//
|
||||
// Created by Kyle Bashour on 11/23/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
public final class Card: NSManagedObject {
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var urlRaw: String
|
||||
public var url: URL? {
|
||||
URL(string: urlRaw)
|
||||
}
|
||||
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var title: String
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var desc: String
|
||||
|
||||
@NSManaged public private(set) var typeRaw: String
|
||||
// sourcery: autoGenerateProperty
|
||||
public var type: MastodonCardType {
|
||||
get { MastodonCardType(rawValue: typeRaw) }
|
||||
set { typeRaw = newValue.rawValue }
|
||||
}
|
||||
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var authorName: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var authorURLRaw: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var providerName: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var providerURLRaw: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var width: Int64
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var height: Int64
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var image: String?
|
||||
public var imageURL: URL? {
|
||||
image.flatMap(URL.init)
|
||||
}
|
||||
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var embedURLRaw: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var blurhash: String?
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var html: String?
|
||||
|
||||
// sourcery: autoGenerateRelationship
|
||||
@NSManaged public private(set) var status: Status
|
||||
}
|
||||
|
||||
extension Card {
|
||||
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property
|
||||
) -> Card {
|
||||
let object: Card = context.insertObject()
|
||||
|
||||
object.configure(property: property)
|
||||
|
||||
return object
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Card: Managed {
|
||||
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AutoGenerateProperty
|
||||
extension Card: AutoGenerateProperty {
|
||||
// sourcery:inline:Card.AutoGenerateProperty
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public struct Property {
|
||||
public let urlRaw: String
|
||||
public let title: String
|
||||
public let desc: String
|
||||
public let type: MastodonCardType
|
||||
public let authorName: String?
|
||||
public let authorURLRaw: String?
|
||||
public let providerName: String?
|
||||
public let providerURLRaw: String?
|
||||
public let width: Int64
|
||||
public let height: Int64
|
||||
public let image: String?
|
||||
public let embedURLRaw: String?
|
||||
public let blurhash: String?
|
||||
public let html: String?
|
||||
|
||||
public init(
|
||||
urlRaw: String,
|
||||
title: String,
|
||||
desc: String,
|
||||
type: MastodonCardType,
|
||||
authorName: String?,
|
||||
authorURLRaw: String?,
|
||||
providerName: String?,
|
||||
providerURLRaw: String?,
|
||||
width: Int64,
|
||||
height: Int64,
|
||||
image: String?,
|
||||
embedURLRaw: String?,
|
||||
blurhash: String?,
|
||||
html: String?
|
||||
) {
|
||||
self.urlRaw = urlRaw
|
||||
self.title = title
|
||||
self.desc = desc
|
||||
self.type = type
|
||||
self.authorName = authorName
|
||||
self.authorURLRaw = authorURLRaw
|
||||
self.providerName = providerName
|
||||
self.providerURLRaw = providerURLRaw
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.image = image
|
||||
self.embedURLRaw = embedURLRaw
|
||||
self.blurhash = blurhash
|
||||
self.html = html
|
||||
}
|
||||
}
|
||||
|
||||
public func configure(property: Property) {
|
||||
self.urlRaw = property.urlRaw
|
||||
self.title = property.title
|
||||
self.desc = property.desc
|
||||
self.type = property.type
|
||||
self.authorName = property.authorName
|
||||
self.authorURLRaw = property.authorURLRaw
|
||||
self.providerName = property.providerName
|
||||
self.providerURLRaw = property.providerURLRaw
|
||||
self.width = property.width
|
||||
self.height = property.height
|
||||
self.image = property.image
|
||||
self.embedURLRaw = property.embedURLRaw
|
||||
self.blurhash = property.blurhash
|
||||
self.html = property.html
|
||||
}
|
||||
|
||||
public func update(property: Property) {
|
||||
}
|
||||
|
||||
// sourcery:end
|
||||
}
|
||||
|
||||
// MARK: - AutoGenerateRelationship
|
||||
extension Card: AutoGenerateRelationship {
|
||||
// sourcery:inline:Card.AutoGenerateRelationship
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public struct Relationship {
|
||||
public let status: Status
|
||||
|
||||
public init(
|
||||
status: Status
|
||||
) {
|
||||
self.status = status
|
||||
}
|
||||
}
|
||||
|
||||
public func configure(relationship: Relationship) {
|
||||
self.status = relationship.status
|
||||
}
|
||||
|
||||
// sourcery:end
|
||||
}
|
@ -77,9 +77,6 @@ public final class Status: NSManagedObject {
|
||||
// sourcery: autoUpdatableObject
|
||||
@NSManaged public private(set) var replyTo: Status?
|
||||
|
||||
// sourcery: autoGenerateRelationship
|
||||
@NSManaged public private(set) var card: Card?
|
||||
|
||||
// one-to-many relationship
|
||||
@NSManaged public private(set) var feeds: Set<Feed>
|
||||
|
||||
@ -377,23 +374,19 @@ extension Status: AutoGenerateRelationship {
|
||||
public struct Relationship {
|
||||
public let application: Application?
|
||||
public let reblog: Status?
|
||||
public let card: Card?
|
||||
|
||||
public init(
|
||||
application: Application?,
|
||||
reblog: Status?,
|
||||
card: Card?
|
||||
) {
|
||||
reblog: Status?
|
||||
) {
|
||||
self.application = application
|
||||
self.reblog = reblog
|
||||
self.card = card
|
||||
}
|
||||
}
|
||||
|
||||
public func configure(relationship: Relationship) {
|
||||
self.application = relationship.application
|
||||
self.reblog = relationship.reblog
|
||||
self.card = relationship.card
|
||||
}
|
||||
// sourcery:end
|
||||
}
|
||||
|
@ -1,85 +0,0 @@
|
||||
//
|
||||
// Persistence+Card.swift
|
||||
//
|
||||
//
|
||||
// Created by MainasuK on 2021-12-9.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import CoreDataStack
|
||||
import Foundation
|
||||
import MastodonSDK
|
||||
|
||||
extension Persistence.Card {
|
||||
|
||||
public struct PersistContext {
|
||||
public let domain: String
|
||||
public let entity: Mastodon.Entity.Card
|
||||
public let me: MastodonUser?
|
||||
public init(
|
||||
domain: String,
|
||||
entity: Mastodon.Entity.Card,
|
||||
me: MastodonUser?
|
||||
) {
|
||||
self.domain = domain
|
||||
self.entity = entity
|
||||
self.me = me
|
||||
}
|
||||
}
|
||||
|
||||
public struct PersistResult {
|
||||
public let card: Card
|
||||
public let isNewInsertion: Bool
|
||||
|
||||
public init(
|
||||
card: Card,
|
||||
isNewInsertion: Bool
|
||||
) {
|
||||
self.card = card
|
||||
self.isNewInsertion = isNewInsertion
|
||||
}
|
||||
}
|
||||
|
||||
public static func create(
|
||||
in managedObjectContext: NSManagedObjectContext,
|
||||
context: PersistContext
|
||||
) -> PersistResult {
|
||||
var type: MastodonCardType {
|
||||
switch context.entity.type {
|
||||
case .link: return .link
|
||||
case .photo: return .photo
|
||||
case .video: return .video
|
||||
case .rich: return ._other(context.entity.type.rawValue)
|
||||
case ._other(let rawValue): return ._other(rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
let property = Card.Property(
|
||||
urlRaw: context.entity.url,
|
||||
title: context.entity.title,
|
||||
desc: context.entity.description,
|
||||
type: type,
|
||||
authorName: context.entity.authorName,
|
||||
authorURLRaw: context.entity.authorURL,
|
||||
providerName: context.entity.providerName,
|
||||
providerURLRaw: context.entity.providerURL,
|
||||
width: Int64(context.entity.width ?? 0),
|
||||
height: Int64(context.entity.height ?? 0),
|
||||
image: context.entity.image,
|
||||
embedURLRaw: context.entity.embedURL,
|
||||
blurhash: context.entity.blurhash,
|
||||
html: context.entity.html.flatMap { $0.isEmpty ? nil : $0 }
|
||||
)
|
||||
|
||||
let card = Card.insert(
|
||||
into: managedObjectContext,
|
||||
property: property
|
||||
)
|
||||
|
||||
return PersistResult(
|
||||
card: card,
|
||||
isNewInsertion: true
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@ -79,15 +79,11 @@ extension Persistence.Status {
|
||||
isNewInsertion: false
|
||||
)
|
||||
} else {
|
||||
|
||||
let card = createCard(in: managedObjectContext, context: context)
|
||||
|
||||
let application: Application? = createApplication(in: managedObjectContext, context: .init(entity: context.entity))
|
||||
|
||||
let relationship = Status.Relationship(
|
||||
application: application,
|
||||
reblog: reblog,
|
||||
card: card
|
||||
reblog: reblog
|
||||
)
|
||||
let status = create(
|
||||
in: managedObjectContext,
|
||||
@ -156,28 +152,6 @@ extension Persistence.Status {
|
||||
networkDate: context.networkDate
|
||||
)
|
||||
status.update(property: property)
|
||||
|
||||
if status.card == nil, context.entity.card != nil {
|
||||
let card = createCard(in: managedObjectContext, context: context)
|
||||
let relationship = Card.Relationship(status: status)
|
||||
card?.configure(relationship: relationship)
|
||||
}
|
||||
}
|
||||
|
||||
private static func createCard(
|
||||
in managedObjectContext: NSManagedObjectContext,
|
||||
context: PersistContext
|
||||
) -> Card? {
|
||||
guard let entity = context.entity.card else { return nil }
|
||||
let result = Persistence.Card.create(
|
||||
in: managedObjectContext,
|
||||
context: Persistence.Card.PersistContext(
|
||||
domain: context.domain,
|
||||
entity: entity,
|
||||
me: context.me
|
||||
)
|
||||
)
|
||||
return result.card
|
||||
}
|
||||
|
||||
private static func createApplication(
|
||||
|
@ -45,7 +45,6 @@ public enum Persistence {
|
||||
extension Persistence {
|
||||
public enum MastodonUser { }
|
||||
public enum Status { }
|
||||
public enum Card { }
|
||||
public enum SearchHistory { }
|
||||
public enum Notification { }
|
||||
}
|
||||
|
@ -326,18 +326,6 @@ private extension StatusCardControl {
|
||||
}
|
||||
}
|
||||
|
||||
private extension Card {
|
||||
var layout: StatusCardControl.Layout {
|
||||
var aspectRatio = CGFloat(width) / CGFloat(height)
|
||||
if !aspectRatio.isFinite {
|
||||
aspectRatio = 1
|
||||
}
|
||||
return (abs(aspectRatio - 1) < 0.05 || image == nil) && html == nil
|
||||
? .compact
|
||||
: .large(aspectRatio: aspectRatio)
|
||||
}
|
||||
}
|
||||
|
||||
private extension Mastodon.Entity.Card {
|
||||
var layout: StatusCardControl.Layout {
|
||||
var aspectRatio = CGFloat(width ?? 1) / CGFloat(height ?? 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user